9.2. Adding Images to Glance

To launch instances based on images stored in Glance you must first add some images. You must first have created or downloaded suitable images to use in an OpenStack environment. If you have not then refer to Section 9.1, “Building Images using Oz” and the Red Hat Enterprise Linux Virtualization_Host_Configuration_and_Guest_Installation_Guide for more information.

Important

It is recommended that the virt-sysprep command is run on Linux-based virtual machine images prior to uploading them to Glance. The virt-sysprep command re-initializes a disk image in preparation for use in a virtual environment. Operations it performs by default include removal of SSH keys, removal of persistent MAC addresses, and removal of user accounts.
The virt-sysprep command is available in the libguestfs-tools package in Red Hat Enterprise Linux.
$ sudo yum install -y libguestfs-tools
$ virt-sysprep --add FILE
Refer to the virt-sysprep manual page by running the man virt-sysprep command for information on enabling and disabling specific operations.

Procedure 9.2. Adding an Image to Glance

  1. Ensure that you have set the environment variables used for authenticating with Keystone by loading them from the keystonerc file associated with your user. Note that an administrative account is not required.
    $ source ~/keystonerc_user
  2. Use the glance image-create command to import your disk image:
    $ glance image-create --name "NAME" \
            --is-public IS_PUBLIC \
            --disk-format DISK_FORMAT \
            --container-format CONTAINER_FORMAT \
            --file IMAGE
    Replace the command line arguments to glance image-create with the appropriate values for your environment and disk image:
    • Replace NAME with the name that users will refer to the disk image by.
    • Replace IS_PUBLIC with true or false. Setting this value to true means that all users will be able to view and use the image.
    • Replace DISK_FORMAT with the format of the virtual machine disk image. Valid values include raw, vhd, vmdk, vdi, iso, qcow2, aki, ami, and ami.
      If the format of the virtual machine disk image is unknown then use the qemu-img info command to try and identify it.

      Example 9.2. Using qemu-img info

      In this example the qemu-img info is used to determine the format of a disk image stored in the file ./RHEL64.img.
      $ qemu-img info ./RHEL64.img
      image: ./RHEL64.img
      file format: qcow2
      virtual size: 5.0G (5368709120 bytes)
      disk size: 136K
      cluster_size: 65536

    • Replace CONTAINER_FORMAT with the container format of the image. The container format is bare unless the image is packaged in a file format such as ovf or ami that includes additional metadata related to the image.
    • Replace IMAGE with the local path to the image file to upload.
    Refer to the output of the glance help image-create command for more information about supported arguments to glance image-create.

    Note

    If the image being uploaded is not locally accessible but is available using a remote URL then provide it using the --location parameter instead of using the --file parameter.
    Note however that unless you also specify the --copy-from argument then Glance will not copy the image into the object store but instead it will be accessed remotely each time it is required.

    Example 9.3. Uploading an Image to Glance

    In this example the qcow2 format image in the file named rhel-64.qcow2 is uploaded to Glance. It is created in Glance as a publicly accessible image named RHEL 6.4.
    $ glance image-create --name "RHEL 6.4" --is-public true --disk-format qcow2 \
              --container-format bare \
              --file rhel-64.qcow2
    +------------------+--------------------------------------+
    | Property         | Value                                |
    +------------------+--------------------------------------+
    | checksum         | 2f81976cae15c16ef0010c51e3a6c163     |
    | container_format | bare                                 |
    | created_at       | 2013-01-25T14:45:48                  |
    | deleted          | False                                |
    | deleted_at       | None                                 |
    | disk_format      | qcow2                                |
    | id               | 0ce782c6-0d3e-41df-8fd5-39cd80b31cd9 |
    | is_public        | True                                 |
    | min_disk         | 0                                    |
    | min_ram          | 0                                    |
    | name             | RHEL 6.4                             |
    | owner            | b1414433c021436f97e9e1e4c214a710     |
    | protected        | False                                |
    | size             | 25165824                             |
    | status           | active                               |
    | updated_at       | 2013-01-25T14:45:50                  |
    +------------------+--------------------------------------+

  3. Use the glance image-list command to verify that your image was successfully uploaded.
     $ glance image-list
    +--------------+----------+-------------+------------------+----------+--------+
    | ID           | Name     | Disk Format | Container Format |Size      | Status |
    +--------------+----------+-------------+------------------+----------+--------+
    | 0ce782c6-... | RHEL 6.4 | qcow2       | bare             |213581824 | active |
    +--------------+----------+-------------+------------------+----------+--------+
    
    Use the glance image-show command to view more detailed information about an image. Use the identifier of the image to specify the image that you wish to view.
    $ glance image-show 0ce782c6-0d3e-41df-8fd5-39cd80b31cd9
    +------------------+--------------------------------------+
    | Property         | Value                                |
    +------------------+--------------------------------------+
    | checksum         | 2f81976cae15c16ef0010c51e3a6c163     |
    | container_format | bare                                 |
    | created_at       | 2013-01-25T14:45:48                  |
    | deleted          | False                                |
    | disk_format      | qcow2                                |
    | id               | 0ce782c6-0d3e-41df-8fd5-39cd80b31cd9 |
    | is_public        | True                                 |
    | min_disk         | 0                                    |
    | min_ram          | 0                                    |
    | name             | RHEL 6.4                             |
    | owner            | b1414433c021436f97e9e1e4c214a710     |
    | protected        | False                                |
    | size             | 25165824                             |
    | status           | active                               |
    | updated_at       | 2013-01-25T14:45:50                  |
    +------------------+--------------------------------------+
You have successfully uploaded a disk image to Glance. This disk image can now be used as the basis for launching virtual machine instances in your OpenStack environment.