Manage Images with the OpenStack Glance Client

Updated 6 months ago by Brian Banaszynski

This tutorial provides basic recipes for manipulating images using glance.

Upload an Image from a File

DSM’s cloud platform 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, Miruma 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:
$ 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

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

glance image-create --progress --disk-format qcow2 --container-format bare --file ~/images/my-qcow2-img.img --visibility private --name myimage --property pf9_description='my cloud image' --property pf9_virtual_size=41126400
 Scope of image accessibility Valid values: public, private, community, shared

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>

View Image Properties

Using the glance option image-show, you can view image properties:

$ glance image-show myimage
          | Property | Value |
          | Property 'pf9_description' | cirros cloud image |
          | 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 | private |
          | 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

Using the glance option image-delete, you can delete an image:

glance image-delete <IMAGE_ID>

Download an Image

Using the glance option image-download, you can download an image:

glance image-download [--file ] [--progress] <IMAGE_ID>

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-regionparameter. This argument is added before the command.

For example, to create the above ‘myimage’ image on the ‘WH-KVM01’ region, invoke the client as follows:

glance --os-region WH-KVM01 image-create --disk-format qcow2 --container-format bare --file ~/images/my-qcow2-img.img --visibility private --name myimage --property pf9_description='my cloud image' --property pf9_virtual_size=41126400

How Did We Do?