Split waiting for images into its own method

Nodepool got bit by incorrectly waiting for images. So let's copy the
wait_for_server pattern and make a wait_for_image method that knows how
to properly wait for an image to become ready.

Change-Id: Icac2606ae4d51c6fde5066e767b53a6baa14dd50
This commit is contained in:
Monty Taylor 2016-03-25 14:37:02 -05:00
parent d9867f4922
commit de364270bc

View File

@ -2064,20 +2064,30 @@ class OpenStackCloud(object):
return image.id
return None
def create_image_snapshot(self, name, server, wait=False, timeout=3600,
**metadata):
def create_image_snapshot(
self, name, server, wait=False, timeout=3600, **metadata):
image_id = str(self.manager.submitTask(_tasks.ImageSnapshotCreate(
image_name=name, server=server, metadata=metadata)))
self.list_images.invalidate(self)
image = self.get_image(image_id)
if not wait:
return self.get_image(image_id)
for count in _utils._iterate_timeout(timeout,
"Timeout waiting for image to "
"snapshot"):
return image
return self.wait_for_image(image, timeout=timeout)
def wait_for_image(self, image, timeout=3600):
image_id = image['id']
for count in _utils._iterate_timeout(
timeout, "Timeout waiting for image to snapshot"):
self.list_images.invalidate(self)
image = self.get_image(image_id)
if not image:
continue
if image['status'] == 'active':
return image
elif image['status'] == 'error':
raise OpenStackCloudException(
'Image {image} hit error state'.format(image=image_id))
def delete_image(self, name_or_id, wait=False, timeout=3600):
image = self.get_image(name_or_id)