From: David Garcia Date: Fri, 16 Oct 2020 13:38:13 +0000 (+0200) Subject: Add credential_name option for add_k8s() and add_cloud() X-Git-Tag: release-v9.0-start~13 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F9861%2F1;p=osm%2FN2VC.git Add credential_name option for add_k8s() and add_cloud() Change-Id: I4adf740231e4c0d8785768631a8f2daedc198947 Signed-off-by: David Garcia --- diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index 0fa42f8..a00fa58 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -1025,16 +1025,21 @@ class Libjuju: 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 - :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: @@ -1062,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, @@ -1119,20 +1126,28 @@ class Libjuju: 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 - :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: - 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