|
7 | 7 | import macaroonbakery.httpbakery as httpbakery |
8 | 8 | from juju.client.connection import Connection |
9 | 9 | from juju.client.gocookies import GoCookieJar, go_to_py_cookie |
10 | | -from juju.client.jujudata import FileJujuData |
| 10 | +from juju.client.jujudata import FileJujuData, API_ENDPOINTS_KEY |
11 | 11 | from juju.client.proxy.factory import proxy_from_config |
12 | | -from juju.errors import JujuConnectionError, JujuError |
| 12 | +from juju.errors import JujuConnectionError, JujuError, PylibjujuProgrammingError |
13 | 13 | from juju.client import client |
14 | 14 | from juju.version import SUPPORTED_MAJOR_VERSION, TARGET_JUJU_VERSION |
15 | 15 |
|
@@ -83,6 +83,11 @@ async def connect(self, **kwargs): |
83 | 83 | await self._connection.close() |
84 | 84 | self._connection = await Connection.connect(**kwargs) |
85 | 85 |
|
| 86 | + if not self.controller_name: |
| 87 | + if 'endpoint' not in kwargs: |
| 88 | + raise PylibjujuProgrammingError("Please report this error to the maintainers.") |
| 89 | + self.controller_name = self.jujudata.controller_name_by_endpoint(kwargs['endpoint']) |
| 90 | + |
86 | 91 | # Check if we support the target controller |
87 | 92 | juju_server_version = self._connection.info['server-version'] |
88 | 93 | if not juju_server_version.startswith(TARGET_JUJU_VERSION): |
@@ -112,7 +117,7 @@ async def connect_controller(self, controller_name=None, specified_facades=None) |
112 | 117 | raise JujuConnectionError('No current controller') |
113 | 118 |
|
114 | 119 | controller = self.jujudata.controllers()[controller_name] |
115 | | - endpoints = controller['api-endpoints'] |
| 120 | + endpoints = controller[API_ENDPOINTS_KEY] |
116 | 121 | accounts = self.jujudata.accounts().get(controller_name, {}) |
117 | 122 |
|
118 | 123 | proxy = proxy_from_config(controller.get('proxy-config', None)) |
@@ -146,7 +151,7 @@ async def connect_model(self, _model_name=None, **kwargs): |
146 | 151 | if controller is None: |
147 | 152 | raise JujuConnectionError('Controller {} not found'.format( |
148 | 153 | controller_name)) |
149 | | - endpoints = controller['api-endpoints'] |
| 154 | + endpoints = controller[API_ENDPOINTS_KEY] |
150 | 155 | account = self.jujudata.accounts().get(controller_name, {}) |
151 | 156 | models = self.jujudata.models().get(controller_name, {}).get('models', |
152 | 157 | {}) |
|
0 commit comments