问题描述
我们的代码是取消所有订购的计费项目。但是取消计费项目Gateway Appliance Cluster
时出现错误,并显示“ SoftLayerAPIError(SoftLayer_Exception_Public):此计费项目类别无法取消。”。
能否请您告知如何取消此结算项目?谢谢。
解决方法
要取消网关设备,可以使用SoftLayer_Billing_Item::cancelItem
要在您的帐户中获取所有网关及其账单项ID,可以使用以下rest api调用:
方法:GET
https://api.softlayer.com/rest/v3.1/SoftLayer_Account/getHardware?objectMask=mask[id,networkGatewayMemberFlag,billingItem[id]]&objectFilter={"hardware":{"networkGatewayMemberFlag":{"operation":1}}}
要取消网关设备,请参见以下python脚本示例:
import SoftLayer
from pprint import pprint as pp
# Use the hardware gateway id from request above.
hardware_id = 85467
client = SoftLayer.Client()
hardwareResult = client['SoftLayer_Hardware'].getBillingItem(id=hardware_id)
billingItemId = hardwareResult['id']
try:
result = client['SoftLayer_Billing_Item'].cancelItem(
False,True,"No longer needed","Api test",id=billingItemId)
pp(result)
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to get billing item information faultCode=%s,faultString=%s'
% (e.faultCode,e.faultString))
参考:
https://cloud.ibm.com/docs/gateway-appliance?topic=gateway-appliance-cancel-gateway-appliance