Here's how I did it in Python. I couldn't find the answer anywhere, and finally figured it out. Having to do a 'patch' and the payload is {"createDraft":"True"} is the magic.
Publishing the draft is also a little tricky. I've included a code snippet for that too.
import requests
lb_name = "f5"
username = "admin"
password = "admin"
def create_policy_draft(policy_name):
ret = requests.patch(
'https://%s/mgmt/tm/ltm/policy/%s' % (lb_name, policy_name),
json={"createDraft": True},
auth=(username, password),
verify=False
)
def add_policy_rule(draft_policy_name, rule_json):
ret = requests.post(
'https://%s/mgmt/tm/ltm/policy/~Common~Drafts~%s/rules' % (
lb_name, draft_policy_name),
json=rule_json,
auth=(username, password),
verify=False
)
def publish_policy_draft(draft_policy_name):
ret = requests.post('https://%s/mgmt/tm/ltm/policy' % lb_name,
json={"command": "publish",
"name": "Drafts/%s" % draft_policy_name},
auth=(username, password),
verify=False)