properly delete the External SAPs
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 18 Apr 2017 14:57:40 +0000 (16:57 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 18 Apr 2017 14:57:40 +0000 (16:57 +0200)
src/emuvim/api/sonata/dummygatekeeper.py
src/emuvim/dcemulator/net.py
src/emuvim/dcemulator/node.py

index fb19e45..e1feaf7 100755 (executable)
@@ -47,6 +47,7 @@ import pkg_resources
 from subprocess import Popen
 from random import randint
 import ipaddress
+import copy
 
 logging.basicConfig()
 LOG = logging.getLogger("sonata-dummy-gatekeeper")
@@ -247,6 +248,12 @@ class Service(object):
         for v in vnf_instances:
             self._stop_vnfi(v)
 
+        for sap_name in self.saps_ext:
+            ext_sap = self.saps[sap_name]
+            target_dc = ext_sap.get("dc")
+            target_dc.removeExternalSAP(sap_name, ext_sap['net'])
+            LOG.info("Stopping the SAP instance: %r in DC %r" % (sap_name, target_dc))
+
         if not GK_STANDALONE_MODE:
             # remove placement?
             # self._remove_placement(RoundRobinPlacement)
@@ -484,7 +491,6 @@ class Service(object):
         # create list of all SAPs
         # check if we need to deploy management ports
         if USE_DOCKER_MGMT:
-            LOG.debug("nsd: {0}".format(self.nsd))
             SAPs = [p for p in self.nsd["connection_points"] if 'management' not in p.get('type')]
         else:
             SAPs = [p for p in self.nsd["connection_points"]]
@@ -944,8 +950,10 @@ class Packages(fr.Resource):
 
             # first stop and delete any other running services
             if AUTO_DELETE:
-                for service_uuid in GK.services:
-                    for instance_uuid in GK.services[service_uuid].instances:
+                service_list = copy.copy(GK.services)
+                for service_uuid in service_list:
+                    instances_list = copy.copy(GK.services[service_uuid].instances)
+                    for instance_uuid in instances_list:
                         # valid service and instance UUID, stop service
                         GK.services.get(service_uuid).stop_service(instance_uuid)
                         LOG.info("service instance with uuid %r stopped." % instance_uuid)
index af6fbad..418ab20 100755 (executable)
@@ -229,6 +229,13 @@ class DCNetwork(Containernet):
 
         return link
 
+    def removeLink(self, link=None, node1=None, node2=None):
+        """
+        Remove the link from the Containernet and the networkx graph
+        """
+        Containernet.removeLink(self, link=link, node1=node1, node2=node2)
+        self.DCNetwork_graph.remove_edge(node2.name, node1.name)
+
     def addDocker( self, label, **params ):
         """
         Wrapper for addDocker method to use custom container class.
index 3587aff..1225728 100755 (executable)
@@ -256,14 +256,19 @@ class Datacenter(object):
     def attachExternalSAP(self, sap_name, sap_net, **params):
         # create SAP as separate OVS switch with an assigned ip address
         sap_ip = str(sap_net[1]) + '/' + str(sap_net.prefixlen)
+        # allow connection to the external internet through the host
+        params = dict(NAT=True, SAPNet=str(sap_net))
         sap_switch = self.net.addExtSAP(sap_name, sap_ip, dpid=hex(self._get_next_extSAP_dpid())[2:], **params)
         sap_switch.start()
 
         # link SAP to the DC switch
         self.net.addLink(sap_switch, self.switch, cls=Link)
 
-        # allow connection to the external internet through the host
-        self.net.addSAPNAT(sap_switch, str(sap_net))
+    def removeExternalSAP(self, sap_name, sap_net):
+        sap_switch = self.net.getNodeByName(sap_name)
+        # link SAP to the DC switch
+        self.net.removeLink(link=None, node1=sap_switch, node2=self.switch)
+        self.net.removeExtSAP(sap_name, str(sap_net))
 
     def listCompute(self):
         """