Forum Discussion

mhite_60883's avatar
mhite_60883
Icon for Cirrocumulus rankCirrocumulus
Jan 22, 2012

Test API version to implement backward compatibility

Hello,

 

 

What is the recommended best practice for determining API version via iControl? I have a mixed 10.x and 11.x environment, and I would like to create versions of various scripts that can work with both API versions (when possible). Ideally, the various scripts will test the API version of the device before sending various API-version specific calls.

 

 

 

Thanks for any pointers -- much appreciated!

 

 

 

-M

 

  • Mark_Worrell_98's avatar
    Mark_Worrell_98
    Historic F5 Account
    Hi -

     

     

    Use the get_version method. It is available in almost every interface.

     

     

    Mark

     

  • Ah, so I suppose if I want a version independent way of doing this, I need to just pick an API endpoint that is supported in V9 and above, ie.

     

     

    def f5_get_api_version(b):

     

    version_string = str(b.System.SystemInfo.get_version())

     

    major, minor, patch = [int(x) for x in version_string.split("_")[1][1:].split(".")]

     

    return(major, minor, patch)

     

     

    (Presuming that major, minor, and patch values are always numeric... probably a bad presumption..lol)

     

  • Another option is to use the System.SystemInfo.get_system_information() method.

     

     

    -Joe

     

  • This is what I ended up doing. Alternatively I could have had the WSDL locally stored and not performed the 2nd connection.

    
    WSDLS_PRE = ['Management.Partition', 'LocalLB.Pool', 'LocalLB.NodeAddress',
                 'LocalLB.PoolMember']
    
    WSDLS_V11 = ['LocalLB.Pool', 'LocalLB.NodeAddressV2', 'LocalLB.Pool',
                 'System.Session']
    
     Create F5 object
    print "Connecting to iControl API on LTM %s..." % ltm
    try:
        b = f5_build_bigip_object(ltm, user, pw, ['System.SystemInfo'],
                                  soap_debug=SOAP_DEBUG)
    except Exception, detail:
        print "=== Exception Details ===\n%s\n=========================" % detail
        fatals += 1
        continue   try next ltm in loop
    else:
        print "Connection successfully established."
    
     Check API version
    print "Determining iControl API version supported on LTM %s..." % ltm
    try:
        major, minor, patch = f5_get_api_version(b)
    except Exception, detail:
        print "=== Exception Details ===\n%s\n=========================" % detail
        fatals += 1
        continue   try next ltm in loop
    else:
        print "API version is %d.%d.%d." % (major, minor, patch)
        if major >= 11:
            wsdls = WSDLS_V11
        else:
            wsdls = WSDLS_PRE
    
     Callback and create f5 object using version dependent wsdls
    print "Reconnecting to iControl API to request v%s specific WSDLs..." % major
    try:
        b = f5_build_bigip_object(ltm, user, pw, wsdls, soap_debug=SOAP_DEBUG)
    except Exception, detail:
        print "=== Exception Details ===\n%s\n=========================" % detail
        fatals += 1
        continue   try next ltm in loop
    else:
        print "Connection successfully established."