Feature 8720: Add scale support
[osm/N2VC.git] / n2vc / k8s_juju_conn.py
index 7a3bf27..b2ef079 100644 (file)
@@ -16,12 +16,13 @@ import asyncio
 import concurrent
 import os
 import uuid
+import yaml
 
 import juju
 from juju.controller import Controller
+from juju.model import Model
 from n2vc.exceptions import K8sException
 from n2vc.k8s_conn import K8sConnector
-import yaml
 
 from .exceptions import MethodNotImplemented
 
@@ -334,8 +335,10 @@ class K8sJujuConnector(K8sConnector):
                     in the package>
                 - <URL_where_to_fetch_juju_bundle>
             """
-
-            previous_workdir = os.getcwd()
+            try:
+                previous_workdir = os.getcwd()
+            except FileNotFoundError:
+                previous_workdir = "/app/storage"
 
             bundle = kdu_model
             if kdu_model.startswith("cs:"):
@@ -728,7 +731,7 @@ class K8sJujuConnector(K8sConnector):
 
         return True
 
-    async def add_model(self, model_name: str, cluster_uuid: str,) -> juju.model.Model:
+    async def add_model(self, model_name: str, cluster_uuid: str,) -> Model:
         """Adds a model to the controller
 
         Adds a new model to the Juju controller
@@ -744,9 +747,12 @@ class K8sJujuConnector(K8sConnector):
             "Adding model '{}' to cluster_uuid '{}'".format(model_name, cluster_uuid)
         )
         try:
-            model = await self.controller.add_model(
-                model_name, config={"authorized-keys": self.juju_public_key}
-            )
+            if self.juju_public_key is not None:
+                model = await self.controller.add_model(
+                    model_name, config={"authorized-keys": self.juju_public_key}
+                )
+            else:
+                model = await self.controller.add_model(model_name)
         except Exception as ex:
             self.log.debug(ex)
             self.log.debug("Caught exception: {}".format(ex))
@@ -850,7 +856,7 @@ class K8sJujuConnector(K8sConnector):
                 "Unable to locate configuration for cluster {}".format(cluster_uuid)
             )
 
-    async def get_model(self, model_name: str, cluster_uuid: str,) -> juju.model.Model:
+    async def get_model(self, model_name: str, cluster_uuid: str,) -> Model:
         """Get a model from the Juju Controller.
 
         Note: Model objects returned must call disconnected() before it goes