2016-11-04 26 views

回答

0

要订购具有Mongo DB的虚拟客人,必须使用此物品的价格ID。 验证/将与现有的商品价格对任何产品的订单,最好的办法是查看下一个方法: http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices

下一个脚本可用于订购与MongoDB的社区版虚拟客户。

""" 
Order Virtual Guest with MongoDB Community Edition. 

Important manual pages: 
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest 
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder 
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer 
from pprint import pprint as pp 

USERNAME = 'set me' 
API_KEY = 'set me' 

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 

order = { 
    'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest', 
    'quantity': 1, 
    'virtualGuests': [ 
     {'hostname': 'test-template', 'domain': 'example.com'} 
    ], 
    'location': 168642, # San Jose 1 
    'packageId': 46,  # CCI Package 
    'prices': [ 
     {'id': 1640}, # 1 x 2.0 GHz Core 
     {'id': 1644}, # 1 GB RAM 
     {'id': 905}, # Reboot/Remote Console 
     {'id': 272}, # 10 Mbps Public & Private Networks 
     {'id':50231}, # 1000 GB Bandwidth 
     {'id': 21}, # 1 IP Address 
     {'id': 2202}, # 25 GB (SAN) 
     {'id':13945}, # CentOS 6.x - Minimal Install (64 bit) 
     {'id': 55}, # Host Ping Monitoring 
     {'id': 57}, # Email and Ticket Notifications 
     {'id': 58}, # Automated Notification Response 
     {'id': 420}, # Unlimited SSL VPN Users & 1 PPTP VPN User per account 
     {'id': 418}, # Nessus Vulnerability Assessment & Reporting 
     {'id':20893} # MongoDB Community Edition 
    ] 
} 

try: 
     # Replace verifyOrder for placeOrder 
     result = client['SoftLayer_Product_Order'].verifyOrder(order) 
     pp(result) 
except SoftLayer.SoftLayerAPIError as e: 
     pp('Unable to verify/place order faultCode=%s, faultString=%s' 
     % (e.faultCode, e.faultString)) 

您可以审查,以及下一个链接了解更多信息: http://sldn.softlayer.com/blog/bpotter/Going-Further-SoftLayer-API-Python-Client-Part-3

UPDATE

对象模板将是最好的方式来检索其他对象的数据,如已创建实例的物品价格ID。

您可以使用此面膜:

mask[billingItem[orderItem,children[orderItem]]] 

或者这一块,这是更细化:

mask[billingItem[id,orderItem[itemPriceId],children[id,orderItem[itemPriceId]]]] 

在Python中,你可以以这种方式使用这些面具:

""" 
Get Virtual Guest and its itme price ids 

Important manual pages: 
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest 
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getObject 
https://sldn.softlayer.com/article/object-masks 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer 
from pprint import pprint as pp 

USERNAME = 'set me' 
API_KEY = 'set me' 

virtualGuestId = 25129311 

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 

objectMask = 'mask[billingItem[id,orderItem[itemPriceId],children[id,orderItem[itemPriceId]]]]' 

try: 
    result = client['SoftLayer_Virtual_Guest'].getObject(id=virtualGuestId, mask=objectMask) 
    pp(result) 
except SoftLayer.SoftLayerAPIError as e: 
    pp('Unable to get virtual guest faultCode=%s, faultString=%s' 
    % (e.faultCode, e.faultString)) 

关于ssh密钥,您只需将此行添加到订单上述脚本的对象(使用mongo db命令虚拟客户端的对象)

'sshKeys': [{'sshKeyIds': [214147, 94206]}] 
+0

谢谢。代码片段非常有用。如何获得已预配置实例的价格ID? –

+0

我把twicked你的代码片段,以适应我的设置。但是,无论我检查了什么,我都无法弄清楚添加ssh密钥的正确语法。这是我的最后尝试: –

+0

顺序= { '的complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest', 'useHourlyPricing':真, '量':1, 'sshKeys':[{ 'sshKeyIds':[716119]}], 'virtualGuests':[{ '主机名':集箱, '域':设定我”, 'sshKeyCount':1, 'sshKeys':[716119] }], .....} –