From ba51a81ddd774203e6e581d49a34670e4a2b4701 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Sun, 23 Apr 2017 01:22:59 +0200 Subject: [PATCH] update dashboard with graph --- src/emuvim/api/rest/network.py | 28 ++++++++++++++++++++++++ src/emuvim/api/rest/rest_api_endpoint.py | 6 +++-- src/emuvim/dashboard/index.html | 21 +++++++++++++++++- src/emuvim/dashboard/js/main.js | 16 ++++++++++++-- src/emuvim/dcemulator/node.py | 5 ++++- src/emuvim/examples/demo_topo_3pop.py | 11 +++++++++- 6 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/emuvim/api/rest/network.py b/src/emuvim/api/rest/network.py index e766e62..65dddc4 100755 --- a/src/emuvim/api/rest/network.py +++ b/src/emuvim/api/rest/network.py @@ -121,3 +121,31 @@ class NetworkAction(Resource): except Exception as ex: logging.exception("API error.") return ex.message, 500, CORS_HEADER + + +class DrawD3jsgraph(Resource): + + global net + + def get(self): + nodes = list() + nodes2 = list() + links = list() + # add all DCs + #for dc in net.dcs: + for node_name in net.DCNetwork_graph.nodes(): + nodes2.append(node_name) + node_index = nodes2.index(node_name) + node_dict = {"name":node_name,"group":node_index} + nodes.append(node_dict) + + # add links between other DCs + for node1_name in net.DCNetwork_graph.nodes(): + node1_index = nodes2.index(node1_name) + for node2_name in net.DCNetwork_graph.neighbors(node1_name): + node2_index = nodes2.index(node2_name) + edge_dict = {"source": node1_index, "target": node2_index, "value": 10} + links.append(edge_dict) + + json = {"nodes":nodes, "links":links} + return json, 200, CORS_HEADER \ No newline at end of file diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 71f87b9..f328b8e 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -38,7 +38,7 @@ from compute import dcs, ComputeList, Compute, ComputeResources, DatacenterList, # need to import total module to set its global variable net import network -from network import NetworkAction +from network import NetworkAction, DrawD3jsgraph import monitor from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction @@ -85,7 +85,8 @@ class RestApiEndpoint(object): # network related actions (setup chaining between VNFs) self.api.add_resource(NetworkAction, "/restapi/network") - + self.api.add_resource(DrawD3jsgraph, + "/restapi/network/d3jsgraph") # monitoring related actions # export a network interface traffic rate counter @@ -103,6 +104,7 @@ class RestApiEndpoint(object): self.api.add_resource(MonitorSkewAction, "/restapi/monitor/skewness") + logging.debug("Created API endpoint %s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)) diff --git a/src/emuvim/dashboard/index.html b/src/emuvim/dashboard/index.html index 6f77d08..8f1258e 100755 --- a/src/emuvim/dashboard/index.html +++ b/src/emuvim/dashboard/index.html @@ -26,10 +26,22 @@ + + + +

MeDICINE Dashboard

@@ -87,6 +99,13 @@
+ +
+ + +
+ +
diff --git a/src/emuvim/dashboard/js/main.js b/src/emuvim/dashboard/js/main.js index 71741f2..9715683 100755 --- a/src/emuvim/dashboard/js/main.js +++ b/src/emuvim/dashboard/js/main.js @@ -40,7 +40,7 @@ function update_table_datacenter(data) // clear table $("#table_datacenter").empty(); // header - $("#table_datacenter").append('LabelInt. NameSwitchNum. ContainersMetadata Items'); + $("#table_datacenter").append('LabelInt. NameSwitchNum. ContainersVNFs'); // fill table $.each(data, function(i, item) { var row_str = ""; @@ -49,7 +49,8 @@ function update_table_datacenter(data) row_str += '' + item.internalname + ''; row_str += '' + item.switch + ''; row_str += '' + item.n_running_containers + ''; - row_str += '' + Object.keys(item.metadata).length + ''; + //row_str += '' + Object.keys(item.metadata).length + ''; + row_str += '' + item.vnf_list + ''; row_str += ''; $("#table_datacenter").append(row_str); }); @@ -105,6 +106,14 @@ function fetch_container() } +function fetch_d3graph() +{ + // do HTTP request and trigger gui update on success + var request_url = API_HOST + "/restapi/network/d3jsgraph"; + console.debug("fetching from: " + request_url); + //$.getJSON(request_url, update_graph); +} + function fetch_loop() { // only fetch if we are connected @@ -161,6 +170,9 @@ $(document).ready(function(){ $("#btn_connect").click(connect); $("#btn_disconnect").click(disconnect); + fetch_datacenter(); + fetch_container(); + // additional refresh on window focus $(window).focus(function () { if(CONNECTED) diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py index 1225728..d5a8cdf 100755 --- a/src/emuvim/dcemulator/node.py +++ b/src/emuvim/dcemulator/node.py @@ -223,6 +223,7 @@ class Datacenter(object): self.net.addLink(d, self.switch, params1=nw, cls=Link, intfName1=nw.get('id')) # do bookkeeping self.containers[name] = d + return d # we might use UUIDs for naming later on def stopCompute(self, name): @@ -281,12 +282,14 @@ class Datacenter(object): """ Return a dict with status information about this DC. """ + container_list = [name for name in self.containers] return { "label": self.label, "internalname": self.name, "switch": self.switch.name, "n_running_containers": len(self.containers), - "metadata": self.metadata + "metadata": self.metadata, + "vnf_list" : container_list } def assignResourceModel(self, rm): diff --git a/src/emuvim/examples/demo_topo_3pop.py b/src/emuvim/examples/demo_topo_3pop.py index bf3cc20..4dd011c 100755 --- a/src/emuvim/examples/demo_topo_3pop.py +++ b/src/emuvim/examples/demo_topo_3pop.py @@ -49,12 +49,19 @@ def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True) dc1 = net.addDatacenter("dc1") - + dc2 = net.addDatacenter("dc2") + dc3 = net.addDatacenter("dc3") + s1 = net.addSwitch("s1") + net.addLink(dc1, s1) + net.addLink(dc2, s1) + net.addLink(dc3, s1) # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) + rapi1.connectDatacenter(dc2) + rapi1.connectDatacenter(dc3) # run API endpoint server (in another thread, don't block) rapi1.start() @@ -69,6 +76,8 @@ def create_topology1(): docker_management=True, auto_delete=True, sap_vnfd_path=sap_vnfd_path) sdkg1.connectDatacenter(dc1) + sdkg1.connectDatacenter(dc2) + sdkg1.connectDatacenter(dc3) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() -- 2.25.1