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:

  • pf9_description: a short description that is displayed with the image in the web UI
  • pf9_virtual_size: this is the size in bytes of the disk image if it were expanded to its full physical size. For raw images, this is simply the image file size. For sparse formats (like qcow2) it may be much larger than the file size. When deploying the image, Platform9 uses this value to decide whether or not the disk contents will fit on the virtual disk specified with the instance flavor. The virtual size of a disk can be viewed with the qemu-img tool:[code lang=”bash”]$ qemu-img info cirros-0.3.3-x86_64-disk.img
    image: cirros-0.3.3-x86_64-disk.img
    file format: qcow2
    virtual size: 39M (41126400 bytes)
    disk size: 13M
    cluster_size: 65536[/code]

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

[code lang=”bash”]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[/code]

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:

[code lang=”bash”]glance image-update –property pf9_virtual_size=<virtual size>[/code]

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

View Image Properties

[code lang=”bash”]$ 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 |
+—————————–+———————————————————————————-+[/code]

Delete an Image

[code lang=”bash”]glance image-delete myimage[/code]

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:

[code lang=”bash”]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[/code]

The browser you are using is outdated. For the best experience please download or update your browser to one of the following:

Leaving VMware? Get the VMware alternatives guideDownload now