我可以找到一些API来取消单个项目,例如虚拟客户或存储。但是,取消虚拟客户以及所有其他结算项目非常复杂,我找不到可以获取虚拟客户的所有结算项目的API。
例如,存在一个带有disk2,disk3的虚拟客户机,当我取消此虚拟客户机时,我不想再保留磁盘了。我怎么能做到这一点?
更新
虚拟客户有三个存储(门户 - >设备详细信息 - >存储):
块设备(磁盘)(25GB)(系统) - >第一
块设备(磁盘)(2GB)(交换) - >交换
块设备(磁盘)(10GB)(系统) - >第二
我尝试通过API升级虚拟客户端存储,以便在取消虚拟客户端时,可以自动删除存储。
我升级了这样:
none_first_disk_list = {
'local':{
25:'GUEST_DISK_25_GB_LOCAL_3',
100:'GUEST_DISK_100_GB_LOCAL_3',
150:'GUEST_DISK_150_GB_LOCAL',
200:'GUEST_DISK_200_GB_LOCAL',
300:'GUEST_DISK_300_GB_LOCAL'
},
'san':{
10:'GUEST_DISK_10_GB_SAN',
20:'GUEST_DISK_20_GB_SAN',
25:'GUEST_DISK_25_GB_SAN_4',
30:'GUEST_DISK_30_GB_SAN',
40:'GUEST_DISK_40_GB_SAN',
50:'GUEST_DISK_50_GB_SAN',
75:'GUEST_DISK_75_GB_SAN',
100:'GUEST_DISK_100_GB_SAN_3',
125:'GUEST_DISK_125_GB_SAN',
150:'GUEST_DISK_150_GB_SAN',
175:'GUEST_DISK_175_GB_SAN',
200:'GUEST_DISK_200_GB_SAN',
250:'GUEST_DISK_250_GB_SAN',
300:'GUEST_DISK_300_GB_SAN',
350:'GUEST_DISK_350_GB_SAN',
400:'GUEST_DISK_400_GB_SAN',
500:'GUEST_DISK_500_GB_SAN',
750:'GUEST_DISK_750_GB_SAN_2',
1000:'GUEST_DISK_1000_GB_SAN_2',
1500:'GUEST_DISK_1500_GB_SAN',
2000:'GUEST_DISK_2000_GB_SAN'
}
}
class Server_Manager(VSManager):
def __init__(self, client):
super(Server_Manager, self).__init__(client)
self.sl_virtual_guest = client['Virtual_Guest']
self.sl_virtual_disk_image = client['Virtual_Disk_Image']
self.sl_software_component = client['Software_Component']
def get_disk_local_flag(self, instance_id):
block_devices = self.sl_virtual_guest.getBlockDevices(id=instance_id)
local_flag = False
for device in block_devices:
if device['device'] == 0:
local_flag = self.sl_virtual_disk_image.getLocalDiskFlag(id=device['diskImageId'])
else:
continue
return local_flag
def disk_upgrade(self, instance_id, disk_upgrade_config):
disk_type = 'LOCAL' if self.get_disk_local_flag(instance_id) else 'SAN'
for volume in disk_upgrade_config:
if volume not in none_first_disk_list[disk_type.lower()]:
raise AttributeError('Invalid disk volume')
mask = [
'id',
'billingItem[id, package[id, items[softwareDescriptionId, id, keyName, itemCategory[name], prices[id]]]]'
]
items_list = self.sl_virtual_guest.getObject(id=instance_id, mask="mask[%s]" % ','.join(mask))['billingItem']['package']['items']
prices = []
for disk_volume in disk_upgrade_config:
disk_keyName = none_first_disk_list[disk_type.lower()][disk_volume]
for item in items_list:
if item['keyName'] == disk_keyName and item['itemCategory']['name'] == 'Second Disk':
prices.append({'id': item['prices'][0]['id']})
maintenance_window = datetime.datetime.now(utils.UTC())
order = {
'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_'
'Upgrade',
'prices': prices,
'properties': [{
'name': 'MAINTENANCE_WINDOW',
'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
}],
'virtualGuests': [{'id': int(instance_id)}],
}
if prices:
self.client['Product_Order'].placeOrder(order)
return True
return False
client = SoftLayer.create_client_from_env(username="XXX",api_key="XXXX")
server_mgt = Server_Manager(client)
disk_upgrade_config = [25, 30]
server_mgt.disk_upgrade(17732233, disk_upgrade_config)
它有一个例外:
SoftLayerAPIError(SoftLayer_Exception_Public): Unable to add 30 GB (SAN) because a Second Disk price has already been added.
似乎虚拟客户已经有了第二个错误,但我怎么能升级便携式存储?
答案 0 :(得分:0)
您在服务器中升级的所有项目都将被取消 例如,如果升级硬盘,则所有硬盘都将被取消 当您从VSI取消结算项目时。
如果你有一个订购的便携式存储器 分开,并将它附加到服务器,控件 Portal提供了一个取消服务器的选项 便携式存储一次,但在你想尝试的情况下 API,您应该从VSI取消结算项目并创建一个 取消便携式存储的标准票证。
对于块和文件存储,如果取消VSI,则为这些存储 对象将从VSI分离,没有取消选项 他们马上与服务器。
更新
目前发送价格存在问题,您需要指定" 类别"每个商品价格的属性,
这是一个你需要发送的例子:
order = {
'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_'
'Upgrade',
'prices': [{'id': 2257, 'categories':[{'id': 82, 'name':'Second Disk', 'categoryCode': 'guest_disk2'}]},
{'id': 21861, 'categories':[{'id': 92, 'name':'Third Disk', 'categoryCode': 'guest_disk3'}]}],
'properties': [{
'name': 'MAINTENANCE_WINDOW',
'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
}],
'virtualGuests': [{'id': int(instance_id)}],