2016-11-09 71 views
0

我已經做了一些在stackoverflow搜索,並通過API看,但似乎無法找到答案具體。 我在python中創建了一些自動化腳本,想知道是否有辦法抓取primaryNetworkComponentprimaryBackendNetworkComponent對,並根據位置?有getVlans()方法,但不知道哪些vlans走到一起,除非我去gui。 vlan對上的機器數量沒有限制嗎?如果沒有的話,拿起路由器就可以接受,只要拿到前兩個vlans?訂購Softlayer Vlan對

回答

0

下面的腳本可以幫助檢索特定位置的VLAN:

""" 
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. <[email protected]> 
""" 
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)) 

有在公網VLAN服務器的數量沒有限制,但是這取決於從可用的IP地址,同樣的情況對私人VLAN。如果私有VLAN有256個IP地址的限制。

如果vlan具有硬件防火牆,則它具有30臺服務器(VSI或BMS)的限制。

從路由器中檢索第一個vlans是不可能的,因爲這是受限制的,您只能檢索您購買的vlans。

參考文獻:

+0

非常感謝ruber! – Patrick

0

我有這樣的代碼

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']: 

在我試圖讓全球標識符,但我不斷收到一個關鍵錯誤

在訂單完成並處於部署狀態後,會生成全局標識符嗎?

我試圖尋找像域不同的密鑰,它工作

+0

我發佈了一個新的答案,如果您需要進一步的幫助,請讓我知道 –

0

我有以下腳本成功:

""" 
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. <[email protected]> 
""" 
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)) 

你是對的,在收到訂單生成的全局標識符,但他們連接到服務器,直到提供過程完成。所以,有必要等到服務器的供應過程完成後才能進行搜索。