Add option to auto delete any running service when uploading a new package
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Mon, 17 Apr 2017 19:22:10 +0000 (21:22 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Mon, 17 Apr 2017 19:22:47 +0000 (21:22 +0200)
src/emuvim/api/sonata/__init__.py
src/emuvim/api/sonata/dummygatekeeper.py
src/emuvim/examples/sonata_simple_topology.py

index af891d3..6a6e2c2 100755 (executable)
@@ -46,13 +46,14 @@ class SonataDummyGatekeeperEndpoint(object):
     topology.
     """
 
-    def __init__(self, listenip, port, deploy_sap=False, docker_management=False, auto_deploy=False):
+    def __init__(self, listenip, port, deploy_sap=False, docker_management=False, auto_deploy=False,  auto_delete=False):
         self.dcs = {}
         self.ip = listenip
         self.port = port
         dgk.DEPLOY_SAP = deploy_sap
         dgk.USE_DOCKER_MGMT = docker_management
-        dgk.AUTODEPLOY = auto_deploy
+        dgk.AUTO_DEPLOY = auto_deploy
+        dgk.AUTO_DELETE = auto_delete
         logging.debug("Created API endpoint %s" % self)
 
     def __repr__(self):
index c0bf9f7..fb19e45 100755 (executable)
@@ -79,6 +79,9 @@ USE_DOCKER_MGMT = False
 # automatically deploy uploaded packages (no need to execute son-access deploy --latest separately)
 AUTO_DEPLOY = False
 
+# and also automatically terminate any other running services
+AUTO_DELETE = False
+
 def generate_subnets(prefix, base, subnet_size=50, mask=24):
     # Generate a list of ipaddress in subnets
     r = list()
@@ -938,6 +941,15 @@ class Packages(fr.Resource):
                 with open(upload_path, 'wb') as f:
                     f.write(son_file)
             size = os.path.getsize(upload_path)
+
+            # 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:
+                        # 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)
+
             # create a service object and register it
             s = Service(service_uuid, file_hash, upload_path)
             GK.register_service_package(service_uuid, s)
index 1339ec7..b68e760 100755 (executable)
@@ -58,7 +58,7 @@ def create_topology1():
     rapi1.start()
 
     # add the SONATA dummy gatekeeper to each DC
-    sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True, auto_deploy=True, docker_management=True)
+    sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True, auto_deploy=True, docker_management=True, auto_delete=True)
     sdkg1.connectDatacenter(dc1)
     # run the dummy gatekeeper (in another thread, don't block)
     sdkg1.start()