Glance in OpenStack

MohammadReza saberi
5 min readNov 29, 2020

Glance has a RESTful API that allows querying of VM image metadata as well as retrieval of the actual image.

GLANCE

VM images made available through Glance can be stored in a variety of locations from simple filesystems to object-storage systems like the OpenStack Swift project , ceph , Filesystem , sheepdog and etc.

What is the difference between a virtual machine and a cloud in images?

Glance hosts a metadefs catalog. In cloud infrastructure, all metadata is loaded into the image when booted.

glance

Images and instances

To launch an instance, select an image, flavor, and any optional attributes. The selected flavor provides a root volume, labeled vda in this diagram, and additional ephemeral storage, labeled vdb. In this example, the cinder-volume store is mapped to the third virtual disk on this instance, vdc.

Openstack Glance Image Cache

By default,image caching is disabled.The Glance API server may be configured to have an optional local image cache. A local image cache stores a copy of image files., essentially enabling multiple API servers to serve the same image file, resulting in an increase in scalability due to an increase number of endpoints serving an image file.Image cache depends on what backend do you use.for example ceph and swift support this feature.

Lets implementing Glance module

Source the admin credentials to gain access to admin-only CLI commands:

# source keystone_admin

Always before implementing any module, we must first introduce it to the keystone.

Create glance user:

# openstack user create — domain default — project PROJECTNAME — password-prompt glance

assign admin role to glance user.This command provides no output.

# openstack role add — project PROJECTNAME — user glance admin

to check tole assignment list:

# openstack role assignment list — names

to create glance service entity:

# openstack service create — name glance — description “OpenStack Image” image

to check service list:

# openstack service list

Create the Image service API endpoints:

# openstack endpoint create — region Tehran image admin http://controller:9292
# openstack endpoint create — region Tehran image public http://controller:9292
# openstack endpoint create — region Tehran image internal http://controller:9292

Create database for glance:

# mysql -u root -p

MariaDB [(none)]> CREATE DATABASE glance;

Grant proper access to the glance database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'GLANCE_DBPASS';
  • Replace GLANCE_DBPASS with a suitable password.
  • Exit the database access client.

Install and configure components

# yum — enablerepo=centos-openstack-train -y install openstack-glance

You can see all the section of glance config file.

# grep -ve “^#” -ve “^$” /etc/glance/glance-api.conf

Edit the /etc/glance/glance-api.conf file and complete the following actions:

, configure database access:

[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
  • Replace GLANCE_DBPASS with the password you chose for the Image service database.

In the [DEFAULT] section.listen to all ip.

bind_host = 0.0.0.0

In the [keystone_authtoken] and [paste_deploy] sections, configure Identity service access:

[keystone_authtoken]
# ...
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS

[paste_deploy]
# ...
flavor = keystone
config_file = /etc/glance/glance-api-paste.ini

# cp /usr/share/glance/glance-api-dist-paste.ini /etc/glance/glance-api-dist-paste.ini

you can use this template ([keystone_authtoken])for all modules which want to authenticate by keystone.

uri is for verify token.

url is for verify password.

In the [glance_store] section, configure the local file system store and location of image files:

[glance_store]
# ...
stores = file
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

Populate the Image service database:

# sudo -u glance glance-manage db_sync

Start the Image services and configure them to start when the system boots:

# systemctl start openstack-glance-api.service

# systemctl enable openstack-glance-api.service

check the service status

# ss -tulpen | grep 9292

Get images

The simplest way to obtain a virtual machine image that works with OpenStack is to download one that someone else has already created.

# openstack image create DOWNLOADED_DISK_IMAGE— public \
— disk-format qcow2 — container-format bare \
— file DOWNLOADED_DISK_IMAGE.qcow2

CirrOS is a minimal Linux distribution that was designed for use as a test image on clouds such as OpenStack Compute.

cirros

If your deployment uses QEMU or KVM, we recommend using the images in qcow2 format

# openstack image list

# openstack image show IMAGE_ID

you can find your image in this path:

/var/lib/glance/images

you can assign some property to you image such as min_disk, min_ram ,…

# openstack image set — min-disk <disk-gb> IMAGE_ID

# openstack image set — min-ram <ram-mb> IMAGE_ID

protected Field Prevent image from being deleted. default value is False.

# openstack image set — protected

Useful image properties

You can set image properties that can be consumed by other services to affect the behavior of those other services. read more

# openstack image set — property hw_scsi_model=virtio-scsi IMAGE_ID

you can set os type for your image:

# openstack image set — property os_type=linux IMAGE_ID

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

The more customized your images, the better the performance.

congratulation ! glance is ready.

next :

  • we will learn about nova

If you have any questions/comments please comment below so everyone can benefit from the discussion.

If you enjoyed this article, please click the 👏 button and share to help others find it! Feel free to leave a comment below.

--

--