如何通过 python 为 Softlayer 虚拟服务器指定单个磁盘大小

How to specify single disk size for Softlayer virtual server via python

我正在使用 python 软层创建虚拟服务器实例。当我指定 2 个磁盘大小时,可以验证请求。如果我只请求 1 个磁盘大小,调用将失败。我不想使用默认大小。如何指定 100 GB 驱动器?

示例请求:

vsi_request= {
    'cpus': 2,
    'memory': 6144,
    'hourly': True,
    'hostname': 'test',
    'domain': u'sample.domain.com',
    'local_disk': False,
    'datacenter': datacenter_code,
    'os_code' : u'UBUNTU_14_64',
    'dedicated': False,
    'private_vlan': 1234,
    'post_uri': 'https://bla',
    'private': True,
    'ssh_keys': [2345],
    'nic_speed': 1000,
    'tags': 'test, pleaseCancel',
    'disks': ('100')  <---- This makes it fail
}
vsi = vsmgr.verify_create_instance(**vsi_request)

我尝试了各种输入:

# <no disks specification> success, default to 25 GB
#('100', '10') success
#('100') Unable to find prices for block device 0 with capacity of 1.
#('25') Unable to find prices for block device 0 with capacity of 2.
## Some invalid values just to see the error message
#('500')  Unable to find prices for block device 0 with capacity of 5.
#('100', '4') Unable to find prices for block device 2 with capacity of 4.
#('100', '0') Unable to find prices for block device 2 with capacity of 0.

相关堆栈跟踪:

Traceback (most recent call last):
vsi = vsmgr.verify_create_instance(**vsi_request)
File "C:\Python27\lib\site-packages\SoftLayer\managers\vs.py", line 475, in verify_create_instance
return self.guest.generateOrderTemplate(create_options)
File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 373, in call_handler
return self(name, *args, **kwargs)
File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 341, in call
return self.client.call(self.name, name, *args, **kwargs)
File "C:\Python27\lib\site-packages\SoftLayer\API.py", line 237, in call
return self.transport(request)
File "C:\Python27\lib\site-packages\SoftLayer\transports.py", line 187, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError:  SoftLayerAPIError(SoftLayer_Exception_NotFound): Unable to find prices for block device 0 with capacity of 1.

请试试这个:

'disks': ['100']

'disks': ('100',)

例如:

vsi_request= {
    'cpus': 2,
    'memory': 6144,
    'hourly': True,
    'hostname': 'test',
    'domain': u'sample.domain.com',
    'local_disk': False,
    'datacenter': datacenter_code,
    'os_code' : u'UBUNTU_14_64',
    'dedicated': False,
    'private_vlan': 1234,
    'post_uri': 'https://bla',
    'private': True,
    'ssh_keys': [2345],
    'nic_speed': 1000,
    'tags': 'test, pleaseCancel',
    'disks': ['100']
}

此外,我建议使用 get_create_options 来获取订购 VSI 的可用选项:

mgr.get_create_options()