307 |
307 |
self.write_config('server_port', server_port)
|
308 |
308 |
self.logger.debug("Server's ssh port is %s" % _green(server_port))
|
309 |
309 |
self.logger.debug("Access server using \"ssh -p %s %s@%s\"" %
|
310 |
|
(server_port, fabric.env.user, server_ip))
|
|
310 |
(server_port, server['metadata']['users'], server_ip))
|
311 |
311 |
|
312 |
312 |
@_check_fabric
|
313 |
313 |
def _copy_ssh_keys(self, ssh_keys):
|
314 |
314 |
"""Upload/Install ssh keys to server"""
|
315 |
|
self.logger.debug("Check for authentication keys to upload")
|
|
315 |
self.logger.debug("Check for authentication keys to use")
|
316 |
316 |
if ssh_keys is None:
|
317 |
317 |
ssh_keys = self.config.get("Deployment", "ssh_keys")
|
318 |
318 |
|
319 |
|
if ssh_keys != "" and os.path.exists(ssh_keys):
|
|
319 |
if ssh_keys != "":
|
|
320 |
self.logger.debug("Will use %s authentication keys file" % ssh_keys)
|
320 |
321 |
keyfile = '/tmp/%s.pub' % fabric.env.user
|
321 |
322 |
_run('mkdir -p ~/.ssh && chmod 700 ~/.ssh', False)
|
322 |
|
_put(ssh_keys, keyfile)
|
|
323 |
if ssh_keys.startswith("http://") or \
|
|
324 |
ssh_keys.startswith("https://") or \
|
|
325 |
ssh_keys.startswith("ftp://"):
|
|
326 |
cmd = """
|
|
327 |
apt-get update
|
|
328 |
apt-get install wget --yes
|
|
329 |
wget {0} -O {1} --no-check-certificate
|
|
330 |
""".format(ssh_keys, keyfile)
|
|
331 |
_run(cmd, False)
|
|
332 |
elif os.path.exists(ssh_keys):
|
|
333 |
_put(ssh_keys, keyfile)
|
|
334 |
else:
|
|
335 |
self.logger.debug("No ssh keys found")
|
323 |
336 |
_run('cat %s >> ~/.ssh/authorized_keys' % keyfile, False)
|
324 |
337 |
_run('rm %s' % keyfile, False)
|
325 |
338 |
self.logger.debug("Uploaded ssh authorized keys")
|