获取从图像模板创建 vsi 的问题
Getting issue for creating a vsi from an image template
我使用 Python API 创建 vsi,但在尝试从现有图像模板创建 vsi 时遇到问题。我的 Python 版本是 3.6.3,我 运行 我的 Python 脚本在 Windows 7.
您的文档 (http://softlayer-python.readthedocs.io/en/latest/api/managers/vs.html) 说:
os_code (string) – The operating system to use. Cannot be specified if
image_id is specified.
image_id (int) – The ID of the image to load onto the server. Cannot be specified if os_code is specified.
当我在 python 脚本中指定没有 os_code 的 image_id 时,出现以下错误:
Traceback (most recent call last):
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 173, in __call__
result = utils.xmlrpc_client.loads(resp.content)[0][0]
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 1021, in loads
return u.close(), u.getmethodname()
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault SoftLayer_Exception_MissingCreationProperty: "The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'.">
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\ods\Documents\slenv\", line 66, in <module>
create_vsi()
File "C:\Users\ods\Documents\slenv\", line 50, in create_vsi
ssh_keys=ssh_keys)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\managers\vs.py", line 514, in verify_create_instance
return self.guest.generateOrderTemplate(create_options)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 263, in call
return self.transport(request)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 195, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_MissingCreationProperty): The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'.
所以我更改了我的脚本以指定 os_code 和 image_id,然后我能够成功创建一个 vsi,但是图像模板没有加载到 vsi 中。
你能帮忙解决一下吗?谢谢
供您参考,下面是我用来实际创建 vsi 或只是尝试干 运行:
的 python 脚本
from __future__ import print_function
import SoftLayer
from SoftLayer.managers.vs import VSManager
def create_vsi():
#Create a client to the SoftLayer_Account API service.
#Note: currently set without the user ID and API key since
#it will by default use the values set in the CLI
#to use other values use SoftLayer.Client(sl_username, sl_api_key)
client = SoftLayer.create_client_from_env(username="your username",
api_key="your key")
vsi_mgr = VSManager(client)
# uncomment to display create options
#print(vsi_mgr.get_create_options())
# common values
datacenter = 'tor01' # the data center code
cpus = 4
memory = 65536 # MB
os_code = 'REDHAT_7_64' # the operating system code. Doesn't need this as we'll use image_id
local_disk = False # local disk or SAN
hourly = True # hourly or monthly billing
dedicated = False # multi-tenant or single tenant
image_id = '1211529' # slcli image list
nic_speed = 1000 # speed of network device
disks = [100] # size of the disks - GB
private = False # private networking only or include public internet networking as well. When set to true, Public IP will not be available.
#ssh_keys = [227113, 229467] # the IDs of the ssh keys to load on the server - use slcli sshkey list
ssh_keys = [504233] # Audrey's SSH Key
# server properties
hostname = 'testapi'
domain = 'smartworks.com' # the domain name suffix for the host
private_vlan = '1219977' # VLAN for the server see VLAN list above - use slcli vlan list
#tags = 'owner:bob,project:poc,type:docker'
# code that can verify the create operation without actually doing it
template = vsi_mgr.verify_create_instance(hostname=hostname, domain=domain,
# os_code=os_code,
cpus=cpus, memory=memory, datacenter=datacenter,
image=image_id, local_disk=local_disk,
hourly=hourly, dedicated=dedicated,
private_vlan=private_vlan, disks=disks,
nic_speed=nic_speed, private=private,
ssh_keys=ssh_keys)
print(template)
# Code that will actually create the instance
# result = vsi_mgr.create_instance(hostname=hostname, domain=domain, os_code=os_code,
# cpus=cpus, memory=memory, datacenter=datacenter,
# image=image_id, local_disk=local_disk,
# hourly=hourly, dedicated=dedicated,
# private_vlan=private_vlan, disks=disks,
# nic_speed=nic_speed, private=private,
# ssh_keys=ssh_keys)
# print(result)
if __name__ == '__main__':
create_vsi()
文档中存在问题,image_id 不是 INT 类型。 create_instance 方法调用 Softlayer_Virtual_Guest::createObject 方法,此方法使用图像的全局标识符而不是其 id。
要了解全局标识符,您可以使用 SLCLI 或此处描述的方法 get_image http://softlayer-python.readthedocs.io/en/latest/api/managers/image.html
mgr = ImageManager(client)
resp = mgr.get_image(image_id=1211529)
您可以使用以下 python 代码对其进行测试,用您自己的数据更改选项变量中的值。
import SoftLayer
from SoftLayer import VSManager
from pprint import pprint as pp
USERNAME = 'set me'
API_KEY = 'set me'
options = {
'cpus': 4,
'datacenter': 'tor01',
'domain': 'softlayer.xyz',
'hostname': 'hostname-test',
'dedicated': False,
'hourly': True,
'local_disk': False,
'memory': 65536,
'nic_speed': 1000,
'image_id': '87be78f2-fa03-4250-840e-bfa66d14866c',
'private_vlan': 12315455,
'private': False
}
# Creating client instance
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
# Get the Hardware Manager
vsi_mgr = VSManager(client)
try:
# verify_create_instance() will check for errors
# Change the method by create_instance(**options) when you ready to order.
resp = vsi_mgr.verify_create_instance(**options)
# Print retrieved value
pp(resp)
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with
the error message.
"""
pp("Unable to create Virtual Instance: %s, %s " % (e.faultCode, e.faultString))
我使用 Python API 创建 vsi,但在尝试从现有图像模板创建 vsi 时遇到问题。我的 Python 版本是 3.6.3,我 运行 我的 Python 脚本在 Windows 7.
您的文档 (http://softlayer-python.readthedocs.io/en/latest/api/managers/vs.html) 说:
os_code (string) – The operating system to use. Cannot be specified if image_id is specified.
image_id (int) – The ID of the image to load onto the server. Cannot be specified if os_code is specified.
当我在 python 脚本中指定没有 os_code 的 image_id 时,出现以下错误:
Traceback (most recent call last):
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 173, in __call__
result = utils.xmlrpc_client.loads(resp.content)[0][0]
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 1021, in loads
return u.close(), u.getmethodname()
File "c:\users\ods\appdata\local\programs\python\python36\Lib\xmlrpc\client.py", line 656, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault SoftLayer_Exception_MissingCreationProperty: "The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'.">
在处理上述异常的过程中,又发生了异常:
Traceback (most recent call last):
File "C:\Users\ods\Documents\slenv\", line 66, in <module>
create_vsi()
File "C:\Users\ods\Documents\slenv\", line 50, in create_vsi
ssh_keys=ssh_keys)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\managers\vs.py", line 514, in verify_create_instance
return self.guest.generateOrderTemplate(create_options)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 392, in call_handler
return self(name, *args, **kwargs)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 360, in call
return self.client.call(self.name, name, *args, **kwargs)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\API.py", line 263, in call
return self.transport(request)
File "C:\Users\ods\Documents\slenv\lib\site-packages\SoftLayer\transports.py", line 195, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_MissingCreationProperty): The property 'operatingSystemReferenceCode' must be set to create an instance of 'SoftLayer_Virtual_Guest'.
所以我更改了我的脚本以指定 os_code 和 image_id,然后我能够成功创建一个 vsi,但是图像模板没有加载到 vsi 中。
你能帮忙解决一下吗?谢谢
供您参考,下面是我用来实际创建 vsi 或只是尝试干 运行:
的 python 脚本from __future__ import print_function
import SoftLayer
from SoftLayer.managers.vs import VSManager
def create_vsi():
#Create a client to the SoftLayer_Account API service.
#Note: currently set without the user ID and API key since
#it will by default use the values set in the CLI
#to use other values use SoftLayer.Client(sl_username, sl_api_key)
client = SoftLayer.create_client_from_env(username="your username",
api_key="your key")
vsi_mgr = VSManager(client)
# uncomment to display create options
#print(vsi_mgr.get_create_options())
# common values
datacenter = 'tor01' # the data center code
cpus = 4
memory = 65536 # MB
os_code = 'REDHAT_7_64' # the operating system code. Doesn't need this as we'll use image_id
local_disk = False # local disk or SAN
hourly = True # hourly or monthly billing
dedicated = False # multi-tenant or single tenant
image_id = '1211529' # slcli image list
nic_speed = 1000 # speed of network device
disks = [100] # size of the disks - GB
private = False # private networking only or include public internet networking as well. When set to true, Public IP will not be available.
#ssh_keys = [227113, 229467] # the IDs of the ssh keys to load on the server - use slcli sshkey list
ssh_keys = [504233] # Audrey's SSH Key
# server properties
hostname = 'testapi'
domain = 'smartworks.com' # the domain name suffix for the host
private_vlan = '1219977' # VLAN for the server see VLAN list above - use slcli vlan list
#tags = 'owner:bob,project:poc,type:docker'
# code that can verify the create operation without actually doing it
template = vsi_mgr.verify_create_instance(hostname=hostname, domain=domain,
# os_code=os_code,
cpus=cpus, memory=memory, datacenter=datacenter,
image=image_id, local_disk=local_disk,
hourly=hourly, dedicated=dedicated,
private_vlan=private_vlan, disks=disks,
nic_speed=nic_speed, private=private,
ssh_keys=ssh_keys)
print(template)
# Code that will actually create the instance
# result = vsi_mgr.create_instance(hostname=hostname, domain=domain, os_code=os_code,
# cpus=cpus, memory=memory, datacenter=datacenter,
# image=image_id, local_disk=local_disk,
# hourly=hourly, dedicated=dedicated,
# private_vlan=private_vlan, disks=disks,
# nic_speed=nic_speed, private=private,
# ssh_keys=ssh_keys)
# print(result)
if __name__ == '__main__':
create_vsi()
文档中存在问题,image_id 不是 INT 类型。 create_instance 方法调用 Softlayer_Virtual_Guest::createObject 方法,此方法使用图像的全局标识符而不是其 id。
要了解全局标识符,您可以使用 SLCLI 或此处描述的方法 get_image http://softlayer-python.readthedocs.io/en/latest/api/managers/image.html
mgr = ImageManager(client)
resp = mgr.get_image(image_id=1211529)
您可以使用以下 python 代码对其进行测试,用您自己的数据更改选项变量中的值。
import SoftLayer
from SoftLayer import VSManager
from pprint import pprint as pp
USERNAME = 'set me'
API_KEY = 'set me'
options = {
'cpus': 4,
'datacenter': 'tor01',
'domain': 'softlayer.xyz',
'hostname': 'hostname-test',
'dedicated': False,
'hourly': True,
'local_disk': False,
'memory': 65536,
'nic_speed': 1000,
'image_id': '87be78f2-fa03-4250-840e-bfa66d14866c',
'private_vlan': 12315455,
'private': False
}
# Creating client instance
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
# Get the Hardware Manager
vsi_mgr = VSManager(client)
try:
# verify_create_instance() will check for errors
# Change the method by create_instance(**options) when you ready to order.
resp = vsi_mgr.verify_create_instance(**options)
# Print retrieved value
pp(resp)
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with
the error message.
"""
pp("Unable to create Virtual Instance: %s, %s " % (e.faultCode, e.faultString))