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
# 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
# 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
self.api.add_resource(MonitorSkewAction,
"/restapi/monitor/skewness")
+
logging.debug("Created API endpoint %s(%s:%d)" % (self.__class__.__name__, self.ip, self.port))
<![endif]-->
<script src="js/main.js" type="text/javascript"></script>
+
+
</head>
+<style>
-<body>
+.link {
+ stroke: #ccc;
+}
+.node text {
+ pointer-events: none;
+ font: 15px sans-serif;
+}
+
+</style>
+<body>
<div id="page-top">
<div class="row">
<div class="col-sm-8"><h1>MeDICINE Dashboard</h1></div>
<table class="table table-striped table-hover" id="table_container">
</table>
</div>
+
+<div>
+<script src="//d3js.org/d3.v3.min.js"></script>
+<script src="js/graph.js" type="text/javascript"></script>
+</div>
+
+
</div>
<footer class="footer text-center small">(c) 2017 by SONATA Consortium and Paderborn University</footer>
// clear table
$("#table_datacenter").empty();
// header
- $("#table_datacenter").append('<tr class="tbl-head"><td>Label</td><td>Int. Name</td><td>Switch</td><td>Num. Containers</td><td>Metadata Items</td></tr>');
+ $("#table_datacenter").append('<tr class="tbl-head"><td>Label</td><td>Int. Name</td><td>Switch</td><td>Num. Containers</td><td>VNFs</td></tr>');
// fill table
$.each(data, function(i, item) {
var row_str = "";
row_str += '<td>' + item.internalname + '</td>';
row_str += '<td>' + item.switch + '</td>';
row_str += '<td><span class="badge">' + item.n_running_containers + '</span></td>';
- row_str += '<td><span class="badge">' + Object.keys(item.metadata).length + '</span></td>';
+ //row_str += '<td><span class="badge">' + Object.keys(item.metadata).length + '</span></td>';
+ row_str += '<td>' + item.vnf_list + '</span></td>';
row_str += '<tr>';
$("#table_datacenter").append(row_str);
});
}
+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
$("#btn_connect").click(connect);
$("#btn_disconnect").click(disconnect);
+ fetch_datacenter();
+ fetch_container();
+
// additional refresh on window focus
$(window).focus(function () {
if(CONNECTED)
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):
"""
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):
# 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()
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()