Give a warning when removing a cloud that does not exist
[osm/N2VC.git] / n2vc / n2vc_juju_conn.py
index 5435c4e..81c1a74 100644 (file)
@@ -24,6 +24,7 @@ import asyncio
 import logging
 import os
 
+from n2vc.config import ModelConfig
 from n2vc.exceptions import (
     N2VCBadArgumentsException,
     N2VCException,
@@ -149,15 +150,7 @@ class N2VCJujuConnector(N2VCConnector):
             )
             self.api_proxy = None
 
-        if "enable_os_upgrade" in vca_config:
-            self.enable_os_upgrade = vca_config["enable_os_upgrade"]
-        else:
-            self.enable_os_upgrade = True
-
-        if "apt_mirror" in vca_config:
-            self.apt_mirror = vca_config["apt_mirror"]
-        else:
-            self.apt_mirror = None
+        model_config = ModelConfig(vca_config)
 
         self.cloud = vca_config.get('cloud')
         self.k8s_cloud = None
@@ -179,8 +172,6 @@ class N2VCJujuConnector(N2VCConnector):
         self.libjuju = Libjuju(
             endpoint=self.url,
             api_proxy=self.api_proxy,
-            enable_os_upgrade=self.enable_os_upgrade,
-            apt_mirror=self.apt_mirror,
             username=self.username,
             password=self.secret,
             cacert=self.ca_cert,
@@ -188,6 +179,7 @@ class N2VCJujuConnector(N2VCConnector):
             log=self.log,
             db=self.db,
             n2vc=self,
+            model_config=model_config,
         )
 
         # create juju pub key file in lcm container at
@@ -782,15 +774,16 @@ class N2VCJujuConnector(N2VCConnector):
                 # destroy the model
                 # TODO: should this be removed?
                 await self.libjuju.destroy_model(
-                    model_name=model_name, total_timeout=total_timeout
+                    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)
+                    model_name=model_name,
+                    application_name=application_name,
+                    total_timeout=total_timeout,
+                )
         except Exception as e:
             raise N2VCException(
                 message=(
@@ -798,18 +791,6 @@ class N2VCJujuConnector(N2VCConnector):
                 ).format(ee_id, application_name, e)
             )
 
-        # destroy the machine
-        # try:
-        #     await self._juju_destroy_machine(
-        #         model_name=model_name,
-        #         machine_id=machine_id,
-        #         total_timeout=total_timeout
-        #     )
-        # except Exception as e:
-        #     raise N2VCException(
-        #        message='Error deleting execution environment {} (machine {}) : {}'
-        #                .format(ee_id, machine_id, e))
-
         self.log.info("Execution environment {} deleted".format(ee_id))
 
     async def exec_primitive(