Skip to content

Commit 7c4722a

Browse files
author
David Garcia
committed
Fix bug #406: Get api_endpoints directly from the controller
1 parent d7cfc98 commit 7c4722a

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

juju/client/connector.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ async def connect(self, **kwargs):
6767
for macaroon in kwargs.pop('macaroons'):
6868
jar.set_cookie(go_to_py_cookie(macaroon))
6969
self._connection = await Connection.connect(**kwargs)
70-
controller = self.jujudata.controllers()[
71-
self.jujudata.current_controller()
72-
]
73-
self._connection.endpoints = [
74-
(e, controller["ca-cert"])
75-
for e in controller["api-endpoints"]
76-
]
7770

7871
async def disconnect(self):
7972
"""Shut down the watcher task and close websockets.

juju/controller.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ async def connect(self, *args, **kwargs):
144144
raise ValueError('Authentication parameters are required '
145145
'if controller_name not given')
146146
await self._connector.connect(**kwargs)
147+
info = await self.info()
148+
self._connector._connection.endpoints = [
149+
(e, info.results[0].cacert)
150+
for e in info.results[0].addresses
151+
]
147152

148153
async def connect_current(self):
149154
"""
@@ -181,12 +186,13 @@ def controller_uuid(self):
181186
return self._connector.controller_uuid
182187

183188
@property
184-
def api_endpoints(self):
185-
controller_name = self._connector.jujudata.current_controller()
186-
if controller_name:
187-
return self._connector.jujudata.controllers().get(controller_name).get(
188-
"api-endpoints"
189-
)
189+
async def api_endpoints(self):
190+
"""Get API endpoints
191+
192+
:return list string: List of API Endpoints
193+
"""
194+
info = await self.info()
195+
return info.results[0].addresses
190196

191197
async def disconnect(self):
192198
"""Shut down the watcher task and close websockets.
@@ -273,6 +279,17 @@ async def add_cloud(self, name, cloud):
273279
result = await self.cloud(name=name)
274280
return result.cloud
275281

282+
async def info(self):
283+
"""Show Controller Info from connection
284+
285+
:return ControllerAPIInfoResult
286+
"""
287+
log.debug('Getting information')
288+
uuids = await self.model_uuids()
289+
controller_facade = client.ControllerFacade.from_connection(self.connection())
290+
params = [client.Entity(tag.model(uuids["controller"]))]
291+
return await controller_facade.ControllerAPIInfoForModels(entities=params)
292+
276293
async def remove_cloud(self, name):
277294
"""Remove a cloud from this controller.
278295

0 commit comments

Comments
 (0)