2016-04-29 35 views
0

我正在嘗試使用Python創建一個新的帶寬池。當我運行下面的代碼,我得到了我認爲是正確的響應:用Python創建帶寬池

import SoftLayer 
from pprint import pprint as pp 
import logging 
logger = logging.getLogger() 
logger.addHandler(logging.StreamHandler()) 
logger.setLevel(3) 
client = SoftLayer.Client() 
templateObject = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].createObject({ 
    "accountId": 11111, 
    "bandwidthAllotmentTypeId": 2, 
    "createDate": "04/28/2016 16:18:03", 
    "endDate": "04/28/2017 16:18:03", 
    "locationGroupId": 1, 
    "name": "RtiffanyTest1", 
    "serviceProviderId": 1 
}) 


pp(templateObject) 

的問題是,當我登錄到客戶門戶的新池被標記爲待刪除。

你能指出我在正確的方向有一個新的帶寬池產生的?

我在Network bandwidth allotment服務上使用createObject

回答

0

請嘗試下面的例子:

""" 
Create Bandwidth Pool 

Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment/createObject/ 

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

API_USERNAME = 'set me' 
API_KEY = 'set me' 

# Set the needed values to create a new item 
accountId = 307600 

# The values for bandwidthAllotmentTypeId are: (1) and (2) 
# where: (1) means this allotment is marked as a virtual private rack or 
#  (2) bandwidth pooling 
bandwidthAllotmentTypeId = 2 

# To get locationGroupId, execute: SoftLayer_Location_Group::getAllObjects 
locationGroupId = 1 
newBandwithPoolName = 'testPool02' 

# Create an object template to create the item. 
objectTemplate = { 
    'accountId': accountId, 
    'bandwidthAllotmentTypeId': bandwidthAllotmentTypeId, 
    'locationGroupId': locationGroupId, 
    'name': newBandwithPoolName 
} 

# Creates a new connection to the API service. 
client = SoftLayer.Client(
    username=API_USERNAME, 
    api_key=API_KEY 
) 

try: 
    result = client['SoftLayer_Network_Bandwidth_Version1_Allotment'].createObject(objectTemplate) 
    pp(result) 

except SoftLayer.SoftLayerAPIError as e: 
    pp('Failed ... Unable to create a new Bandwidth Pool faultCode=%s, faultString=%s' 
     % (e.faultCode, e.faultString)) 
+0

這完美地工作。謝謝。 – greyhoundforty

+0

快樂喲幫助:) – mcruz