2017-01-18 22 views
0

Для softlayer api SoftLayer_Network_Subnet, описание говорит:Как назначить подсеть для vlan на softlayer?

Каждый SoftLayer IP-адрес, связанный с подсетью, которая определяется в SoftLayer_Network_Subnet службы. Подсети SoftLayer определяют группу IP-адресов и назначаются SoftLayer_Network_Vlan.

http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet

Я пытаюсь найти API, который может назначить подсеть ВЛС или просто строить отношения между подсеть и VLAN, но не повезло.

Q1: Есть ли api, который может назначить подсеть для vlan?

Также у меня есть еще один вопрос о network/subnet/vlan. При создании виртуального сервера без опции подсети IP по-прежнему будет выделен для этого виртуального сервера. Какой метод используется для определения подсети и распределения этого IP-адреса на виртуальном сервере?

Действительно оцените, если кто-то может предоставить информацию.

ответ

0

при заказе VLAN также вы заказываете свою подсеть, теперь, когда вы заказываете подсеть, вы можете прикрепить ее к vlan, вы можете сделать это для подсетей «Portable Public», «Portable Private» и «Portable Public IPv6» , Как вы можете видеть, вы можете рассказать о подсети для vlan в момент заказа, нет никакого способа оценить их после выполнения заказа.

здесь простой пример о порядке подсети

""" 
Orders a new portable public subnet 

Important manual pages: 
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 
# For nice debug output: 
from pprint import pprint as pp 

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

# Order Template with all new item configurations 

orderTemplate = { 
    'location': 224092, # Singapore 1 
    'packageId': 0, 
    'endPointVlanId': 527900, 
    'prices': [ 
     { 
      'id': 13980 
     } 
    ], 
    'quantity': 1, 
    'itemCategoryQuestionAnswers': [ 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 14, 
      'answer': 1 # TOTAL_IPS_IN_30_DAYS 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 15, 
      'answer': 3 # TOTAL_IPS_IN_12_MONTHS 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 16, 
      'answer': 'Test description of your need for additional IPs'  # REASON_FOR_IPS 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 9, 
      'answer': 'ContactNameTest' # CONTACT_NAME 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 10, 
      'answer': 'ContactJobTitleTest' # CONTACT_JOB_TITLE 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 11, 
      'answer': '[email protected]' # CONTACT_EMAIL 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 12, 
      'answer': '72878781' # CONTACT_PHONE_NUMBER 
     }, 
     { 
      'categoryId': 313, 
      'categoryCode': 'sov_sec_ip_addresses_pub', 
      'questionId': 13, 
      'answer': True # CONTACT_VALIDATED 
     } 
    ], 
    'complexType': 'SoftLayer_Container_Product_Order_Network_Subnet' 
} 

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

try: 
    result = client['SoftLayer_Product_Order'].verifyOrder(orderTemplate) 
    pp(result) 
except SoftLayer.SoftLayerAPIError as e: 
    pp('Failed ... Unable to order the new item faultCode=%s, faultString=%s' 
     % (e.faultCode, e.faultString)) 

и это более полный код заказа подсеть любого вида:

""" 
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)) 

В отношении вашего другой вопрос всегда IP назначается на ваш компьютер, даже если вы не настроили его.

вы можете увидеть в этой статье о том, как выбрать сеть, которую вы хотите в вашем заказе: http://sldn.softlayer.com/blog/phil/CCI-VLAN-Specification

Для Ассинг виртуальной локальной сети к вашей машине вы только можете сделать это proccess во время заказа, если вы хотите Чанга vlan после заказа вам нужно отправить билет в softlayer и спросить их.

После того как вы VLAN вы можете перечислить свои подсети и выбрать подсеть, которую вы хотите для этого см:

http://sldn.softlayer.com/reference/services/SoftLayer_Network_Vlan/getSubnets

Вот пример о том, как заказать VSI + подсеть

https://$user:[email protected]/rest/v3/SoftLayer_Product_Order/placeOrder 

Method: Post 

{ 
    "parameters":[ 
     { 
     "orderContainers":[ 
      { 
       "hardware":[ 
        { 
        "hostname":"testhost", 
        "domain":"softlayer.com", 
        "primaryBackendNetworkComponent": 
         { 
          "networkVlanId":971077, 
          "networkVlan":{ 
           "primarySubnet":{ 
           "id":225652 
           } 
          } 
         } 
        , 
        "primaryNetworkComponent": 
         { 
          "networkVlanId":971075, 
          "networkVlan":{ 
           "primarySubnet":{ 
           "id":233232 
           } 
          } 
         } 

        } 
       ], 
       "location":"DALLAS05", 
       "quantity":1, 
       "packageId":46, 
       "prices":[ 
        { 
        "id":1640 
        }, 
        { 
        "id":1644 
        }, 
        { 
        "id":1857 
        }, 
        { 
        "id":1639 
        }, 
        { 
        "id":50367 
        }, 
        { 
        "id":273 
        }, 
        { 
        "id":2302 
        }, 
        { 
        "id":55 
        }, 
        { 
        "id":58 
        }, 
        { 
        "id":420 
        }, 
        { 
        "id":418 
        }, 
        { 
        "id":21 
        }, 
        { 
        "id":57 
        }, 
        { 
        "id":905 
        } 
       ] 
      } 
     ] 
     } 
    ] 
} 
+0

Спасибо большое! От вас ответ я получаю четкую структуру о порядке vsi/subnet/vlan. Для части «В отношении вашего другого вопроса всегда IP-адрес назначается вашему компьютеру, даже если вы его не настроили». Все еще хотите узнать больше о том, как выбирается IP-адрес. Я думаю, что должна быть какая-то политика для проверки доступных IP-адресов, которые могут быть назначены vsi, если подсеть/vlan не указана в порядке api. Не могли бы вы объяснить больше об этом? Благодаря! – Hengguo

+0

softlayer ищет доступную VLAN в вашей учетной записи, и это похоже на то, что и есть. если нет доступной VLAN, ваш заказ не будет выполнен в процессе подготовки, и сотрудник программного обеспечения будет связываться с вами. –

+0

Спасибо! Мое сомнение решено здесь. – Hengguo