diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py index ca9e3a0ddf5868586e2497d3d9329d28ea0f68f5..afa9a5cb5b082a23a4dad25a460a721f19d1d7eb 100644 --- a/src/service/clmcservice/graphapi/views.py +++ b/src/service/clmcservice/graphapi/views.py @@ -250,7 +250,7 @@ class GraphAPI(object): # map the dpid to the switch IP address, the IP address is in the format '/172.168.23.54:1234' switches[switch["switchDPID"]] = switch["inetAddress"][1:].split(":")[0] - # retrieve all links - if SDN controller is unavailable on the given IP address return 503 Service Unavailable + # retrieve all external links (gathered through BDDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable try: url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/external-links/json") response = get(url) @@ -266,7 +266,28 @@ class GraphAPI(object): raise HTTPNotImplemented("The SDN controller failed to return a successful response when querying for the network topology.") try: - links = response.json() + external_links = response.json() + except ValueError: # response not in JSON + msg = "The SDN controller returned a response which couldn't be converted to JSON." + log.error("Unexpected error: {0}".format(msg)) + raise HTTPNotImplemented("The SDN controller failed to return a valid JSON response when querying for the network topology.") + + # retrieve all local links (gathered through LLDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable + try: + url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/links/json") + response = get(url) + except exceptions.ConnectionError: + msg = "The SDN controller is not available on IP {0} and port 8080.".format(sdn_controller_ip) + log.error("Unexpected error: {0}".format(msg)) + raise HTTPServiceUnavailable("The SDN controller couldn't be reached when trying to build the network topology.") + + if response.status_code != 200: + msg = "The SDN controller returned a response with status code different than 200." + log.error("Unexpected error: {0}".format(msg)) + raise HTTPNotImplemented("The SDN controller failed to return a successful response when querying for the network topology.") + + try: + local_links = response.json() except ValueError: # response not in JSON msg = "The SDN controller returned a response which couldn't be converted to JSON." log.error("Unexpected error: {0}".format(msg)) @@ -283,7 +304,10 @@ class GraphAPI(object): clusters = {} # build the network graph and retrieve the number of switch nodes and cluster nodes that were created - switch_count, clusters_count = build_network_graph(graph, switches, links, clusters) + tmp_switch_count, tmp_clusters_count = build_network_graph(graph, switches, external_links, clusters) + switch_count, clusters_count = build_network_graph(graph, switches, local_links, clusters) + switch_count += tmp_switch_count + clusters_count += tmp_clusters_count return {"new_switches_count": switch_count, "new_clusters_count": clusters_count}