我们有兴趣使用API获取网络上的信息>状态>本地页面。
API是否允许这样做?
谢谢
答案 0 :(得分:0)
是的,但是没有一个API调用会返回结果。基本上,您需要获取帐户中的所有路由器。
这里有一个可以帮助你的代码(它使用的是Python客户端)
"""
Get network status local
The script displays the same information as the https://control.softlayer.com/network/status/local page.
Important manual pages
https://sldn.softlayer.com/reference/services/SoftLayer_Account/
https://sldn.softlayer.com/reference/services/SoftLayer_Account/getObject
https://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
"""
import SoftLayer
import json
def getRacks(networkHardware, routerStatus):
"""Retrieves the racks information.
:param SoftLayer_Hardware networkHardware: A network hardware downstream.
:param SoftLayer_Hardware routerStatus: The routers in the account which contains the network incidents.
"""
racks = []
if 'downstreamNetworkHardware' in networkHardware:
for network in networkHardware['downstreamNetworkHardware']:
rack = {}
if 'cs' in network['hostname']:
rack['name'] = network['hostname'] + '.' + network['domain']
rack['type'] = network['hardwareChassis']['hardwareFunction']['code']
rack['status'] = getAggregationRackStatus(network, routerStatus)
racks.append(rack)
return racks
def getAggregationRackStatus(networkHardware, routerStatus):
"""Retrieves the status for racks and aggregation hardware.
:param SoftLayer_Hardware networkHardware: A network hardware downstream.
:param SoftLayer_Hardware routerStatus: The routers in the account which contains the network incidents.
"""
if 'downstreamNetworkHardwareWithIncidents' in routerStatus:
for incident in routerStatus['downstreamNetworkHardwareWithIncidents']:
if incident['hostname'] == networkHardware['hostname']:
return incident['networkStatus']
else:
return routerStatus['networkStatus']
def getAggregation(router, routerStatus):
"""Retrieves the racks information.
:param SoftLayer_Hardware router: A router hardware.
:param SoftLayer_Hardware routerStatus: The routers in the account which contains the network incidents.
"""
aggregations = []
if 'downstreamNetworkHardware' in router:
for networkHardware in router['downstreamNetworkHardware']:
aggregation= {}
if 'as' in networkHardware['hostname']:
aggregation['name'] = networkHardware['hostname'] + '.' + networkHardware['domain']
aggregation['type'] = networkHardware['hardwareChassis']['hardwareFunction']['code']
aggregation['status'] = getAggregationRackStatus(networkHardware, routerStatus)
aggregation['rack'] = getRacks(networkHardware, routerStatus)
aggregations.append(aggregation)
return aggregations
USERNAME = 'set me'
API_KEY = 'set me'
# Declares the API client
client = SoftLayer.Client()
accountService = client['SoftLayer_Account']
objectMask = "mask[id,routers[id,hardwareChassis[manufacturer,name,hardwareFunction[code,description]],hostname,domain,networkStatus,networkMonitorAttachedDownVirtualGuestCount,networkMonitorAttachedDownHardwareCount,downstreamNetworkHardware[downstreamNetworkHardware,hostname,domain,hardwareChassis[manufacturer,name,hardwareFunction[code,description]]]]]"
objectMaskStatus = "mask[networkMonitorDownVirtualGuestCount,networkMonitorDownHardwareCount,routers[downstreamNetworkHardwareWithIncidents[hardwareChassis[hardwareFunction], networkStatus]]]"
try:
response = accountService.getObject(mask=objectMask)
responseStatus = accountService.getObject(mask=objectMask)
except SoftLayer.SoftLayerAPIError as e:
print("Unable to get the account. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
routers = []
for i in range(0, len(response['routers'])):
router = response['routers'][i]
routerStatus = responseStatus['routers'][i]
device = {}
device['name'] = router['hostname'] + "." + router['domain']
device['type'] = router['hardwareChassis']['hardwareFunction']['code']
device['status'] = router['networkStatus']
device['aggregation'] = getAggregation(router, routerStatus)
device['routerstatus'] = routerStatus['id']
device['id'] = router['id']
routers.append(device)
print(json.dumps(routers, sort_keys=True, indent=2, separators=(',', ': ')))
答案 1 :(得分:0)
此请求可能会对您有所帮助:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Account/getRouters?objectMask=mask[downlinkNetworkHardware,networkStatus,hardwareChassis.hardwareFunction,networkMonitorAttachedDownHardware.latestNetworkMonitorIncident, networkMonitorAttachedDownVirtualGuests[latestNetworkMonitorIncident,primaryIpAddress],downstreamNetworkHardwareWithIncidents.networkStatus,downlinkVirtualGuests.latestNetworkMonitorIncident, downlinkServers[hardwareChassis.hardwareFunction, latestNetworkMonitorIncident]]
Method: GET
参考:
(注意:这个参考文章很快就会过时,但它现在可以帮到你了)