Forum Discussion
Trying to assign a policy to a virtual server
- Oct 05, 2022
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'})
Looks like your partition is not being added to the request URI. You can try debug to see what the curl command would be outright, copy that out, add your partition, and see if that works. Then we can troubleshoot why it's not being added. Try removing the subPath kwarg as well.
>>> mgmt = ManagementRoot('ltm3.test.local', 'admin', 'admin', debug=True) # set on instantiation
>>> mgmt.debug = True # turn on after instantiation
>>> mgmt.debug = False # turn off
>>> for x in mgmt.debug_output:
...... print(x)
output will show you with curl what the request URI looks like. You can iterate through the debug_ouput list after you run your commands that fail.
Also, the nomenclature of "create" is pretty weird, but it is create on the virtual to add an existing policy to it. I wish we had just used the proper REST verbs for the actions...
also...this code should *just work* once we get your partitions worked out
# Load existing virtual with no policy and assert it doesn't exist on the virtual
v1 = b.tm.ltm.virtuals.virtual.load(‘name’: ‘myvip’, ‘partition’: ‘Common’)
assert v1.policies_s.policies.exists(‘name’: ‘mypol’, ‘partition’: ‘Common’) is False
# Add the existing policy to the virtual
v1_pol = v1.policies_s.policies.create(name=‘mypol’, ‘partition’: ‘Common’)
# Refresh the virtual object so the newly attached policy is referenced locally
v1.refresh()
# assert the policy exists on the virtual
assert v1.policies_s.policies.exists(‘name’: ‘mypol’, ‘partition’: ‘Common’) is True
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