Forum Discussion

jcrubaugh45_208's avatar
May 22, 2018

use python to get clientssl info

id like to query my BigIP SYSTEM and get a list of virtual servers. but only ones which have more than 1 client ssl profile applied. then print the list of virtual servers and the associated client ssl profiles using python. anyone already done something similar?

 

9 Replies

  • Hi,

     

    Normally based on the logic under your script. I have experience by using bash script to all relate configuration.

     

  • Give this a try:

    !/usr/bin/env python3
    
    import pprint
    
    from f5.bigip import ManagementRoot
    
    mgmt = ManagementRoot('hostname', 'username', 'password')
    
    virtuals = {}
    
    for virtual in mgmt.tm.ltm.virtuals.get_collection():
        virtuals[virtual.fullPath] = {
            'partition': virtual.partition,
            'name': virtual.name,
            'clientssl': [],
        }
    
        for profile in virtual.profiles_s.get_collection():
            if profile.context == 'clientside':
                try:
                    pobj = mgmt.tm.ltm.profile.client_ssls_client_ssl.load(
                        partition=profile.partition,
                        name=profile.name,
                    )
                except:
                     Not a client ssl profile
                    pobj = None
    
                if pobj:
                    virtuals[virtual.fullPath]['clientssl'].append({
                        'partition': profile.partition,
                        'name': profile.name,
                    })
    
         If we didn't find more than 1 clientssl profile delete the virtual
         server from the list (well, dict) of virtuals
        if len(virtuals[virtual.fullPath]['clientssl']) < 2:
            del(virtuals[virtual.fullPath])
    
    pprint.pprint(virtuals)
    
    • jcrubaugh45_208's avatar
      jcrubaugh45_208
      Icon for Cirrus rankCirrus

      thanks, ill give this a go, i already see based on what your showing me, i was assuming i could get some data only making 1 call and i needed more.

       

    • jcrubaugh45_208's avatar
      jcrubaugh45_208
      Icon for Cirrus rankCirrus

      this seems to be accepted by my F5 but its returning no data, im going to have to keep tweaking it some...thanks for pointing me down the road closer to my goal :)

       

    • Jason_Nance_333's avatar
      Jason_Nance_333
      Icon for Cirrus rankCirrus

      I wrote that code against 11.6.0 HF5. There may be slight differences if you're running a different version. I would try removing the if/del block to see if any data comes back. If so, it may be that we're just not on the same page regarding what you're trying to pull.

       

  • Give this a try:

    !/usr/bin/env python3
    
    import pprint
    
    from f5.bigip import ManagementRoot
    
    mgmt = ManagementRoot('hostname', 'username', 'password')
    
    virtuals = {}
    
    for virtual in mgmt.tm.ltm.virtuals.get_collection():
        virtuals[virtual.fullPath] = {
            'partition': virtual.partition,
            'name': virtual.name,
            'clientssl': [],
        }
    
        for profile in virtual.profiles_s.get_collection():
            if profile.context == 'clientside':
                try:
                    pobj = mgmt.tm.ltm.profile.client_ssls_client_ssl.load(
                        partition=profile.partition,
                        name=profile.name,
                    )
                except:
                     Not a client ssl profile
                    pobj = None
    
                if pobj:
                    virtuals[virtual.fullPath]['clientssl'].append({
                        'partition': profile.partition,
                        'name': profile.name,
                    })
    
         If we didn't find more than 1 clientssl profile delete the virtual
         server from the list (well, dict) of virtuals
        if len(virtuals[virtual.fullPath]['clientssl']) < 2:
            del(virtuals[virtual.fullPath])
    
    pprint.pprint(virtuals)
    
    • jcrubaugh45_208's avatar
      jcrubaugh45_208
      Icon for Cirrus rankCirrus

      thanks, ill give this a go, i already see based on what your showing me, i was assuming i could get some data only making 1 call and i needed more.

       

    • jcrubaugh45_208's avatar
      jcrubaugh45_208
      Icon for Cirrus rankCirrus

      this seems to be accepted by my F5 but its returning no data, im going to have to keep tweaking it some...thanks for pointing me down the road closer to my goal :)

       

    • Jason_Nance's avatar
      Jason_Nance
      Icon for Nimbostratus rankNimbostratus

      I wrote that code against 11.6.0 HF5. There may be slight differences if you're running a different version. I would try removing the if/del block to see if any data comes back. If so, it may be that we're just not on the same page regarding what you're trying to pull.