2016-02-01 5 views
0

Я ищу API, который извлекает список подсети и ее цены.API SoftLayer: заказная подсеть

Для портативных IP-адресов и статического найденного идентификатора категории 279 и 281. И найден для глобальных IPv4, портативных общедоступных IPv6 и глобальных IPv6. Мы выполнили это, Идентификатор пакета 0 и присоединились к именам элементов.

Есть ли лучший способ получить его? Или что такое идентификатор категории для глобального IPv4, портативного общедоступного IPv6 и глобального IPv6.

Спасибо.

ответ

2

Чтобы получить все подсети категории, выполните:

https://[username]:[ap[ikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/getSubnetCategories 

Method: GET 

Результат будет выглядеть примерно так:

0: { 
"categoryCode": "global_ipv4" 
"id": 330 
"name": "Global IPv4" 
"quantityLimit": 0 
}- 
1: { 
"categoryCode": "global_ipv6" 
"id": 331 
"name": "Global IPv6" 
"quantityLimit": 0 
}- 
2: { 
"categoryCode": "sec_ip_addresses" 
"id": 14 
"name": "Public Secondary IP Addresses" 
"quantityLimit": 0 
}- 
3: { 
"categoryCode": "sov_ipv6_addresses" 
"id": 70 
"name": "Public Portable IPv6 Addresses" 
"quantityLimit": 0 
}- 
4: { 
"categoryCode": "sov_sec_ip_addresses" 
"id": 54 
"name": "Public Secondary VLAN IP Addresses" 
"quantityLimit": 0 

Чтобы увидеть пакеты подсети идентификаторов и категорий, пожалуйста, выполните:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/getAllObjects?objectMask=mask[id,description,categories[categoryCode,group.name]] 

Method: GET 

Результат будет примерно таким:

{ 
"id": 0 
"categories": [23] 
0: { 
"categoryCode": "dedicated_load_balancer" 
"group": { 
"name": "Network" 
}- 
}- 
… 
6: { 
"categoryCode": "global_ipv4" 
"group": { 
"name": "Network" 
}- 
}- 
7: { 
"categoryCode": "global_ipv6" 
"group": { 
"name": "Network" 
}- 
} 

Где: «global_ipv4» и «global_ipv6» использовать пакет 0.

Ниже приведены некоторые примеры, заказать некоторые подсети: Global IP V6:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder.json 
Method: POST 
Json: 
|========================= 
{ 
    "parameters": [ 
    { 
     "packageId": 0, 
     "prices": [ 
     { 
      "id": 19066 
     } 
     ], 
     "quantity": 1, 
     "complexType": "SoftLayer_Container_Product_Order_Network_Subnet" 
    } 
    ] 
} 
|========================= 

How to get the Global IPv6 prices? 

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/0/getItemPrices?objectFilter={"itemPrices":{"item":{"keyName": {"operation": "GLOBAL_IPV6"}}}} 

Глобальный IP v4:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder.json 

Method: POST 

Json: 
|=========================== 
{ 
    "parameters": [ 
    { 
     "packageId": 0, 
     "prices": [ 
     { 
      "id": 19065 
     } 
     ], 
     "quantity": 1, 
     "complexType": "SoftLayer_Container_Product_Order_Network_Subnet" 
    } 
    ] 
} 
|=========================== 

Ссылки:

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject

1

Ну Портал использует 3 Pacakges перечислить цены. У меня есть примеры в Python, я надеюсь, это поможет вам

""" 
List the options and te prices to order a subnet like the portal. 

Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAllObjects 
http://sldn.softlayer.com/article/Object-Masks 
http://sldn.softlayer.com/article/Object-Filters 

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

import SoftLayer 
import json 

client = SoftLayer.Client() 
packageService = client['SoftLayer_Product_Package'] 

# The groups listed in the portal and its category code. 
groups = { 
    "Static Public": "static_sec_ip_addresses", 
    "Portable Public": "sov_sec_ip_addresses_pub", 
    "Portable Private": "sov_sec_ip_addresses_priv", 
    "Global IPv4": "global_ipv4", 
    "Static Public IPv6": "static_ipv6_addresses", 
    "Portable Public IPv6": "sov_ipv6_addresses", 
    "Global IPv6": "global_ipv6" 
} 

# Declaring a filter to get the packages related to subnets 
objectFilter = { 
    "type": { 
     "keyName": { 
      "operation": "in", 
      "options": [{ 
       "name": "data", 
       "value": [ 
        "ADDITIONAL_SERVICES", 
        "ADDITIONAL_SERVICES_PORTABLE_IP_ADDRESSES", 
        "ADDITIONAL_SERVICES_STATIC_IP_ADDRESSES" 
       ] 
      }] 
     } 
    } 
} 

# Declaring an object mask to get more information about the packages 
objectMask = "mask[items[id, description, prices[id, recurringFee, attributes], categories[categoryCode]]]" 

try: 
    packages = packageService.getAllObjects(filter=objectFilter, mask=objectMask) 
except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to list the packages. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString)) 

options = [] 
for group in groups.keys(): 
    option = {} 
    option['category'] = group 
    option['items'] = [] 
    for package in packages: 
     for item in package['items']: 
      newOpItem = True 
      for opItem in option['items']: 
       if opItem['id'] == item['id']: 
        newOpItem = False 
        break 
      if newOpItem: 
       for category in item['categories']: 
        if category['categoryCode'] == groups[group]: 
         prices = [] 
         if len(item['prices']) > 1: 
          for price in item['prices']: 
           if len(price['attributes']) == 0: 
            if 'recurringFee' in price: 
             prices.append(price) 
             item['prices'] = price 
             break 
         option['items'].append(item) 
         break 
    options.append(option) 

print(json.dumps(options, sort_keys=True, indent=2, separators=(',', ': '))) 

Чтобы заказать подсеть

""" 
Order a new subnet. 

The script order a new subnet using the same options like the portal. 

Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAllObjects 
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/getSubnetForIpAddress 
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans 
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_Container_Product_Order_Network_Subnet 
http://sldn.softlayer.com/blog/bpotter/Going-Further-SoftLayer-API-Python-Client-Part-3 
http://sldn.softlayer.com/article/Object-Filters 
http://sldn.softlayer.com/article/Python 
http://sldn.softlayer.com/article/Object-Masks 


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

import SoftLayer 
import json 

# The subnet you wish to order. The available options are the 
# same like in the in the Softlayer Portal. 
# e.g. "1 Static Public IP Address", 
# "/64 Block Static Public IPv6 Addresses", etc. 
option = "Global IPv6" 

# The endpoint IP address for the subnet. 
# You need to configure this field if 
# your order belongs to the categories 
# "Static Public" or "Static Public IPv6" 
# e.g. "119.81.142.114", "2401:c900:1201:9c::2". 
endPointIP = "119.81.142.114" 

# The VLan number for the subnet. 
# You need to configure this field if 
# your order belongs to the categories 
# "Portable Public", "Portable Private" and 
# "Portable Public IPv6". 
vlanNumber = 758 

client = SoftLayer.Client() 
packageService = client['SoftLayer_Product_Package'] 
subnetService = client['SoftLayer_Network_Subnet'] 
orderService = client['SoftLayer_Product_Order'] 
accountService = client['SoftLayer_Account'] 

# Declaring an object filter to get the packages 
# related to subnets. 
objectFilter = { 
    "type": { 
     "keyName": { 
      "operation": "in", 
      "options": [{ 
       "name": "data", 
       "value": [ 
        "ADDITIONAL_SERVICES", 
        "ADDITIONAL_SERVICES_PORTABLE_IP_ADDRESSES", 
        "ADDITIONAL_SERVICES_STATIC_IP_ADDRESSES" 
       ] 
      }] 
     } 
    } 
} 

# Declaring an object mask to get more information about the packages 
objectMask = "mask[items[id, description, prices[id, recurringFee, attributes, categories]]]" 

# Getting the items and the prices available to order subnets 
try: 
    packages = packageService.getAllObjects(filter=objectFilter, 
              mask=objectMask) 

except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to list the packages. faultCode=%s, faultString=%s" % 
      (e.faultCode, e.faultString)) 
    exit(1) 

# Getting item price for the configured option to order. 
optionItem = {} 
optionPackage = 0 
for package in packages: 
    for item in package['items']: 
     if item['description'] == option: 
      prices = [] 
      if len(item['prices']) > 1: 
       for price in item['prices']: 
        if len(price['attributes']) == 0: 
         if 'recurringFee' in price: 
          prices.append(price) 
          item['prices'] = price 
          break 
      optionItem = item 
      optionPackage = package['id'] 
      break 
    if 'id' in optionItem: 
     break 

if not 'id' in optionItem: 
    print("The configured option: " + option + " is not valid.") 
    exit(1) 

# Verifying if the configured option requires a VLan or end point IP. 
requireVlan = False 
requireIp = False 
for category in optionItem['prices'][0]["categories"]: 
    cat = category['categoryCode'] 
    if cat == "static_sec_ip_addresses" or cat == "static_ipv6_addresses": 
     requireIp = True 
    if (cat == "sov_sec_ip_addresses_pub" or 
     cat == "sov_sec_ip_addresses_priv" or cat == "sov_ipv6_addresses"): 
     requireVlan = True 
    break 

# Getting the IP address object. 
ip = {} 
if requireIp: 
    try: 
     objectMask = "mask[ipAddresses]" 
     subnet = subnetService.getSubnetForIpAddress(endPointIP, 
                mask=objectMask) 
     if not 'id' in subnet: 
      print("There is no a IP address " + endPointIP + 
        " in the subnets of the account.") 
      exit(1) 
     else: 
      for ipSubnet in subnet['ipAddresses']: 
       if ipSubnet['ipAddress'] == endPointIP: 
        ip = ipSubnet 
        break 
    except SoftLayer.SoftLayerAPIError as e: 
     print("Unable to find the subnet. faultCode=%s, faultString=%s" 
       % (e.faultCode, e.faultString)) 
     exit(1) 

# Getting the VLan. 
vlan = {} 
if requireVlan: 
    try: 
     objectFilter = { 
      "networkVlans": { 
       "vlanNumber": { 
        "operation": vlanNumber 
       } 
      } 
     } 
     vlans = accountService.getNetworkVlans(filter=objectFilter) 
     if len(vlans) == 0: 
      print("There is no a VLan number " + str(vlanNumber) + 
        " in the account.") 
      exit(1) 
     else: 
      vlan = vlans[0] 
    except SoftLayer.SoftLayerAPIError as e: 
     print("Unable to retrieve the VLans. faultCode=%s, faultString=%s" % 
       (e.faultCode, e.faultString)) 
     exit(1) 

# Creating the order template for the subnet 
orderTemplate = { 
    'packageId': optionPackage, 
    'prices': optionItem['prices'], 
    'quantity': 1, 
    'complexType': 'SoftLayer_Container_Product_Order_Network_Subnet' 
} 

if requireVlan: 
    orderTemplate['endPointVlanId'] = vlan['id'] 
elif requireIp: 
    orderTemplate['endPointIpAddressId'] = ip['id'] 

try: 
    # 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. 
    result = orderService.verifyOrder(orderTemplate) 
    print(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': '))) 
except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to place the order. faultCode=%s, faultString=%s" % 
      (e.faultCode, e.faultString))