removing cli command to add ssh keys (#161)
authorSébastien Pattyn <sebastien.pattyn@gmail.com>
Thu, 28 Sep 2017 19:52:31 +0000 (15:52 -0400)
committerCory Johns <johnsca@gmail.com>
Thu, 28 Sep 2017 19:52:31 +0000 (15:52 -0400)
* removing cli command to add ssh keys

* add ssh-key after model-creation

* awaiting method

* Update controller.py

* adding user ssh-key when model is created

* fixed wrong config placement

juju/controller.py

index 9b452c7..98dd59d 100644 (file)
@@ -95,6 +95,10 @@ class Controller(object):
             credential = None
 
         log.debug('Creating model %s', model_name)
+        
+        if not config or 'authorized-keys' not in config:
+            config = config or {}
+            config['authorized-keys'] = await utils.read_ssh_key(loop=self.loop)
 
         model_info = await model_facade.CreateModel(
             tag.cloud(cloud_name),
@@ -105,24 +109,6 @@ class Controller(object):
             region
         )
 
-        # Add our ssh key to the model, to work around
-        # https://bugs.launchpad.net/juju/+bug/1643076
-        try:
-            ssh_key = await utils.read_ssh_key(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 "
-                "to ssh into machines in this model. "
-                "Manually running `juju add-ssh-key <key>` in the cli "
-                "may fix this problem.")
-
         model = Model()
         await model.connect(
             self.connection.endpoint,
@@ -136,6 +122,7 @@ class Controller(object):
 
         return model
 
+
     async def destroy_models(self, *uuids):
         """Destroy one or more models.