`400 Unexpected Error: Bad Request for uri: https://192.168.80.150:443/mgmt/tm/transaction/1520127675018281/commands/1/conditions/
Text: '{"code":400,"message":"Found invalid command id 1/conditions/","errorStack":[],"apiError":1}'
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))