import yaml
-from juju.errors import JujuAPIError
+from juju.errors import JujuAPIError, JujuConnectionError
log = logging.getLogger("websocket")
"""
jujudata = JujuData()
controller_name = jujudata.current_controller()
+ if not controller_name:
+ raise JujuConnectionError('No current controller')
return await cls.connect_controller(controller_name)
self.path = os.path.abspath(os.path.expanduser(self.path))
def current_controller(self):
- cmd = shlex.split('juju show-controller --format yaml')
+ cmd = shlex.split('juju list-controllers --format yaml')
output = subprocess.check_output(cmd)
output = yaml.safe_load(output)
- return list(output.keys())[0]
+ return output.get('current-controller', '')
def controllers(self):
return self._load_yaml('controllers.yaml', 'controllers')
self.response = result['response']
self.request_id = result['request-id']
super().__init__(self.message)
+
+
+class JujuConnectionError(ConnectionError):
+ pass