from flask_restful import Resource
from flask import request
import json
+import networkx
logging.basicConfig(level=logging.INFO)
nodes2 = list()
links = list()
# add all DCs
- #for dc in net.dcs:
+ node_attr = networkx.get_node_attributes(net.DCNetwork_graph, 'type')
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}
+ type = node_attr[node_name]
+ node_dict = {"name":node_name,"group":type}
nodes.append(node_dict)
# add links between other DCs
# last step: remove the instance from the list of all instances
del self.instances[instance_uuid]
- def _start_vnfd(self, vnfd, vnf_id):
+ def _start_vnfd(self, vnfd, vnf_id, **kwargs):
"""
Start a single VNFD of this service
:param vnfd: vnfd descriptor dict
cpu_period=cpu_period,
cpuset=cpu_list,
mem_limit=mem_lim,
- volumes=volumes)
+ volumes=volumes,
+ type=kwargs.get('type','docker'))
# rename the docker0 interfaces (eth0) to the management port name defined in the VNFD
if USE_DOCKER_MGMT:
if sap["type"] == "internal":
vnfi = None
if not GK_STANDALONE_MODE:
- vnfi = self._start_vnfd(sap, sap['name'])
+ vnfi = self._start_vnfd(sap, sap['name'], type='sap_int')
self.instances[instance_uuid]["vnf_instances"].append(vnfi)
elif sap["type"] == "external":
"""
Wrapper for addDocker method to use custom container class.
"""
- self.DCNetwork_graph.add_node(label)
+ self.DCNetwork_graph.add_node(label, type=params.get('type', 'docker'))
return Containernet.addDocker(self, label, cls=EmulatorCompute, **params)
- def removeDocker( self, label, **params ):
+ def removeDocker( self, label, **params):
"""
Wrapper for removeDocker method to update graph.
"""
self.DCNetwork_graph.remove_node(label)
return Containernet.removeDocker(self, label, **params)
+ def addExtSAP(self, sap_name, sap_ip, **params):
+ """
+ Wrapper for addExtSAP method to store SAP also in graph.
+ """
+ # make sure that 'type' is set
+ params['type'] = params.get('type','sap_ext')
+ self.DCNetwork_graph.add_node(sap_name, type=params['type'])
+ LOG.info('add ext sap: {0}'.format(sap_name))
+ return Containernet.addExtSAP(self, sap_name, sap_ip, **params)
+
+ def removeExtSAP(self, sap_name, **params):
+ """
+ Wrapper for removeExtSAP method to remove SAP also from graph.
+ """
+ self.DCNetwork_graph.remove_node(sap_name)
+ return Containernet.removeExtSAP(self, sap_name)
+
def addSwitch( self, name, add_to_graph=True, **params ):
"""
Wrapper for addSwitch method to store switch also in graph.
# add this switch to the global topology overview
if add_to_graph:
- self.DCNetwork_graph.add_node(name)
+ self.DCNetwork_graph.add_node(name, type=params.get('type','switch'))
+ LOG.info('*** **** *** add switch: {0} type: {1}'.format(name, params.get('type')))
# set the learning switch behavior
if 'failMode' in params :
s = Containernet.addSwitch(self, name, protocols='OpenFlow10,OpenFlow12,OpenFlow13', failMode=failMode, **params)
- # set flow entry that enables learning switch behavior (needed to enable E-LAN functionality)
- #LOG.info('failmode {0}'.format(failMode))
- #if failMode == 'standalone' :
- # LOG.info('add NORMAL')
- # s.dpctl('add-flow', 'actions=NORMAL')
-
return s
def getAllContainers(self):