2016-11-08 40 views
0

對於新創建的VSI,我們可以在「Anniversary Date」中取消它。 API billing_item.cancelItem可以幫助完成它。然後在softlayer的網站/ devicelist中,CancelDevice按鈕將無法使用。 enter image description hereSoftlayer api:如何檢查VSI是否已在「Anniversary Date」上創建取消請求?

我的問題是如何檢查VSI是否已創建取消請求「週年日期」或不是通過api? Ohter的話,我希望api得到VSI的狀態已經提交了取消請求。

回答

1

如果該屬性的值爲「null」,則只需查看vsi的開票項目的「cancelationDate」屬性即表示VSI尚未取消。如果VSI在「週年日期」中被取消,則該房產的價值將等於機器將被取消的日期。

請參閱下面的示例以獲取特定的「cancelationDate」屬性VSI:

import SoftLayer 

USERNAME = 'set me' 
API_KEY = 'set me' 

vsiId = 123 

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 
vsiService = client['SoftLayer_Virtual_Guest'] 

objectMask = "mask[id, cancellationDate]" 

try: 
    result = vsiService.getBillingItem(mask=objectMask, id=vsiId) 
    print(result) 
except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to retrieve the VSI's billing item. " % (e.faultCode, e.faultString)) 
    exit(1) 

列表中的所有的VSI及其billingItems

import SoftLayer 

USERNAME = 'set me' 
API_KEY = 'set me' 

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 
vsiService = client['SoftLayer_Account'] 

objectMask = "mask[id,hostname, billingItem[cancellationDate]]" 

try: 
    result = vsiService.getVirtualGuests(mask=objectMask) 
    print(result) 
except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to retrieve the VSI's billing item. " % (e.faultCode, e.faultString)) 
    exit(1) 
+0

謝謝。我的要求是掃描之前創建的軟層vsi列表,並在需要時自動提交「Anniversary Date」上的取消請求。有時候一個vsi可能已經被deleteObject方法取消了。如果接下來我使用已刪除的vsi id調用siService.getBillingItem,則api將拋出一個異常。軟層API的異常很難檢查錯誤類型是什麼,錯誤代碼是不可靠的。所以,你能告訴我另一個可以幫助檢查vsi是否被取消的API嗎? – lippman

+0

否則,你可以告訴我如何檢查哪些錯誤發生的代碼時,有一個例外:[SoftLayer.exceptions.SoftLayerAPIError:SoftLayerAPIError(SoftLayer_Exception_Public):此取消無法處理。請聯繫支持。此結算項目已被取消。]。也許你會提供在錯誤信息中使用搜索關鍵字'已取消'的方法來確定錯誤的原因。但我認爲這種方法是不可靠的。任何其他方式可以幫助準確地檢查什麼類型的錯誤? – lippman

+0

哦,我發現你已經使用這個[除了SoftLayer.SoftLayerAPIError作爲e: print(「無法檢索VSI的結算項目。」%(e.faultCode,e.faultString)) ],你能否提供e .moder的默認代碼列表? – lippman

相關問題