在Python中创建带宽池

时间:2016-04-29 14:08:07

标签: python ibm-cloud-infrastructure

我正在尝试使用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)

问题是当我登录到客户门户时,新池被标记为待删除。

您能指出我正确的方向来创建新的带宽池吗?

我在createObject服务上使用Network bandwidth allotment

1 个答案:

答案 0 :(得分: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. <sldn@softlayer.com>
"""
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))