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

2024-03-28 10:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

对于新创建的VSI,我们可以在“周年日”取消它。API账单_item.cancelItem项目可以帮助完成它。然后在softlayer的网站/设备列表中,取消设备按钮将无法启动。enter image description here

我的问题是如何检查一个VSI是否在“周年日”创建了一个取消请求?换句话说,我想让api获取VSI的状态是否已提交取消请求。你知道吗


Tags: 项目api列表网站状态item按钮账单
1条回答
网友
1楼 · 发布于 2024-03-28 10:30:50

您只需要查看vsi的billing item的“cancelationDate”属性,如果该属性的值为“null”,则表示vsi尚未取消。如果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)

列出所有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)

相关问题 更多 >