From: Pete Vander Giessen Date: Fri, 31 Mar 2017 13:27:22 +0000 (-0400) Subject: Added controller to ssh fix. (#100) X-Git-Tag: 0.4.0~10 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=commitdiff_plain;h=088c31421225483fffffe91ef71fcbcb3d2d98ac Added controller to ssh fix. (#100) If a user has established a link to a controller other than the one in "focus" locally, our ssh key workaround doesn't work. This change fixes the issue by adding the controler name to the model name when appropriate. --- diff --git a/juju/controller.py b/juju/controller.py index b3d2ac1..135027a 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -22,6 +22,7 @@ class Controller(object): """ self.loop = loop or asyncio.get_event_loop() self.connection = None + self.controller_name = None async def connect( self, endpoint, username, password, cacert=None, macaroons=None): @@ -44,6 +45,7 @@ class Controller(object): """ self.connection = ( await connection.Connection.connect_controller(controller_name)) + self.controller_name = controller_name async def disconnect(self): """Shut down the watcher task and close websockets. @@ -102,9 +104,13 @@ class Controller(object): # https://bugs.launchpad.net/juju/+bug/1643076 try: ssh_key = await utils.read_ssh_key(loop=self.loop) - await utils.execute_process( - 'juju', 'add-ssh-key', '-m', model_name, ssh_key, log=log, - loop=self.loop) + + if self.controller_name: + model_name = "{}:{}".format(self.controller_name, model_name) + + cmd = ['juju', 'add-ssh-key', '-m', model_name, ssh_key] + + await utils.execute_process(*cmd, log=log, loop=self.loop) except Exception: log.exception( "Could not add ssh key to model. You will not be able "