Forum Discussion

christopherlloy's avatar
christopherlloy
Icon for Altostratus rankAltostratus
Apr 11, 2019

iREST access to rules within a LTM policy

Is there a way to access attributes/settings of a rule within an LTM policy using iREST? (Ver 11.5.7) The goal is to use iREST to determine if a ViP has a security policy applied to it.

 

More generally, is there a guide to f5 objects accessible through iREST?

 

1 Reply

  • Well, I didn't use REST, I used the F5 API. I'm just learning Python myself so this is probably spaghetti but hopefully this will help get you towards the REST syntax:

     

    #!/usr/bin/env python

     

    def get_collection(container):

       collection = container.get_collection()

       return collection

     

    def load_container(container,element):

       collection = container.load(name=element)

       return collection

     

    from f5.bigip import ManagementRoot

    import sys

     

     

    # Define unique variables

    user = 'USERNAME'

    password = 'P@ssw0rd'

    f5_ip = '192.168.127.127'

     

    # Connect to the F5

    mgmt = ManagementRoot(f5_ip, user, password)

    ltm = mgmt.tm.ltm

     

     

    for virtuals in get_collection(ltm.virtuals):

       partition = ('/' + virtuals.partition + '/')

       print ('VIP Name: {}'.format(virtuals.name))

       if hasattr(virtuals,'description'):

               description = virtuals.description.lower()

       IPPORT = (virtuals.destination).replace(partition,'').split(':')

       #IPPORT =

       print ('   VIP Address: {}'.format(IPPORT[0]))

       print ('   Listening Port: {}'.format(IPPORT[1]))

       # SHOW ASSOCIATED PROFIES

       print ('   Profiles:')

       #for prof in get_collection(virts.profiles_s):

       for prof in get_collection(virtuals.profiles_s):

           #Can be filtered using: if <value> in prof.name:

           print ("       {}".format(prof.name))