Softlayer api:如何检查 VSI 是否已在 "Anniversary Date" 上创建取消请求?
Softlayer api: How to check that a VSI has been created an cancelation request on "Anniversary Date"?
对于新创建的 VSI,我们可以在 "Anniversary Date" 取消它。 API billing_item.cancelItem 可以帮助完成它。那么在softlayer的website/devicelist中,CancelDevice按钮将无法使用。
我的问题是如何检查 api 是否已在 "Anniversary Date" 上创建了取消请求? Ohter word,我要api 获取VSI 的状态是否已提交取消请求。
你只需要查看vsi的billing item的"cancelationDate" 属性如果属性的值为"null"就说明VSI还没有取消。如果 VSI 在 "Anniversary Date" 中被取消,属性 的值将等于机器将被取消的日期
请参阅下面的示例以获取特定 VSI 的 "cancelationDate" 属性:
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 及其计费项目
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)
对于新创建的 VSI,我们可以在 "Anniversary Date" 取消它。 API billing_item.cancelItem 可以帮助完成它。那么在softlayer的website/devicelist中,CancelDevice按钮将无法使用。
我的问题是如何检查 api 是否已在 "Anniversary Date" 上创建了取消请求? Ohter word,我要api 获取VSI 的状态是否已提交取消请求。
你只需要查看vsi的billing item的"cancelationDate" 属性如果属性的值为"null"就说明VSI还没有取消。如果 VSI 在 "Anniversary Date" 中被取消,属性 的值将等于机器将被取消的日期
请参阅下面的示例以获取特定 VSI 的 "cancelationDate" 属性:
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 及其计费项目
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)