X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fn2vc_juju_conn.py;h=5435c4ef864a97873d348de84d4246c44adb9769;hp=2566b0c0717e9c53dc3d813bbf02774916bd11b1;hb=refs%2Fchanges%2F42%2F10442%2F1;hpb=04686d9251e8dd3c5ac2d617aa5a1b5552e769d1;ds=sidebyside diff --git a/n2vc/n2vc_juju_conn.py b/n2vc/n2vc_juju_conn.py index 2566b0c..5435c4e 100644 --- a/n2vc/n2vc_juju_conn.py +++ b/n2vc/n2vc_juju_conn.py @@ -543,13 +543,14 @@ class N2VCJujuConnector(N2VCConnector): _, ns_id, _, _, _ = self._get_namespace_components(namespace=namespace) model_name = '{}-k8s'.format(ns_id) - cloud = cloud_name or self.k8s_cloud - credential = credential_name or cloud_name if cloud_name else self.k8s_cloud - await self.libjuju.add_model( - model_name, - cloud_name=cloud, - credential_name=credential - ) + if not await self.libjuju.model_exists(model_name): + cloud = cloud_name or self.k8s_cloud + credential = credential_name or cloud_name if cloud_name else self.k8s_cloud + await self.libjuju.add_model( + model_name, + cloud_name=cloud, + credential_name=credential + ) application_name = self._get_application_name(namespace) try: @@ -762,7 +763,8 @@ class N2VCJujuConnector(N2VCConnector): self.log.info("Namespace {} deleted".format(namespace)) async def delete_execution_environment( - self, ee_id: str, db_dict: dict = None, total_timeout: float = None + self, ee_id: str, db_dict: dict = None, total_timeout: float = None, + scaling_in: bool = False ): self.log.info("Deleting execution environment ee_id={}".format(ee_id)) @@ -775,12 +777,20 @@ class N2VCJujuConnector(N2VCConnector): model_name, application_name, _machine_id = self._get_ee_id_components( ee_id=ee_id ) - - # destroy the application try: - await self.libjuju.destroy_model( - model_name=model_name, total_timeout=total_timeout - ) + if not scaling_in: + # destroy the model + # TODO: should this be removed? + await self.libjuju.destroy_model( + model_name=model_name, total_timeout=total_timeout + ) + else: + # get juju model and observer + controller = await self.libjuju.get_controller() + model = await self.libjuju.get_model(controller, model_name) + # destroy the application + await self.libjuju.destroy_application( + model=model, application_name=application_name) except Exception as e: raise N2VCException( message=(