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'})
so, here's the raw of the virtual server and the policy. i changed the ips to 10.10.10.10, and it's from our lab environment, so there's no real data there otherwise:
Virtual Server:
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'})
- JRahmOct 05, 2022Admin
Also as an alternative to the f5-common-python module, I've been using bigrest, which was developed by one our our MVPs. It does less for you, but it's very straightforward and fully featured because of it for BIG-IP and BIG-IQ as well. Here's roughly the same thing in bigrest:
from bigrest.bigip import BIGIP from bigrest.utils.utils import rest_format as rf b = BIGIP('ltm3.test.local', 'admin', 'admin') vip_remove_policies = b.modify(f"/mgmt/tm/ltm/virtual/{rf('/QA1_Web/reporting/ServiceMain')}", {"policiesReference": {"items": []}}) vip_add_policy = b.modify(f"/mgmt/tm/ltm/virtual/{rf('/QA1_Web/reporting/ServiceMain')}", {"policiesReference": {"items": [{"name": "Portal_QA1", "partition": "QA1_Web", "subPath": "Shared"}]}}) # I used this just to have quick view in my pycharm IDE of what's changing at only the name policies attributes of a virtual server. Not necessary at all to make changes vip_minimal = b.load(f"/mgmt/tm/ltm/virtual/{rf('/QA1_Web/reporting/ServiceMain')}?expandSubcollections=true&$select=name,policiesReference")
Note here that you do not need to load an object to modify it. Also, the rest_format utility (shorted by my input as rf) handles all the / to ~ conversions for you.
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