Forum Discussion
Activate a Policy through F5 Common Python
The F5 Python SDK Documentation is the best starting point for diving into details.
Specifically the tasks page points out the available tasks.
This is a quick example in python3 to create the task to apply/activate the policy from the python command line.
For the example all policies are being printed out for comparison.
Find the policy state and the selfLink, here the target policy is asm_http_base_2:
_policies = mgmt.tm.asm.policies_s.get_collection()
for _policy_Id in range(len(_policies)):
print('Policy Name: {}\tPolicy Active State: {}\tPolicy Link: {}'.format(_policies[_policy_Id].name, _policies[_policy_Id].active, _policies[_policy_Id].selfLink))
Policy Name: asm_http_base Policy Active State: True Policy Link: https://localhost/mgmt/tm/asm/policies/f6ipRwR5MSYfMVgE611xRg?ver=12.1.3
Policy Name: asm_http_base_2 Policy Active State: False Policy Link: https://localhost/mgmt/tm/asm/policies/Fqpvw5rn1SzYqgrCR9CA1Q?ver=12.1.3
With the selfLink from the previous command create the apply_policy task:
mgmt.tm.asm.tasks.apply_policy_s.apply_policy.create(policyReference={"link": "https://localhost/mgmt/tm/asm/policies/Fqpvw5rn1SzYqgrCR9CA1Q"})
Recollect the policy states and verify the task has made the policy active:
_policies = mgmt.tm.asm.policies_s.get_collection()
for _policy_Id in range(len(_policies)):
print('Policy Name: {}\tPolicy Active State: {}\tPolicy Link: {}'.format(_policies[_policy_Id].name, _policies[_policy_Id].active, _policies[_policy_Id].selfLink))
Policy Name: asm_http_base Policy Active State: True Policy Link: https://localhost/mgmt/tm/asm/policies/f6ipRwR5MSYfMVgE611xRg?ver=12.1.3
Policy Name: asm_http_base_2 Policy Active State: True Policy Link: https://localhost/mgmt/tm/asm/policies/Fqpvw5rn1SzYqgrCR9CA1Q?ver=12.1.3
This should get you started and let me know if you need any clarification or additional information.
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