我已经对stackoverflow进行了一些搜索,并查看了API,但似乎无法专门找到答案。
我在python中创建了一些自动化脚本,并想知道是否有一种方法可以抓住primaryNetworkComponent
和primaryBackendNetworkComponent
对并基于位置?除了我去gui之外,还有getVlans()
方法,但不确定哪些vlan会合在一起。 vlan对上的机器数量没有限制吗?如果没有它可以接受路由器并只采取前2个vlan?
答案 0 :(得分: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. <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))
public vlan中的服务器数量没有限制,但它取决于可用的ip地址,私有vlan的情况相同。在私有vlan的情况下有256个ip地址的限制。
如果vlan有硬件防火墙,则限制为30台服务器(VSI或BMS)。
无法从路由器检索第一个vlan,因为这是受限制的,您只能检索您购买的vlan。
<强>参考文献:强>
答案 1 :(得分: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']:
其中我试图获取全局标识符,但我一直收到一个关键错误
订单完成后是否在部署状态下生成全局标识符?
我尝试搜索域名之类的其他键,但它可以正常工作
答案 2 :(得分: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. <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))
您是对的,全局标识符在订单收据中生成,但它们会附加到服务器,直到配置过程完成。因此,有必要等到服务器的配置过程结束,然后进行搜索。