简体   繁体   English

Softlayer API:如何检查VSI是否已在“周年纪念日”上创建取消请求?

[英]Softlayer api: How to check that a VSI has been created an cancelation request on “Anniversary Date”?

For a newly created VSI, we can cancel it on "Anniversary Date". 对于新创建的VSI,我们可以在“周年纪念日”将其取消。 The API billing_item.cancelItem can helps to accomplish it. API billing_item.cancelItem可以帮助完成它。 Then in the website/devicelist of softlayer, the CancelDevice button will be unable. 然后在softlayer的网站/设备列表中,CancelDevice按钮将无法使用。 在此处输入图片说明

My question is how to check that a VSI has been created an cancelation request on "Anniversary Date" or not by api ? 我的问题是如何检查api是否在“周年纪念日”上创建了VSI取消请求? Ohter word, I want the api to get the status of a VSI has been submit the cancelation request or not. 抱歉,我希望api获取VSI的状态是否已提交取消请求。

You just need to see the "cancelationDate" property of the vsi's billing item if the value of the property is "null" it means that the VSI has not been cancelled. 您只需要查看vsi计费项目的“ cancelationDate”属性,如果该属性的值为“ null”,则表示尚未取消VSI。 In case that the VSI has been cancelled in "Anniversary Date" the value of the property will be equals to the date when the machine is going to get canceled 如果在“周年纪念日”中取消了VSI,则该属性的值将等于要取消机器的日期

see the example below to get the "cancelationDate" property of a particular VSI: 请参阅下面的示例以获取特定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)

list all the VSIs and their billingItems 列出所有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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM