ibm-cloud-infrastructureapiconnect

How to get the current active transaction on a Softlayer machine from the Python API?


slcli has the option of getting the current active transaction on a machine using slcli vs detail machine_name | grep active_transaction. What is the equivalent function on the Python API for Softlayer?

More specifically, I want to find out when the rescue transaction is complete. slcli vs detail *** | grep active_transaction active_transaction RESCUE_BOOT
slcli vs detail *** | grep active_transaction active_transaction CLOUD_ISO_BOOT_TEAR_DOWN
slcli vs detail *** | grep active_transaction active_transaction CONFIGURE_CLOUD_NETWORK
slcli vs detail *** | grep active_transaction active_transaction NULL

Is it possible to get the above information through the python API?


Solution

  • Try with the following example,

    import SoftLayer
    
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    vsiId = 111222333
    
    client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
    
    try:
        active_transaction = client['Virtual_Guest'].getActiveTransaction(id=vsiId)    
        print(active_transaction)
    except SoftLayer.SoftLayerAPIError as e:
        pp("Unable to retrieve active transaction: %s, %s " % (e.faultCode, e.faultString))
    

    The getActiveTransaction returns null when there aren't transactions so it means that it was completed, if you want to check the last transaction use the method getLastTransaction instead