Check if cloud is built-in cloud when adding a model 33/8833/3
authorDavid Garcia <david.garcia@canonical.com>
Wed, 29 Apr 2020 10:34:23 +0000 (12:34 +0200)
committerDavid Garcia <david.garcia@canonical.com>
Thu, 30 Apr 2020 08:27:49 +0000 (10:27 +0200)
Change-Id: Iad5f8e8f614898b2be38c6c40f97d6bbe97964cd
Signed-off-by: David Garcia <david.garcia@canonical.com>
n2vc/n2vc_juju_conn.py

index 40f46f1..f48838d 100644 (file)
@@ -54,6 +54,8 @@ class N2VCJujuConnector(N2VCConnector):
     ##################################################################################################
     """
 
+    BUILT_IN_CLOUDS = ["localhost", "microk8s"]
+
     def __init__(
         self,
         db: object,
@@ -1177,12 +1179,19 @@ class N2VCJujuConnector(N2VCConnector):
                 if not self.enable_os_upgrade:
                     config_dict['enable-os-refresh-update'] = False
                     config_dict['enable-os-upgrade'] = False
-
-                model = await self.controller.add_model(
-                    model_name=model_name,
-                    config=config_dict,
-                    cloud_name=self.cloud,
-                )
+                if self.cloud in self.BUILT_IN_CLOUDS:
+                    model = await self.controller.add_model(
+                        model_name=model_name,
+                        config=config_dict,
+                        cloud_name=self.cloud,
+                    )
+                else:
+                    model = await self.controller.add_model(
+                        model_name=model_name,
+                        config=config_dict,
+                        cloud_name=self.cloud,
+                        credential_name="admin"
+                    )
                 self.log.info('New model created, name={}'.format(model_name))
             else:
                 self.log.debug('Model already exists in juju. Getting model {}'.format(model_name))