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:
    $ 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 --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

Vamsi Chemitiganti

Chief Strategist at Platform9 Systems. Vamsi works with Platform9's Client CXOs and Architects to help them on key business transformation initiatives.

In previous roles, Vamsi was the CTO for RiskCounts - a FinTech based in NYC. Prior to that spent eight years as the Chief Architect for Red Hat’s Global Financial Services Vertical based out of NYC. Vamsi also spent two years as the General Manager (Financial Services) at Hortonworks. In both roles, Vamsi was responsible for driving Red Hat and Hortonworks technology vision from a client business standpoint. The clients Vamsi engages with on a daily basis span marquee financial services names across major banking centers in Wall Street, Toronto, London & in Asia. These include businesses in capital markets, retail banking, wealth management and IT operations.holds a BS in Computer Science and Engineering as well as an MBA from the University of Maryland, College Park. He is also a regular speaker at industry events on topics ranging from Cloud Computing, Big Data, AI, High-Performance Computing and Enterprise Middleware. In 2013, Wall Street and Technology Magazine identified Vamsi as a Global Thought Leader. Vamsi writes weekly on financial services business and technology landscape at his highly influential blog – http://www.vamsitalkstech.com
Avatar

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