diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index 02731992..870f3e60 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -153,7 +153,6 @@ def dump_known_requests(filename, requests): @click.command() @click.option("--kube-config", help="Provide a config file for a k8s deployment") -@click.option("--kube-config", help="Provide a config file for a k8s deployment") @click.option("--laconic-config", help="Provide a config file for laconicd", required=True) @click.option("--image-registry", help="Provide a container image registry url for this k8s cluster") @click.option("--deployment-parent-dir", help="Create deployment directories beneath this directory", required=True) @@ -237,9 +236,20 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ if d.attributes.request: deployments_by_request[d.attributes.request] = d + # Find removal requests. + removals_by_request = {} + removal_requests = laconic.app_deployment_removal_requests() + for r in removal_requests: + if r.attributes.request: + removals_by_request[r.attributes.request] = r + requests_to_execute = [] for r in requests_by_name.values(): - if r.id not in deployments_by_request: + if r.id in deployments_by_request: + print(f"Found satisfied request for {r.id} at {deployments_by_request[r.id].names[0]}") + elif r.id in removals_by_request: + print(f"Found removal request for {r.id} at {removals_by_request[r.id].id}") + else: if r.id not in previous_requests: print(f"Request {r.id} needs to processed.") requests_to_execute.append(r) @@ -247,8 +257,6 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ print( f"Skipping unsatisfied request {r.id} because we have seen it before." ) - else: - print(f"Found satisfied request {r.id} at {deployments_by_request[r.id].names[0]}") print("Found %d unsatisfied request(s) to process." % len(requests_to_execute)) diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index f95d3f3e..afec0828 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -146,11 +146,17 @@ class LaconicRegistryClient: raise Exception("Cannot locate record:", name_or_id) return None - def app_deployment_requests(self): - return self.list_records({"type": "ApplicationDeploymentRequest"}, True) + def app_deployment_requests(self, all=True): + return self.list_records({"type": "ApplicationDeploymentRequest"}, all) - def app_deployments(self): - return self.list_records({"type": "ApplicationDeploymentRecord"}) + def app_deployments(self, all=True): + return self.list_records({"type": "ApplicationDeploymentRecord"}, all) + + def app_deployment_removal_requests(self, all=True): + return self.list_records({"type": "ApplicationDeploymentRemovalRequest"}, all) + + def app_deployment_removals(self, all=True): + return self.list_records({"type": "ApplicationDeploymentRemovalRecord"}, all) def publish(self, record, names=[]): tmpdir = tempfile.mkdtemp() @@ -165,11 +171,16 @@ class LaconicRegistryClient: cmd("laconic", "-c", self.config_file, "cns", "record", "publish", "--filename", record_fname) )["id"] for name in names: - cmd("laconic", "-c", self.config_file, "cns", "name", "set", name, new_record_id) + self.set_name(name, new_record_id) return new_record_id finally: cmd("rm", "-rf", tmpdir) + def set_name(self, name, record_id): + cmd("laconic", "-c", self.config_file, "cns", "name", "set", name, record_id) + + def delete_name(self, name): + cmd("laconic", "-c", self.config_file, "cns", "name", "delete", name) def file_hash(filename): return hashlib.sha1(open(filename).read().encode()).hexdigest() diff --git a/stack_orchestrator/main.py b/stack_orchestrator/main.py index fabc58ff..a4644412 100644 --- a/stack_orchestrator/main.py +++ b/stack_orchestrator/main.py @@ -20,7 +20,10 @@ from stack_orchestrator.repos import setup_repositories from stack_orchestrator.build import build_containers from stack_orchestrator.build import build_npms from stack_orchestrator.build import build_webapp -from stack_orchestrator.deploy.webapp import run_webapp, deploy_webapp, deploy_webapp_from_registry +from stack_orchestrator.deploy.webapp import (run_webapp, + deploy_webapp, + deploy_webapp_from_registry, + undeploy_webapp_from_registry) from stack_orchestrator.deploy import deploy from stack_orchestrator import version from stack_orchestrator.deploy import deployment @@ -54,6 +57,7 @@ cli.add_command(build_webapp.command, "build-webapp") cli.add_command(run_webapp.command, "run-webapp") cli.add_command(deploy_webapp.command, "deploy-webapp") cli.add_command(deploy_webapp_from_registry.command, "deploy-webapp-from-registry") +cli.add_command(undeploy_webapp_from_registry.command, "undeploy-webapp-from-registry") cli.add_command(deploy.command, "deploy") # deploy is an alias for deploy-system cli.add_command(deploy.command, "deploy-system") cli.add_command(deployment.command, "deployment")