Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Jul 05, 2017

how to get active ltm via python f5-sdk

self.mgmt = ManagementRoot(host, user, passwd) self.mgmt.tm.sys.failover.load()

 

but I can't get active lba.

 

any one who has exeprience on this and share me the code?

 

2 Replies

  • I don't know the Python API but looks like you are after tmsh show sys failover. e.g.,

     

     tmsh show sys failover
    Failover active for 2d 03:22:15
    

     

    If that's the case, try the following curl command to test if it actually works with the address, userID and password you specified in the code.

     

    curl -sku user:passwd https://host/mgmt/tm/sys/failover
    

     

    Example output (formatted nicely using | python -m json.tool)

     

    {
        "apiRawValues": {
            "apiAnonymous": "Failover active for 2d 03:24:19\n"
        },
        "kind": "tm:sys:failover:failoverstats",
        "selfLink": "https://localhost/mgmt/tm/sys/failover?ver=12.1.2"
    }
    

     

  • The python equivalent of the above as below. In addition, it checks the status of two hosts in HA (assuming both hosts have the same userid/passwd).

     

    from f5.bigip import ManagementRoot
    
    for ip in ['192.168.226.41', '192.168.226.131']:
        mgmt = ManagementRoot(ip, 'admin', 'admin')
        fail = mgmt.tm.sys.failover.load()
        failOverStat = fail.apiRawValues['apiAnonymous'].rstrip()
        print "%s: Ver %s, %s" % (ip, mgmt.tmos_version, failOverStat)
    

     

    Sample output:

     

    192.168.226.41: Ver 13.0.0, Failover standby for 0d 04:35:49
    192.168.226.131: Ver 13.0.0, Failover active for 0d 04:35:52
    

     

    See also F5 Python SDK API Docs.