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

 

  • 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),
            )
    
  • 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),
            )
    
  • 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),
            )
    
  • There were some syntax issue in this script

    1. ManagmentRoot
      is misspelled on line 9
    2. Missing
      :
      on lines 13 and 17
    3. Incorrect comparison operators on lines 18 and 39 (
      =
      should be
      ==
      )
    4. Missing the closing
      )
      on the last line, line 67 for the print function.

    I"m not a Python guy but the script below has the modified changes that worked for me.

    !/usr/bin/env python3
    
    from f5.bigip import ManagementRoot
    from getpass import getpass
    
    hostname = 'my.f5.ltm.net'
    username = 'foo'
    
    mgmt = ManagementRoot(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),
            ))