Add credential_name option for add_k8s() and add_cloud()
[osm/N2VC.git] / n2vc / libjuju.py
index d2c725f..a00fa58 100644 (file)
@@ -160,12 +160,14 @@ class Libjuju:
         """
         await controller.disconnect()
 
         """
         await controller.disconnect()
 
-    async def add_model(self, model_name: str, cloud_name: str):
+    async def add_model(self, model_name: str, cloud_name: str, credential_name=None):
         """
         Create model
 
         :param: model_name: Model name
         :param: cloud_name: Cloud name
         """
         Create model
 
         :param: model_name: Model name
         :param: cloud_name: Cloud name
+        :param: credential_name: Credential name to use for adding the model
+                                 If not specified, same name as the cloud will be used.
         """
 
         # Get controller
         """
 
         # Get controller
@@ -193,7 +195,7 @@ class Libjuju:
                     model_name,
                     config=self.model_config,
                     cloud_name=cloud_name,
                     model_name,
                     config=self.model_config,
                     cloud_name=cloud_name,
-                    credential_name=cloud_name,
+                    credential_name=credential_name or cloud_name,
                 )
                 self.models.add(model_name)
         finally:
                 )
                 self.models.add(model_name)
         finally:
@@ -1023,16 +1025,21 @@ class Libjuju:
             await self.disconnect_controller(controller)
 
     async def add_k8s(
             await self.disconnect_controller(controller)
 
     async def add_k8s(
-        self, name: str, configuration: Configuration, storage_class: str
+        self,
+        name: str,
+        configuration: Configuration,
+        storage_class: str,
+        credential_name: str = None,
     ):
         """
         Add a Kubernetes cloud to the controller
 
         Similar to the `juju add-k8s` command in the CLI
 
     ):
         """
         Add a Kubernetes cloud to the controller
 
         Similar to the `juju add-k8s` command in the CLI
 
-        :param: name:           Name for the K8s cloud
-        :param: configuration:  Kubernetes configuration object
-        :param: storage_class:  Storage Class to use in the cloud
+        :param: name:               Name for the K8s cloud
+        :param: configuration:      Kubernetes configuration object
+        :param: storage_class:      Storage Class to use in the cloud
+        :param: credential_name:    Storage Class to use in the cloud
         """
 
         if not storage_class:
         """
 
         if not storage_class:
@@ -1060,7 +1067,9 @@ class Libjuju:
             },
         )
 
             },
         )
 
-        return await self.add_cloud(name, cloud, credential)
+        return await self.add_cloud(
+            name, cloud, credential, credential_name=credential_name
+        )
 
     def get_k8s_cloud_credential(
         self, configuration: Configuration,
 
     def get_k8s_cloud_credential(
         self, configuration: Configuration,
@@ -1117,20 +1126,28 @@ class Libjuju:
         return client.CloudCredential(auth_type=auth_type, attrs=attrs,)
 
     async def add_cloud(
         return client.CloudCredential(auth_type=auth_type, attrs=attrs,)
 
     async def add_cloud(
-        self, name: str, cloud: Cloud, credential: CloudCredential = None
+        self,
+        name: str,
+        cloud: Cloud,
+        credential: CloudCredential = None,
+        credential_name: str = None,
     ) -> Cloud:
         """
         Add cloud to the controller
 
     ) -> Cloud:
         """
         Add cloud to the controller
 
-        :param: name:   Name of the cloud to be added
-        :param: cloud:  Cloud object
-        :param: credential:   CloudCredentials object for the cloud
+        :param: name:               Name of the cloud to be added
+        :param: cloud:              Cloud object
+        :param: credential:         CloudCredentials object for the cloud
+        :param: credential_name:    Credential name.
+                                    If not defined, cloud of the name will be used.
         """
         controller = await self.get_controller()
         try:
             _ = await controller.add_cloud(name, cloud)
             if credential:
         """
         controller = await self.get_controller()
         try:
             _ = await controller.add_cloud(name, cloud)
             if credential:
-                await controller.add_credential(name, credential=credential, cloud=name)
+                await controller.add_credential(
+                    credential_name or name, credential=credential, cloud=name
+                )
             # Need to return the object returned by the controller.add_cloud() function
             # I'm returning the original value now until this bug is fixed:
             #   https://github.com/juju/python-libjuju/issues/443
             # Need to return the object returned by the controller.add_cloud() function
             # I'm returning the original value now until this bug is fixed:
             #   https://github.com/juju/python-libjuju/issues/443