Using image metadata

We can set arbitrary metadata to help describe images and how they are associated to other OpenStack components. This specific data that is set during image creation or updated at a later time can be used to enable specific functionality in other OpenStack services or to simply allow a custom description of the images.

Getting ready

To begin with, ensure you are logged in to our Ubuntu client where we can run the glance tool. This can be installed using the following command:

sudo apt-get update
sudo apt-get install python-glanceclient

Ensure that you have your environment variable set up correctly with our admin user and password, as created in the previous chapter:

export OS_TENANT_NAME=cookbook
export OS_USERNAME=admin
export OS_PASSWORD=openstack
export OS_AUTH_URL=https://192.168.100.200:5000/v2.0/
export OS_NO_CACHE=1
export OS_KEY=/vagrant/cakey.pem
export OS_CACERT=/vagrant/ca.pem

How to do it...

Image metadata can be added, updated, and deleted, as well as used for host scheduling.

Updating image properties

Carry out the following steps to update the metadata on the image:

  1. We first get the image ID for which we want to update metadata. We do this as follows:
    glance image-list 
    
  2. Add metadata to the image and set the image_state and os_distro properties:
    glance image-update db02ab51-f9a1-4e38-8c3d-22b367962154
        --property image_state=available 
        --property os_distro=ubuntu
    
  3. We get the following output:
    Updating image properties

Deleting all image properties

Carry out the following steps to delete image properties:

  1. We first get the image ID for which we want to delete metadata. We do this as follows:
    glance image-list 
    
  2. To remove all the metadata, enter the following command:
    glance image-update db02ab51-f9a1-4e38-8c3d-22b367962154 
    --purge-props
    

Deleting specific image properties

Carry out the following steps to delete image properties:

  1. We first get the image ID for which we want to delete metadata. We do this as follows:
    glance image-list 
    
  2. To remove specific metadata, we need to specify which properties to keep during the update. In this example, we will remove the image_state property and any others that might have been set, but we keep the os_distro property. Note that user-added properties are removed if not specified. The code is as follows:
    glance image-update db02ab51-f9a1-4e38-8c3d-22b367962154 
    --purge-props --property os_distro=ubuntu
    

Using metadata for host scheduling

Metadata can be used to determine the scheduling of hosts. For example, if you have hosts with different hypervisor types, you can specify properties to identify on which hypervisor the image may be deployed. Carry out the following steps to enable scheduling based on image metadata:

  1. We first need to edit the /etc/nova/nova.conf file to update the scheduler property:
    # Scheduler
    scheduler_default_filters=ImagePropertiesFilter

    Tip

    While scheduling is inherently an OpenStack compute function, we are including this section with Glance for completeness.

  2. Restart nova scheduler:
    sudo stop nova-scheduler
    sudo start nova-scheduler
    
  3. Get the image ID for which we want to update metadata:
    glance image-list 
    
  4. Set architecture and hypervisor type properties, both kvm and qemu will have the qemu hypervisor type:
    glance image-update db02ab51-f9a1-4e38-8c3d-22b367962154 
        --property architecture=arm 
        --property hypervisor_type=qemu
    

How it works...

The glance image-update option in the glance command allows us to add, modify, and remove custom image properties. The syntax is as follows:

glance image-create [other options] --property <key=value>
glance image-update IMAGE_ID --property <key=value>

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.29.48