Delete created keypairs if nova boot fails

If the server fails to boot (perhaps due to quota issues) during
an image update, if nodepool created a key for that server it won't
be deleted because the existing keypair delete is done as part of
deleting the server.  Handle the special case of never having
actually booted a server and delete the keypair explicitly in that
case.

Change-Id: I0607b77ef2d52cbb8a81feb5e9c502b080a51dbe
This commit is contained in:
James E. Blair 2014-03-19 15:03:35 -07:00
parent bd6f5cdf54
commit 6ab771728e

View File

@ -479,10 +479,21 @@ class ImageUpdater(threading.Thread):
else:
image_name = self.image.base_image
image_id = None
server_id = self.manager.createServer(
hostname, self.image.min_ram, image_name=image_name,
key_name=key_name, name_filter=self.image.name_filter,
image_id=image_id)
try:
server_id = self.manager.createServer(
hostname, self.image.min_ram, image_name=image_name,
key_name=key_name, name_filter=self.image.name_filter,
image_id=image_id)
except Exception:
if (self.manager.hasExtension('os-keypairs') and
not self.provider.keypair):
for kp in self.manager.listKeypairs():
if kp['name'] == key_name:
self.log.debug(
'Deleting keypair for failed image build %s' %
self.snap_image.id)
self.manager.deleteKeypair(kp['name'])
raise
self.snap_image.hostname = hostname
self.snap_image.version = timestamp