From 301d2d31fd08d96238336c311cb959af67204256 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Mon, 17 Apr 2017 21:22:10 +0200 Subject: [PATCH] Add option to auto delete any running service when uploading a new package --- src/emuvim/api/sonata/__init__.py | 5 +++-- src/emuvim/api/sonata/dummygatekeeper.py | 12 ++++++++++++ src/emuvim/examples/sonata_simple_topology.py | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/emuvim/api/sonata/__init__.py b/src/emuvim/api/sonata/__init__.py index af891d3..6a6e2c2 100755 --- a/src/emuvim/api/sonata/__init__.py +++ b/src/emuvim/api/sonata/__init__.py @@ -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): diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index c0bf9f7..fb19e45 100755 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -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) diff --git a/src/emuvim/examples/sonata_simple_topology.py b/src/emuvim/examples/sonata_simple_topology.py index 1339ec7..b68e760 100755 --- a/src/emuvim/examples/sonata_simple_topology.py +++ b/src/emuvim/examples/sonata_simple_topology.py @@ -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() -- 2.25.1