Linux:Powerful Server Administration
上QQ阅读APP看书,第一时间看更新

Adding a cloud image to OpenStack

In the previous recipe, we installed and configured OpenStack. Now, to start using the service, we need to upload virtual machine images. The OpenStack installation uploads a test image named Cirros. This is a small Linux distribution designed to be used as a test image in the cloud. We will upload prebuilt cloud images available from Ubuntu.

Getting ready

Make sure you have installed the OpenStack environment and you can access the OpenStack dashboard with valid credentials. It is not necessary to have an admin account to create and upload images.

Select the cloud image of your choice and get its download URL. Here, we will use the Trusty Ubuntu Server image. The selected image format is QCOW2, though OpenStack support various other image formats. The following is the URL for the selected image:

https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img

How to do it…

The OpenStack dashboard provides a separate section for image management. You can see the images that are already available and add or remove your own images. Follow these steps to create your own image:

  1. Log in to your OpenStack dashboard. On successful login, you should get an Overview page for your account.
  2. Now, from the left-hand side Project menu, under the Compute submenu, click on Images:

    This should show you a list of all publicly available images—something like this:

  3. Click on the Create Image button to add a new image. This should open a popup box with various details. Here, you can choose to add an image URL or enter an image path if you have downloaded the image to your local machine.
  4. Fill in the name and other required details. Under Image Source, select the image location, and in the next box, Image Location, enter the URL for the Ubuntu Cloud image.
  5. Under Format, select the image format of your selected image. In this case, it's QCOW2.
  6. Enter amd64 under Architecture. Make sure you match this with your selected image.
  7. Enter the minimum disk and RAM size. As we have selected an Ubuntu image, the minimum disk size should be 5 GB and minimum RAM 256 MB. These values will affect the selection of instance flavors while creating a new instance.
  8. Finally, click on the Create Image button to save the details and add the image to OpenStack. This will download the image from the source URL and save it in the image repository. The resulting image will be listed under the Project tab, as follows:

    Now, the image is ready can be used to launch new cloud instances.

How it works…

OpenStack is a cloud virtualization platform and needs operating system images to launch virtual machines in the cloud. The Glance OpenStack imaging service provides the image-management service. It supports various types of image, including Qemu format, raw disk files, ISO images, and images from other virtualization platforms, as well as Docker images. Like every other thing in OpenStack, image management works with the help of APIs provided by Glance.

OpenStack, being a cloud platform, is expected to have ready-to-use images that can be used to quickly start a virtual instance. It is possible to upload the operating system installation disk and install the OS to a virtual instance, but that would be a waste of resources. Instead, it is preferable to have prebuilt cloud images. Various popular operating systems provide their respective cloud images, which can be imported to cloud systems. In the previous example, we used the Ubuntu Cloud image for the Ubuntu Trusty release.

We imported the image by specifying its source URI. Local image files can also be uploaded by selecting the image file as an image source. You can also build your own images and upload them to the image store to be used in the cloud. Along with the image source, we need to provide a few more parameters, which include the type of the image being uploaded and the minimum resource requirements of that image. Once the image has been uploaded, it can be used to launch a new instance in the cloud. Also, the image can be marked as public so that it is accessible to all OpenStack users. You will need specific rights for your OpenStack account to create public images.

There's more…

OpenStack images can also be managed from the command line with the client called glance. To access the respective APIs from the command line, you need to authenticate with the Glance server. Use the following steps to use glance from the command line:

  1. First, add authentication parameters to the environment:
    export OS_USERNAME=demo
    export OS_PASSWORD=password
    export OS_AUTH_URL=http://10.196.69.158/identity
    export OS_TENANT_ID=8fe52bb13ca44981aa15d9b62e9133f4
    

    Tip

    DevStack makes things even easier by providing a script, openrc. It's located under the root directory of DevStack and can be used as follows:

    $ source openrc demo # source openrc username
    

    You are then ready, without multiple export commands.

  2. Now, use the following command to obtain the image list for the specified user:
    $ glance image-list
    

You can get a list of available command-line options with glance help.

See also