Using OpenStack Image¶
Before working with the Image service, you’ll need to create a connection
to your OpenStack cloud by following the Connect user guide. This will
provide you with the conn
variable used in the examples below.
The primary resource of the Image service is the image.
List Images¶
An image is a collection of files for a specific operating system that you use to create or rebuild a server. OpenStack provides pre-built images. You can also create custom images, or snapshots, from servers that you have launched. Images come in different formats and are sometimes called virtual machine images.
def list_images(conn):
print("List Images:")
for image in conn.image.images():
print(image)
Full example: image resource list
Create Image¶
Create an image by uploading its data and setting its attributes.
def upload_image(conn):
print("Upload Image:")
# Load fake image data for the example.
data = 'This is fake image data.'
# Build the image attributes and upload the image.
image_attrs = {
'name': EXAMPLE_IMAGE_NAME,
'data': data,
'disk_format': 'raw',
'container_format': 'bare',
'visibility': 'public',
}
conn.image.upload_image(**image_attrs)
Full example: image resource create
Delete Image¶
Delete an image.
def delete_image(conn):
print("Delete Image:")
example_image = conn.image.find_image(EXAMPLE_IMAGE_NAME)
conn.image.delete_image(example_image, ignore_missing=False)
Full example: image resource delete