From 7c4722a0de73288c0a235312ae6cbb357f63b8dd Mon Sep 17 00:00:00 2001 From: David Garcia Date: Wed, 29 Apr 2020 09:45:05 +0200 Subject: [PATCH] Fix bug #406: Get api_endpoints directly from the controller --- juju/client/connector.py | 7 ------- juju/controller.py | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/juju/client/connector.py b/juju/client/connector.py index 9502bd6e2..6fa27b6b0 100644 --- a/juju/client/connector.py +++ b/juju/client/connector.py @@ -67,13 +67,6 @@ async def connect(self, **kwargs): for macaroon in kwargs.pop('macaroons'): jar.set_cookie(go_to_py_cookie(macaroon)) self._connection = await Connection.connect(**kwargs) - controller = self.jujudata.controllers()[ - self.jujudata.current_controller() - ] - self._connection.endpoints = [ - (e, controller["ca-cert"]) - for e in controller["api-endpoints"] - ] async def disconnect(self): """Shut down the watcher task and close websockets. diff --git a/juju/controller.py b/juju/controller.py index 1441e58bb..88a363625 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -144,6 +144,11 @@ async def connect(self, *args, **kwargs): raise ValueError('Authentication parameters are required ' 'if controller_name not given') await self._connector.connect(**kwargs) + info = await self.info() + self._connector._connection.endpoints = [ + (e, info.results[0].cacert) + for e in info.results[0].addresses + ] async def connect_current(self): """ @@ -181,12 +186,13 @@ def controller_uuid(self): return self._connector.controller_uuid @property - def api_endpoints(self): - controller_name = self._connector.jujudata.current_controller() - if controller_name: - return self._connector.jujudata.controllers().get(controller_name).get( - "api-endpoints" - ) + async def api_endpoints(self): + """Get API endpoints + + :return list string: List of API Endpoints + """ + info = await self.info() + return info.results[0].addresses async def disconnect(self): """Shut down the watcher task and close websockets. @@ -273,6 +279,17 @@ async def add_cloud(self, name, cloud): result = await self.cloud(name=name) return result.cloud + async def info(self): + """Show Controller Info from connection + + :return ControllerAPIInfoResult + """ + log.debug('Getting information') + uuids = await self.model_uuids() + controller_facade = client.ControllerFacade.from_connection(self.connection()) + params = [client.Entity(tag.model(uuids["controller"]))] + return await controller_facade.ControllerAPIInfoForModels(entities=params) + async def remove_cloud(self, name): """Remove a cloud from this controller.