Mar 27, 2026 - For details about updated CVE-2025-53521 (BIG-IP APM vulnerability), refer to K000156741.

Forum Discussion

dani_martinez_2's avatar
dani_martinez_2
Icon for Nimbostratus rankNimbostratus
May 28, 2018

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.

 

1 Reply

  • 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