pycontribs / pyrax

The Python SDK for the Rackspace Cloud
developer.rackspace.com
Apache License 2.0
237 stars 208 forks source link

create_image function returns a string #518

Open stevekaten opened 9 years ago

stevekaten commented 9 years ago

Example:

image_id =  cs.servers.create_image(server, "NAME")
pyrax.utils.wait_until(image, "status", "ACTIVE", interval=10, attempts=30)

The wait_until function requires an object. The create_image function returns a string. This requires another request to get the object just to use wait_until:

image_id =  cs.servers.create_image(server, "NAME")
image = cs.images.get(image_id)
pyrax.utils.wait_until(image, "status", "ACTIVE", interval=10, attempts=30)
EdLeafe commented 9 years ago

Unfortunately, that's a result of the dependency on novaclient. You can work around it like this:

image_id =  cs.servers.create_image(server, "NAME")
image_obj = cs.images.get(image_id)
pyrax.utils.wait_until(image, "status", ["ACTIVE", "ERROR"], interval=10, attempts=30)

Note that I added a second condition to the wait_until call; image creation fails sometimes, and you always want to be able to handle that condition, too.