From ab376eac7a636362ef7b0d973500fce9669eaba1 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 24 Aug 2016 06:33:51 +1000 Subject: [PATCH] launch-node.py: save key when failing early Save the key to a file in /tmp when failing early with --keep. Although it is put into the JobDir later, if we fail before that we're locked out of the host. While we're here, make what just happened in an error case a little clearer Change-Id: Ide601e2018302664bc4ad609c4483aa1451b3724 --- launch/launch-node.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/launch/launch-node.py b/launch/launch-node.py index 11802f5202..d23f226cf6 100755 --- a/launch/launch-node.py +++ b/launch/launch-node.py @@ -240,14 +240,26 @@ def build_server(cloud, name, image, flavor, print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % ( server.id, server.public_v4, server.public_v6)) except Exception: + print "****" + print "Server %s failed to build!" % (server.id) try: if keep: - print "Server failed to build, keeping as requested." + print "Keeping as requested" + # Write out the private SSH key we generated, as we + # may not have got far enough for ansible to run + with open('/tmp/%s.id_rsa' % server.id, 'w') as key_file: + key.write_private_key(key_file) + os.chmod(key_file.name, 0o600) + print "Private key saved in %s" % key_file.name + print "Run to delete -> openstack server delete %s" % \ + (server.id) else: cloud.delete_server(server.id, delete_ips=True) except Exception: print "Exception encountered deleting server:" traceback.print_exc() + print "The original exception follows:" + print "****" # Raise the important exception that started this raise