From 00e65b9a485862a4af99d8f2c4769fac9a96f9d6 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Tue, 18 Apr 2017 16:57:40 +0200 Subject: [PATCH] properly delete the External SAPs --- src/emuvim/api/sonata/dummygatekeeper.py | 14 +++++++++++--- src/emuvim/dcemulator/net.py | 7 +++++++ src/emuvim/dcemulator/node.py | 9 +++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index fb19e45..e1feaf7 100755 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -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) diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index af6fbad..418ab20 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -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. diff --git a/src/emuvim/dcemulator/node.py b/src/emuvim/dcemulator/node.py index 3587aff..1225728 100755 --- a/src/emuvim/dcemulator/node.py +++ b/src/emuvim/dcemulator/node.py @@ -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): """ -- 2.17.1