Forum Discussion
Building a policy through python sdk
- Mar 04, 2018
I figured out by myself.
The issue was the rule creation where it was the part of transaction. By definition anything within transaction won't be built until whole transaction part is completed.
With my code, the rule was the part of transaction and the following commands of building conditions and actions depended on the rule. Chicken and egg problem.
So to fix this issue, I simply moved the rule creation part out of transaction and it fixed all problem.
Following is the code for your reference.
mr = ManagementRoot('192.168.80.150', 'admin', 'admin') controls=['forwarding', 'persistence'] requires = ['http', 'client-ssl'] try: newpol = mr.tm.ltm.policys.policy.create(name='testpol5', controls=controls, requires=requires, \ subPath='Drafts', strategy='first-match') Rule creation has been placed out of transaction newRules = newpol.rules_s.rules.create(name='r1', ordinal=0, description='r1 desc') tx=mr.tm.transactions.transaction with TransactionContextManager(tx) as api: values=['90'] newRules.conditions_s.conditions.create(name='0', cpuUsage=True, greater=True, last_15secs=True, values=values, request=True) newRules.actions_s.actions.create(name='0', forward=True, node='1.1.1.1', request=True ) newRules.update() newpol.publish() except Exception as e: print("Exception during policy creation: " + str(e))
I figured out by myself.
The issue was the rule creation where it was the part of transaction. By definition anything within transaction won't be built until whole transaction part is completed.
With my code, the rule was the part of transaction and the following commands of building conditions and actions depended on the rule. Chicken and egg problem.
So to fix this issue, I simply moved the rule creation part out of transaction and it fixed all problem.
Following is the code for your reference.
mr = ManagementRoot('192.168.80.150', 'admin', 'admin')
controls=['forwarding', 'persistence']
requires = ['http', 'client-ssl']
try:
newpol = mr.tm.ltm.policys.policy.create(name='testpol5', controls=controls, requires=requires, \
subPath='Drafts', strategy='first-match')
Rule creation has been placed out of transaction
newRules = newpol.rules_s.rules.create(name='r1', ordinal=0, description='r1 desc')
tx=mr.tm.transactions.transaction
with TransactionContextManager(tx) as api:
values=['90']
newRules.conditions_s.conditions.create(name='0', cpuUsage=True, greater=True, last_15secs=True, values=values, request=True)
newRules.actions_s.actions.create(name='0', forward=True, node='1.1.1.1', request=True )
newRules.update()
newpol.publish()
except Exception as e:
print("Exception during policy creation: " + str(e))
I think I did that :) I don't know if there is any F5 posting policy blocking this..
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com