官术网_书友最值得收藏!

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

主站蜘蛛池模板: 湄潭县| 凌海市| 信丰县| 江川县| 鹤山市| 博湖县| 夏河县| 富民县| 乐至县| 肇庆市| 满洲里市| 柳林县| 炎陵县| 大田县| 恭城| 翁牛特旗| 湖南省| 南溪县| 阿荣旗| 常山县| 巫山县| 集贤县| 汶上县| 比如县| 黄浦区| 改则县| 洪洞县| 绥中县| 得荣县| 河南省| 金门县| 西宁市| 都兰县| 抚宁县| 墨竹工卡县| 合肥市| 衢州市| 南皮县| 道真| 新和县| 拉孜县|