Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Assign an existing Security Policy through Python SDK

Can I assign to an Existing Virtual Server an existing Security Policy? Not a local Traffic Policy, I have already created a Automatic Security Policy through the Deployment Wizard but I would like to automate the process through a Python Script. Thanks in advance.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Dani,

Just spent some time digging into this ... was quite painful. Here is a very basic and rudimentary code snippet on how to modify the virtual server assignment for a given security policy. Aka you can add or remove servers as you see fit:

from f5.bigip import ManagementRoot
mgmt = ManagementRoot('ip', 'user', 'pass')
policies = mgmt.tm.asm.policies_s.get_collection()
policy = [p for p in policies if p.fullPath == '/partition/name'][0]
policy.modify(**{'virtualServers': []})

If you want to modify other parameters of the security policy you have to use tasks to apply them.

HTH, Dennis

0