Glance as a registry of images

At launch, a generic virtual machine requires a prebuilt disk image to boot from – some kind of storage that holds the operating system using which the virtual machine will run. Traditionally, a new virtual machine is created with a form of installation media accessible to it. This could take the form of an ISO, optical device, or maybe some form of network-accessible media. Whatever media is provided, an operating system installation is the next step in this scenario. One of the purposes of cloud computing is to be able to quickly create disposable virtual instances. The tasks of running an operating system installation and spawning a virtual machine fast are polar opposites of each other. Cloud computing has removed the need for a per-instance operating system installation by creating what have come to be known as cloud images. Cloud images are simply pre-installed bootable disk images that have been sealed. A sealed disk image is a sparse file containing a filesystem and an underlying operating system that has had its identifiable host-specific metadata removed. Host-specific items include things such as SSH host keys, MAC addresses, static IP addresses, persistent udev rules, and any other identifiers that would conflict if used by two of the same servers. Do you see where this is going? These images are imported into the Glance registry and then copied out to the compute nodes for the instances to launch with. We are going to first look at downloading a pre-baked image and registering it with Glance. Then, we'll look at what's needed to build your own custom image.

Downloading and registering an image

If you search the Internet for cloud image, you'll most likely get a link to a place to download a disk image from and import into Glance; most of the major distributions out there have one already built and ready to go for you. In general, they are distributed as qcow2 or RAW images, and for the vast majority of cases, either of them will work fine. You will have to research them on your own to decide whether one or the other fits your use case better. There's also a test distribution, which is extra-super-small, called CirrOS. If you visit http://download.cirros-cloud.net download the .img file from the latest version is available.

Tip

Don't use CirrOS for anything other than testing. It is built with libraries that make it insecure for anything other than demonstration and testing.

To demonstrate using Glance, we will use the Fedora qcow cloud image downloaded from https://getfedora.org/; let's start with the command line. To interact with Glance, you'll need to be sure that you have sourced your overcloudrc file; refer to Chapter 2, Identity Management, if you need a refresher on this. You will just get an authentication error message if an overcloudrc file is not currently sourced. Go ahead and list the images registered in Glance, as shown in the following command:

undercloud# openstack image list

This should return nothing since there aren't any images in Glance yet.

Note

It is important to note here that this command would only list the images in the project to which the user is authenticating.

When you have sourced your non-admin user's overcloudrc file, you would get the Glance images for that user's project. When you have sourced the admin user's overcloudrc file, you will see all tenants' Glance images. Next let's upload an image to Glance so that there's an image in Glance for us to list. To do this, use the image-create command. It is important to understand that you are not creating the disk image with this command. You need to have an already built image; use the qcow2 file that you have just downloaded from Fedora. This image create command is creating a record of the image you are uploading in the Glance registry:

undercloud# openstack image create --public --disk-format qcow2 --container-format bare --file Fedora-x86_64-disk.qcow2 Fedora

You will notice that you can give your image a name other than the filename of the file that is being uploaded. The disk format and the container format are specific to the image file format that is being uploaded. There are other options for these parameters that you can use the OpenStack help command to read more about.

The public flag sets whether this image can be used across all tenants or is private to the tenant it is uploaded to. Now use the image-list command to list the image you just uploaded. Two images can have the same name; however, two images cannot have the same ID. There is also an argument that will protect the image from deletion and indicate that the image is protected (--protected). Administrators can't delete an image that is protected without first unprotecting the image. Let's use the image set command to set the image as protected. The following command captures the discussion in this paragraph:

undercloud# openstack image set --protected Fedora

In that example, the image's name was used to set the image as protected. It was mentioned that two images can have the same name; if they do, then the image's ID will have to be used instead of the image name. The properties for the images can be passed to image create or image set. Now that we've worked through using the command line to register a disk image with Glance, let's take a look at using the web interface.