X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fcontroller.py;h=135027a597273416afd7006663875ff360a3a333;hb=c8a68279c2043d7b3d3789a881826d52074af04e;hp=2bcb2e7184535fb2b76ced05f52c0950a44c77a4;hpb=ca170102476524e17c37d2efac3ce60f6ac6f326;p=osm%2FN2VC.git diff --git a/juju/controller.py b/juju/controller.py index 2bcb2e7..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,14 @@ 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) - except Exception as e: + + 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 " "to ssh into machines in this model. " @@ -119,6 +126,7 @@ class Controller(object): self.connection.password, self.connection.cacert, self.connection.macaroons, + loop=self.loop, ) return model