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
This commit is contained in:
Ian Wienand 2016-08-24 06:33:51 +10:00
parent 4ed43d2754
commit ab376eac7a

View File

@ -240,14 +240,26 @@ def build_server(cloud, name, image, flavor,
print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % ( print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (
server.id, server.public_v4, server.public_v6)) server.id, server.public_v4, server.public_v6))
except Exception: except Exception:
print "****"
print "Server %s failed to build!" % (server.id)
try: try:
if keep: 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: else:
cloud.delete_server(server.id, delete_ips=True) cloud.delete_server(server.id, delete_ips=True)
except Exception: except Exception:
print "Exception encountered deleting server:" print "Exception encountered deleting server:"
traceback.print_exc() traceback.print_exc()
print "The original exception follows:"
print "****"
# Raise the important exception that started this # Raise the important exception that started this
raise raise