2016-08-01 63 views
0

我下了一個訂單來通過api(python)「placeOrder」升級虛擬機的硬件,它成功返回。我用「wait_for_transaction」(VSManager中的函數)來等待這個事務完成。幾分鐘後,它也成功返回。但是,當我登錄網站「control.softlayer.com」時,我發現升級票據顯示它已被取消,並說「XXXX由於數據中心池資源不足而無法完成」。升級請求已被取消並且此票已關閉「。Softlayer API - 如何檢查我的訂單是否被接受

那麼我怎麼能檢查這個訂單已經被接受和處理成功了?我需要知道訂單結果。

回答

2

VSManager中的「wait_for_transaction」函數僅檢查事務狀態是否未掛起,這就是爲什麼儘管事務失敗,結果仍然成功。 要驗證升級是否有效,需要查看上次事務的狀態。

你可以使用Python客戶端查看下一個示例腳本:

""" 
Retrieve a computing instance's associated upgrade request object if any. 

Important manual pages: 

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getUpgradeRequest 
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Upgrade_Request 
https://sldn.softlayer.com/article/object-masks 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer 
from pprint import pprint as pp 

virtualGuestId = 12345678 

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

client = SoftLayer.Client(username=USERNAME, 
          api_key=API_KEY) 

virtualGuestService = client['SoftLayer_Virtual_Guest'] 

objectMask = 'mask[completedFlag,order,status,ticket[title,id],virtualGuest[id,fullyQualifiedDomainName,lastTransaction[transactionGroup]]]' 

try: 
    upgradeRequest = virtualGuestService.getUpgradeRequest(mask=objectMask, id=virtualGuestId) 
    # The result should display the upgrade request status, order status, ticket associated 
    # and the last transaction and transaction status of the current Virtual Guest. 
    # Note: The upgrade request status could be the next: 
    # APPROVED 
    # PENDING 
    # PENDING_CUSTOMER_APPROVAL 
    # COMPLETE 
    # CANCELLED 
    # MAINTENANCE_UPDATE_REQUIRED 
    # IN_TRANSACTION 
    # PENDING_PAYMENT_PROCESS 
    # PENDING_AUTOMATED_FINALIZE 
    pp(upgradeRequest) 
except SoftLayer.SoftLayerAPIError as e: 
    pp('Unable to upgrade the VSI faultCode=%s, faultString=%s' 
    % (e.faultCode, e.faultString)) 
相關問題