Tutorial: Manage Images with the OpenStack Glance Client

This tutorial provides basic recipes for manipulating images using OpenStack glance.

Requirements

You will first need to install the OpenStack Glance Client on one of your systems. Follow the Tutorial on Installing OpenStack CLI Clients to install the OpenStack Glance Client, and set the required environment variables.

Upload an Image from a File

Platform9 uses a few custom parameters to help improve user experience. These include:

To upload an image named 'myimage' with these custom properties, call glance image-create as follows:

glance image-create --disk-format qcow2
--container-format bare
--file ~/images/my-qcow2-img.img
--visibility public
--name myimage
--property pf9_description='best image ever'
--property pf9_virtual_size=41126400

Note that the --visibility public flag makes the image available to all tenants. Without this, it's only available in the current tenant.

If you forget to set the virtual size when creating an image, you can always update it later:

glance image-update --property pf9_virtual_size=<virtual size>

Where virtual size is calculated (in bytes) by qemu-img info as above.

View Image Properties

$ glance image-show myimage
+-----------------------------+----------------------------------------------------------------------------------+
| Property | Value |
+-----------------------------+----------------------------------------------------------------------------------+
| Property 'pf9_description' | best image ever |
| Property 'pf9_virtual_size' | 41126400 |
| checksum | 133eae9fb1c98f45894a4e60d8736619 |
| container_format | bare |
| created_at | 2015-08-28T00:23:38 |
| deleted | False |
| disk_format | qcow2 |
| id | 3d7a846a-b753-4440-8101-5dda991faed9 |
| visibility | public |
| location | file:///var/opt/pf9/imagelibrary/data/glance/3d7a846a-b753-4440-8101-5dda991faed |
| | 9 |
| location_data | [{u'url': u'file:///var/opt/pf9/imagelibrary/data/glance/3d7a846a-b753-4440-8101 |
| | -5dda991faed9'
, u'status': u'active', u'id': 81942, u'metadata': {}}] |
| min_disk | 0 |
| min_ram | 0 |
| name | myimage |
| owner | f175f441ebbb4c2b8fedf6469d6415fc |
| protected | False |
| size | 13200896 |
| status | active |
| updated_at | 2015-08-28T00:23:40 |
+-----------------------------+----------------------------------------------------------------------------------+

Delete an Image

glance image-delete myimage

Managing Images in Multiple Regions

As with other OpenStack command-line clients, when managing glance images for multiple OpenStack regions, you must specify the region name for all operations using the --os-region parameter. This argument is added before the command. For example, to create the above 'myimage' image on the 'williamsport-pa' region, invoke the client as follows:

glance --os-region williamsport-pa image-create
--disk-format qcow2
--container-format bare
--file ~/images/my-qcow2-img.img
--visibility public
--name myimage
--property pf9_description='best image ever'
--property pf9_virtual_size=41126400


November 16, 2015