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
- Ensure that you have set the environment variables used for authenticating with Keystone by loading them from the
keystonercfile associated with your user. Note that an administrative account is not required.$source~/keystonerc_user - Use the
glance image-createcommand to import your disk image:$glance image-create --name "NAME" \--is-public IS_PUBLIC \--disk-format DISK_FORMAT \--container-format CONTAINER_FORMAT \--file IMAGEReplace the command line arguments toglance image-createwith 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
trueorfalse. Setting this value totruemeans 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, andami.If the format of the virtual machine disk image is unknown then use theqemu-img infocommand to try and identify it.Example 9.2. Using
qemu-img infoIn this example theqemu-img infois used to determine the format of a disk image stored in the file./RHEL64.img.$image: ./RHEL64.img file format: qcow2 virtual size: 5.0G (5368709120 bytes) disk size: 136K cluster_size: 65536qemu-img info ./RHEL64.img - Replace CONTAINER_FORMAT with the container format of the image. The container format is
bareunless the image is packaged in a file format such asovforamithat includes additional metadata related to the image. - Replace IMAGE with the local path to the image file to upload.
Refer to the output of theglance help image-createcommand for more information about supported arguments toglance image-create.Note
If the image being uploaded is not locally accessible but is available using a remote URL then provide it using the--locationparameter instead of using the--fileparameter.Note however that unless you also specify the--copy-fromargument 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 theqcow2format image in the file namedrhel-64.qcow2is uploaded to Glance. It is created in Glance as a publicly accessible image namedRHEL 6.4.$glance image-create --name "RHEL 6.4" --is-public true --disk-format qcow2 \--container-format bare \+------------------+--------------------------------------+ | 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 | +------------------+--------------------------------------+--file rhel-64.qcow2 - Use the
glance image-listcommand 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 theglance image-showcommand 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.