Ordering Softlayer Vlan pairs

旧时模样 提交于 2020-01-25 21:52:26

问题


I've done some searching on stackoverflow and looked through the API but can't seem to find an answer specifically. I'm creating some automation scripts in python and wondering if there's a way to grab the primaryNetworkComponent and the primaryBackendNetworkComponent pairs and based on location? There's the getVlans() method but not sure which vlans go together unless i go to the gui. Is there no limit to the number of machines that can be on a vlan pair? if there isn't would it just be acceptable to grab the router and just take the first 2 vlans?


回答1:


The below script can help to retrieve vlans from specific location:

"""
Retrieves vlans from specific location

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Vlan/
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. <sldn@softlayer.com>
"""
import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

# Define location
datacenter = "Seoul 1"

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)

# Declaring an object mask and object filter to get vlans from datacenter
objectMask = "mask[primaryRouter[datacenter], networkSpace]"
objectFilter = {"networkVlans": {"primaryRouter": {"datacenter": {"longName": {"operation": datacenter}}}}}

try:
    # Getting the VLANs
    vlans = client['SoftLayer_Account'].getNetworkVlans(mask=objectMask, filter=objectFilter)
    # Print vlans
    print("PRIMARY NETWORK COMPONENT")
    for vlan in vlans:
        if vlan['networkSpace'] == 'PUBLIC':
            print("Id: %s     Vlan Number: %s      Primary Router: %s" % (vlan['id'], vlan['vlanNumber'], vlan['primaryRouter']['hostname']))
    print("\nPRIMARY BACKEND NETWORK COMPONENT")
    for vlan in vlans:
        if vlan['networkSpace'] == 'PRIVATE':
            print("Id: %s     Vlan Number: %s      Primary Router: %s" % (vlan['id'], vlan['vlanNumber'], vlan['primaryRouter']['hostname']))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get Vlans. faultCode=%s, faultString=%s"
          % (e.faultCode, e.faultString))

There is no limit for number of servers in a public vlan, but it depends from the available ip addresses , the same situation for private vlan. In case of private vlan has a limit of 256 ip addresses.

If the vlan has a hardware firewall, it has a limitation of 30 servers (VSIs or BMSs).

It's not possible to retrieve the first vlans from router, because this is something restricted, you only will be able to retrieve the vlans that you purchased.

References:

  • How many devices may be assigned to a single VLAN?



回答2:


i have this code

mask = 'id, hostname, domain, hardwareStatus, globalIdentifier, remoteManagementAccounts, primaryBackendIpAddress, primaryIpAddress'
    hardware_list = mgr.list_hardware(mask=mask)
    for hardware in hardware_list:
        if "someGLobalID" == hardware['globalIdentifier']:

in which i'm trying to get the global identifier but i keep getting a key error

Do global identifiers get generated after an order is completed and in the deploy status?

I tried searching a different key like domain and it works




回答3:


I have success with the following script:

"""
List Hardware

Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/hardware.py

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
mgr = SoftLayer.HardwareManager(client)

globalIdentifier = '93e99548-bb97-4a18-b728-9c8ebba6s9e3'

try:
    mask = 'id, hostname, domain, hardwareStatus, globalIdentifier, remoteManagementAccounts, primaryBackendIpAddress, primaryIpAddress'
    hardware_list = mgr.list_hardware(mask=mask)
    for hardware in hardware_list:
        if globalIdentifier == hardware['globalIdentifier']:
            print(hardware['globalIdentifier'])

except SoftLayer.SoftLayerAPIError as e:
    print("Error. "
          % (e.faultCode, e.faultString))

You are right, the global identifiers are generated in the order receipt, but they are attached to the servers until the provision proccess finish. So, it's necessary to wait until the provision process from a server finishes, to search by this.



来源:https://stackoverflow.com/questions/40511624/ordering-softlayer-vlan-pairs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!