Forum Discussion

vladtache_35966's avatar
vladtache_35966
Icon for Nimbostratus rankNimbostratus
Jun 11, 2018

F5 SDK | REST | map vips and ssl profiles

Hey, I would like to get the vips and the ssl profiles associated using F5 SDK. Would you please advise which will be the best method? Regards,Vlad  
  • Jason_Nance_333's avatar
    Jun 11, 2018

    Give this a try for a starter:

    !/usr/bin/env python3
    
    from f5.bigip import ManagementRoot
    from getpass import getpass
    
    hostname = 'my.f5.ltm.net'
    username = 'foo'
    
    mgmt = ManagmentRoot(hostname, username, getpass())
    
    print('Virtual,Client SSLs,Server SSLs')
    
    for virtual in mgmt.tm.ltm.virtuals.get_collection()
        clientssl = []
        serverssl = []
    
        for profile in virtual.profiles_s.get_collection()
            if profile.context = 'clientside':
                 Check to see if it is a client SSL profile
                try:
                     Support subPath
                    if hasattr(profile, 'subPath'):
                        pobj = mgmt.tm.ltm.profile.client_ssls.client_ssl.load(
                            partition=profile.partition,
                            subPath=profile.subPath,
                            name=profile.name,
                        )
                    else:
                        pobj = mgmt.tm.ltm.profile.client_ssls.client_ssl.load(
                            partition=profile.partition,
                            name=profile.name,
                        )
                except:
                     Not a client SSL profile (could be client TCP or other)
                    continue
    
                 If we get here it is a client SSL profile
                clientssl.append(pobj.fullPath)
            elif profile.context = 'serverside':
                 Check to see if it is a server SSL profile
                try:
                     Support subPath
                    if hasattr(profile, 'subPath'):
                        pobj = mgmt.tm.ltm.profile.server_ssls.server_ssl.load(
                            partition=profile.partition,
                            subPath=profile.subPath,
                            name=profile.name,
                        )
                    else:
                        pobj = mgmt.tm.ltm.profile.server_ssls.server_ssl.load(
                            partition=profile.partition,
                            name=profile.name,
                        )
                except:
                     Not a server SSL profile (could be server TCP or other)
                    continue
    
                 If we get here it is a server SSL profile
                serverssl.append(pobj.fullPath)
    
         Print virtual if it has client or server ssl profiles
        if len(clientssl) > 0 or len(serverssl) > 0:
            print('{},{},{}'.format(
                virtual.fullPath,
                ';'.join(clientssl),
                ';'.join(serverssl),
            )