Можете ли вы получить информацию о состоянии сети из API Softlayer?

Мы заинтересованы в использовании API для получения информации, найденной на странице Network > Status > Local.

API это позволяет?

Спасибо


person R. Topete    schedule 21.01.2016    source источник


Ответы (2)


Да, это возможно, но нет единого вызова 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=(',', ': ')))
person Nelson Raul Cabero Mendoza    schedule 21.01.2016

Этот запрос может помочь вам:

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

Ссылка:

https://forums.softlayer.com/forum/softlayer-developer-network/implementations/84851-network-local-status-infrastructure-overview-via-api

(Примечание: этот справочник скоро устареет, но сейчас он может вам помочь)

person mcruz    schedule 21.01.2016