Trying to assign a policy to a virtual server
i am trying to change policies on a virtual server, using the python sdk.
i load the vs, i can load the existing policy on the vs, and delete it, but when i try to create a new policy for the vs, i get a 404 error saying that the policy cannot be found.
## load the virtual server
vs = mgmt.tm.ltm.virtuals.virtual.load(name="serviceMain", partition ="partition", subPath = "subPath")
## load the policy. this works
policy = mgmt.tm.ltm.policys.policy.load(name="pol_name", partition ="partition", subPath = "subPath")
## load existing policy from the vs and delete it. this works
pol = vs.policies_s.policies.load(name="pol_name", partition ="partition", subPath = "subPath")
pol.delete()
## create a new policy. this fails
mgmt.tm.ltm.policys.policy.create(name="pol_name", partition ="partition", subPath = "subPath")
i get this error:
Text: '{"code":404,"message":"01020036:3: The requested policy (pol_name) was not found.","errorStack":[],"apiError":3}'
the policy exists, and was loaded earlier in the script, but it can't be found. i have tried other methods of attaching the policy, and they have all failed.
any ideas?
thanks,
-t
Ok...so I wasn't able to come up with the warm and fuzzy solution. I get the same error, and I'm not sure why. That said, I have a workaround for you. This works for me with your partition/folder structure loaded on my local test LTM:
# Use the modify method to PATCH the specific attribute that includes the policies list. vip.modify(policiesReference={"items": [{"name": "Portal_QA1", "partition": "QA1_Web", "subPath": "Shared"}]}) # Since policies are subcollections, refresh with expandSubcollections attribute to validate at the vip level vip.refresh(requests_params={'params': 'expandSubcollections=true'})