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'})
are you saying creating the policy fails, or attaching the new policy to the virtual server fails? Seems the latter, but you indicate the former. See the functional test code below:
Working with LTM policies: https://github.com/F5Networks/f5-common-python/blob/development/f5/bigip/tm/ltm/test/functional/test_policy.py
Policies have to be published when created in order to attach to the virtual. You can add the kwarg publish=True when creating the policy, OR load the newly created policy object and just append .publish() and hit enter. Applying to virtual should work at that point.
Thanks so much for responding. And yes, the last line of code is wrong.
so what i am trying to do is to attach an existing policy to a virtual server. my understanding was that trying to load a policy that is not already attached to the server would cause a failure:
vs.policies_s.policies.load(name='Portal_QA1', partition ='QA1_Web', subPath = 'Shared')
yields:
File "C:\Users\ttait\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\f5\bigip\tm\ltm\virtual.py", line 138, in load
raise NonExtantVirtualPolicy(msg)f5.sdk_exception.NonExtantVirtualPolicy: The Policy named, Portal_QA1, does not exist on the device.
but was successful if the policy had already been attached to the server (which i tested using the UI)
when i try to load and publish the existing policy
policy = mgmt.tm.ltm.policys.policy.load(name='Portal_QA1', partition ='QA1_Web', subPath = 'Shared') ## <-- this is successful
policy.publish()
i get this error:
policy.publish()
File "C:\Users\ttait\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\f5\bigip\tm\ltm\policy.py", line 155, in publish
assert 'Drafts' in self._meta_data['uri']
AssertionError
i have tried using 'create' to attach an existing policy to the virtual server:
vs.policies_s.policies.create(name='Portal_QA1', partition ='QA1_Web', subPath = 'Shared')
and that yields this error:
File "C:\Users\ttait\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\icontrol\session.py", line 295, in wrapper
raise iControlUnexpectedHTTPError(error_message, response=response)
icontrol.exceptions.iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri: https://10.80.91.172:443/mgmt/tm/ltm/virtual/~QA1_Web~reporting~serviceMain/policies/
Text: '{"code":404,"message":"01020036:3: The requested policy (Portal_QA1) was not found.","errorStack":[],"apiError":3}'
i feel like there should be some way to load the policy using mgmt.tm.ltm.policys.policy.load and then attach that to the virtual_server, but i cannot find anything in the documentation, or the examples that allows that.
the thing that's causing me the headache is that i can load the policy using the ltm.policys, so i know it exists on the f5, but i cannot load it using the vs.policies_s.policies.create() or vs.policies_s.policies.load()
is there something i need to do to the virtual server in order to allow this?
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