如何从Python API获取Softlayer机器上的当前活动事务?



slcli 可以选择使用slcli vs detail machine_name | grep active_transaction在机器上获取当前活动事务。Python API for Softlayer 上的等效函数是什么?

更具体地说,我想找出救援交易何时完成。 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

是否有可能通过python API获取上述信息?

尝试以下示例,

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))

当没有事务时,getActiveTransaction 返回 null,因此这意味着它已完成,如果要检查最后一个事务,请使用方法 getLastTransaction

最新更新