我想要多个数量的订单虚拟服务器,我如何生成订单容器
i want place order virtual server with mutiple quantity ,how i can generate order container
大家好,我使用 python
使用软层 api
我需要放置多个数量的虚拟服务器,如何生成订单容器??
我喜欢这个,
import SoftLayer
client = SoftLayer.Client(username='XXXXXX',api_key='xxxxxx')
vmorderparmers = {
'hostname':'testhost',
'domain': 'exampledomain.com',
'datacenter': 'sjc01',
'startCpus':1,
'maxMemory': 1024,
'localDiskFlag': True,
'hourlyBillingFlag': True,
'operatingSystemReferenceCode':'CENTOS_6_64',
"blockDevices": [
{
"device": "0",
"diskImage": {
"capacity": 100
}
}
]
}
oc = client['Virtual_Guest'].generateOrderTemplate(vmorderparmers)
在我检查数量后
oc['quantity']
说说我是如何改变的
假设我这样改变数量
oc['quantity']=2
result=client['Product_Order'].placeOrder(oc)
我得到错误无效订单contianer
订购多个虚拟服务器的方法有很多种,在您的情况下是方法 SoftLayer_Virtual_Guest::generateOrderTemplate returns the container type SoftLayer_Container_Product_Order_Virtual_Guest that can be send to the method SoftLayer_Product_Order::verifyOrder or SoftLayer_Product_Order::placeOrder。
如果您查看 SoftLayer_Product_Order::placeOrder 页面中的虚拟服务器示例。您会注意到您需要修改 quantity 和 virtualGuest 参数,如下所示。
'virtualGuests': [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
],
'quantity': 3
那么您的 python 代码应该如下所示:
"""
Create a VSI using the simplified way.
The script creates an order template by using the method generateOrderTemplate(), we'll
modify the response in order to create several virtual servers.
See below for more information.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/generateOrderTemplate/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer API username.
USERNAME = 'set me'
API_KEY = 'set me'
# To get the configuration options to create the server call the
# SoftLayer_Virtual_Guest::getCreateObjectOptions method.
vmorderparmers = {
'hostname': 'testhost',
'domain': 'exampledomain.com',
'datacenter': {'name': 'sjc01'},
'startCpus': 1,
'maxMemory': 1024,
'localDiskFlag': True,
'hourlyBillingFlag': True,
'operatingSystemReferenceCode': 'CENTOS_6_64',
'blockDevices': [
{
'device': '0',
'diskImage': {'capacity': 100}
}
]
}
# Declare the API client
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
try:
container = client['SoftLayer_Virtual_Guest'].generateOrderTemplate(vmorderparmers)
# In order to create several VSI we modify the following parameters in the response
container['quantity'] = 3
# If you set quantity greater than 1 then you need to define
# hostname/domain per virtual server you wish to order.
container['virtualGuests'] = [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
]
"""
Now we are able to verify or place the order.
verifyOrder() will check your order for errors. Replace this with a call to
placeOrder() when you're ready to order. Both calls return a receipt object
that you can use for your records.
"""
receipt = client['SoftLayer_Product_Order'].verifyOrder(container)
print (receipt)
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""
print('Unable to create the VSI. %s, %s ' % (e.faultCode, e.faultString))
希望对你有所帮助。
大家好,我使用 python
使用软层 api我需要放置多个数量的虚拟服务器,如何生成订单容器?? 我喜欢这个,
import SoftLayer
client = SoftLayer.Client(username='XXXXXX',api_key='xxxxxx')
vmorderparmers = {
'hostname':'testhost',
'domain': 'exampledomain.com',
'datacenter': 'sjc01',
'startCpus':1,
'maxMemory': 1024,
'localDiskFlag': True,
'hourlyBillingFlag': True,
'operatingSystemReferenceCode':'CENTOS_6_64',
"blockDevices": [
{
"device": "0",
"diskImage": {
"capacity": 100
}
}
]
}
oc = client['Virtual_Guest'].generateOrderTemplate(vmorderparmers)
在我检查数量后
oc['quantity']
说说我是如何改变的 假设我这样改变数量
oc['quantity']=2
result=client['Product_Order'].placeOrder(oc)
我得到错误无效订单contianer
订购多个虚拟服务器的方法有很多种,在您的情况下是方法 SoftLayer_Virtual_Guest::generateOrderTemplate returns the container type SoftLayer_Container_Product_Order_Virtual_Guest that can be send to the method SoftLayer_Product_Order::verifyOrder or SoftLayer_Product_Order::placeOrder。
如果您查看 SoftLayer_Product_Order::placeOrder 页面中的虚拟服务器示例。您会注意到您需要修改 quantity 和 virtualGuest 参数,如下所示。
'virtualGuests': [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
],
'quantity': 3
那么您的 python 代码应该如下所示:
"""
Create a VSI using the simplified way.
The script creates an order template by using the method generateOrderTemplate(), we'll
modify the response in order to create several virtual servers.
See below for more information.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/generateOrderTemplate/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer API username.
USERNAME = 'set me'
API_KEY = 'set me'
# To get the configuration options to create the server call the
# SoftLayer_Virtual_Guest::getCreateObjectOptions method.
vmorderparmers = {
'hostname': 'testhost',
'domain': 'exampledomain.com',
'datacenter': {'name': 'sjc01'},
'startCpus': 1,
'maxMemory': 1024,
'localDiskFlag': True,
'hourlyBillingFlag': True,
'operatingSystemReferenceCode': 'CENTOS_6_64',
'blockDevices': [
{
'device': '0',
'diskImage': {'capacity': 100}
}
]
}
# Declare the API client
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
try:
container = client['SoftLayer_Virtual_Guest'].generateOrderTemplate(vmorderparmers)
# In order to create several VSI we modify the following parameters in the response
container['quantity'] = 3
# If you set quantity greater than 1 then you need to define
# hostname/domain per virtual server you wish to order.
container['virtualGuests'] = [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
]
"""
Now we are able to verify or place the order.
verifyOrder() will check your order for errors. Replace this with a call to
placeOrder() when you're ready to order. Both calls return a receipt object
that you can use for your records.
"""
receipt = client['SoftLayer_Product_Order'].verifyOrder(container)
print (receipt)
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""
print('Unable to create the VSI. %s, %s ' % (e.faultCode, e.faultString))
希望对你有所帮助。