We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install OpenStack on Rocky Linux 8 – Configure Glance (Step 4)

Learn how to – Install OpenStack on Rocky Linux 8 – Configure Glance (Step 4).

Welcome to Part 4 of our article series on the installation and configuration of OpenStack on Rocky Linux 8 servers. In Part 3 we covered the setup of Keystone service. OpenStack Image service (glance) is a service that allows cloud users to upload and discover image data assets meant to be used with other services. Glance has a RESTful API that allows querying of VM image metadata as well as retrieval of the actual image.

In OpenStack, a VM image can be defined as a file that contains a virtual disk with a bootable operating system installed. OpenStack has support for different formats of the VM images. The formats available in OpenStack Platform are many, but the commonly used ones are:

  • ISO – Sector-by-sector copy of the data on a disk, stored in a binary file.
  • RAW – Unstructured disk image format.
  • QCOW2 – Disk format supported by QEMU emulator
  • DOCKER – Indicates that what is stored in the Image service (glance) is a Docker tar archive of the container file system.

These VM images available through Glance can be stored in a variety of backend locations such as:

  • Any filesystem mounted on the glance-api controller node (used in this guide)
  • NFS mount
  • Block Storage (cinder)
  • Object Storage (swift).
  • RADOS Block Device (RBD)

In this article we’ll use local filesystem path to store VM images used for creating virtual machines in an OpenStack environment. For a robust and production usage, consider other solutions that provides for high availability. Our use case is only applicable to Lab environments and demo purposes.

Step 1 – Prepare Storage backend

The configuration process will depend on the storage backend you choose. In our setup we’re using a local disk to store VM images. If your deployment is on a single instance then this can just be a mount point on the host system.

On the host machine we shall create a Logical Volume. But first I’ll check the volume groups available on the system.

$ sudo vgs
  VG #PV #LV #SN Attr   VSize   VFree
  rl   1   2   0 wz--n- 446.03g 398.03g

We’re creating a logical volume named glance on rl volume group.

$ sudo lvcreate -n glance -L 30G rl
  Logical volume "glance" created.

$ sudo lvs
  LV     VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  glance rl -wi-a----- 30.00g
  root   rl -wi-ao---- 40.00g
  swap   rl -wi-ao----  8.00g

Create a filesystem on the logical volume. The type we chose here is xfs.

$ sudo mkfs -t xfs /dev/rl/glance
meta-data=/dev/rl/glance         isize=512    agcount=4, agsize=1966080 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=3840, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
Discarding blocks...Done.

Configure mount point for the logical volume filesystem.

$ sudo vim /etc/fstab
# Mount glance LV
/dev/rl/glance  /var/lib/glance/images xfs defaults 0 0

Next create path on the host system which will hold VM images. The default path on glance service host is /var/lib/glance/images.

sudo mkdir -p /var/lib/glance/images

The test is important to validate the system will mount if a system is rebooted.

sudo mount /var/lib/glance/images

Check mounted filesystems using df command.

$ df -hT /var/lib/glance/images
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/rl-glance xfs    30G  247M   30G   1% /var/lib/glance/images

Step 2: Create service credentials and API endpoints

Before we can install and configure Glance Image service, we must create a database, service credentials, and API endpoints.

Let’s create glance user. We’ll use the password OpenStackSRVPassw0rd for authentication. You can change the password to one that suits you.

$ openstack user create --domain default --project service --password OpenStackSRVPassw0rd glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| default_project_id  | 07b09cf0cddc4e0b9d29db4cf8f72a58 |
| domain_id           | default                          |
| enabled             | True                             |
| id                  | b47f95a77c9e42c8b7ebe3697a523ab4 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

Add the admin role to the glance user and service project:

openstack role add --project service --user glance admin

Next create the glance service entity:

$ openstack service create --name glance --description "OpenStack Image service" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image service          |
| enabled     | True                             |
| id          | 67b0435407864ea9a8d6f64c3db861a6 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

Create the Image service API endpoints:

Export Controller Server IP address as variable.

export controller=172.20.30.3

Creating public API endpoint.

$ openstack endpoint create --region RegionOne image public http://$controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 94181f81fffa47c9a5905197a6d1c0c2 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 67b0435407864ea9a8d6f64c3db861a6 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://172.20.30.3:9292          |
+--------------+----------------------------------+

Creating internal API endpoint.

$ openstack endpoint create --region RegionOne image internal http://$controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 1963c784238849058a4fc9df2c3dd8e8 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 67b0435407864ea9a8d6f64c3db861a6 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://172.20.30.3:9292          |
+--------------+----------------------------------+

Creating admin API endpoint.

$ openstack endpoint create --region RegionOne image admin http://$controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | f4641c88f6aa406bb15bd746cade6cea |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 67b0435407864ea9a8d6f64c3db861a6 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://172.20.30.3:9292          |
+--------------+----------------------------------+

Step 3: Create database for glance

Access the database server as the root user:

mysql -u root -p

Create the glance database:

CREATE DATABASE glance;

Grant proper access to the glance database:

GRANT ALL PRIVILEGES ON glance.* TO glance@'localhost' IDENTIFIED BY 'OpenStackSRVDBPassw0rd'; 
GRANT ALL PRIVILEGES ON glance.* TO glance@'%' IDENTIFIED BY 'OpenStackSRVDBPassw0rd'; 
FLUSH PRIVILEGES;
QUIT

You can replace OpenStackSRVDBPassw0rd with a suitable password.

Step 4: Install and configure glance components

Run the following commands to install the packages:

sudo dnf -y install openstack-glance

Backup default glance API configuration file:

sudo mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.org

Export variables that are used in the configuration of Glance service:

DBPassword=OpenStackSRVDBPassw0rd
DBHost=127.0.0.1
MemcachedHost=127.0.0.1
Controller=172.20.30.3
GlancePassword=OpenStackSRVPassw0rd

We shall update the /etc/glance/glance-api.conf configuration file using contents below:

sudo tee /etc/glance/glance-api.conf<<EOF
[DEFAULT]
bind_host = 0.0.0.0

# Glance storage
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

# Database backend info
[database]
connection = mysql+pymysql://glance:$DBPassword@$DBHost/glance

# Keystone auth information
[keystone_authtoken]
www_authenticate_uri = https://$Controller:5000
auth_url = https://$Controller:5000
memcached_servers = $MemcachedHost:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = $GlancePassword
# if using self-signed certs on httpd for Keystone, turn to [true]
insecure = true

[paste_deploy]
flavor = keystone
EOF

You can edit the file to update parameters before starting the service.

sudo vim /etc/glance/glance-api.conf

Update file permissions

sudo chmod 640 /etc/glance/glance-api.conf
sudo chown root:glance /etc/glance/glance-api.conf

Refer to glance configurations documentation to learn how use other storage backends supported.

Populate the Image service database:

$ sudo su -s /bin/bash glance -c "glance-manage db_sync"
2022-10-20 03:19:40.741 14651 INFO alembic.runtime.migration [-] Context impl MySQLImpl.
2022-10-20 03:19:40.741 14651 INFO alembic.runtime.migration [-] Will assume non-transactional DDL.
2022-10-20 03:19:40.747 14651 INFO alembic.runtime.migration [-] Context impl MySQLImpl.
2022-10-20 03:19:40.747 14651 INFO alembic.runtime.migration [-] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> liberty, liberty initial
INFO  [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of 'images' table
INFO  [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
INFO  [alembic.runtime.migration] Running upgrade ocata_expand01 -> pike_expand01, empty expand for symmetry with pike_contract01
INFO  [alembic.runtime.migration] Running upgrade pike_expand01 -> queens_expand01
INFO  [alembic.runtime.migration] Running upgrade queens_expand01 -> rocky_expand01, add os_hidden column to images table
INFO  [alembic.runtime.migration] Running upgrade rocky_expand01 -> rocky_expand02, add os_hash_algo and os_hash_value columns to images table
INFO  [alembic.runtime.migration] Running upgrade rocky_expand02 -> train_expand01, empty expand for symmetry with train_contract01
INFO  [alembic.runtime.migration] Running upgrade train_expand01 -> ussuri_expand01, empty expand for symmetry with ussuri_expand01
INFO  [alembic.runtime.migration] Running upgrade ussuri_expand01 -> wallaby_expand01, add image_id, request_id, user columns to tasks table"
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: wallaby_expand01, current revision(s): wallaby_expand01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database migration is up to date. No migration needed.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_contract01, remove is_public from images
INFO  [alembic.runtime.migration] Running upgrade ocata_contract01 -> pike_contract01, drop glare artifacts tables
INFO  [alembic.runtime.migration] Running upgrade pike_contract01 -> queens_contract01
INFO  [alembic.runtime.migration] Running upgrade queens_contract01 -> rocky_contract01
INFO  [alembic.runtime.migration] Running upgrade rocky_contract01 -> rocky_contract02
INFO  [alembic.runtime.migration] Running upgrade rocky_contract02 -> train_contract01
INFO  [alembic.runtime.migration] Running upgrade train_contract01 -> ussuri_contract01
INFO  [alembic.runtime.migration] Running upgrade ussuri_contract01 -> wallaby_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: wallaby_contract01, current revision(s): wallaby_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.

Step 5: Finalize and verify glance operation

Start image service and configure to start when the system boots:

sudo systemctl enable --now openstack-glance-api

If firewalld service is running open glance port in

sudo firewall-cmd --add-port=9292/tcp --permanent
sudo firewall-cmd --reload

Test image service

We’ll verify operation of the Image service using CirrOS, a small Linux image that helps you test your OpenStack deployment.

Create images directory

mkdir ~/images && cd ~/images

We can download Cirros cloud image.

sudo yum -y install curl wget
VERSION=$(curl -s http://download.cirros-cloud.net/version/released)
wget http://download.cirros-cloud.net/$VERSION/cirros-$VERSION-x86_64-disk.img

Set correct permissions on images directory.

sudo chown -R  glance:nobody /var/lib/glance/images/
sudo systemctl restart openstack-glance-api.service

Upload Cirros image to Glance using the QCOW2 disk format, bare container format, and public visibility so all projects can access it:

openstack image create --disk-format qcow2 
  --container-format bare --public 
  --file ./cirros-$VERSION-x86_64-disk.img "Cirros"

Confirm image uploaded

$ openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 71620d2c-f4cb-4844-abe3-580067efbc1d | Cirros | active |
+--------------------------------------+--------+--------+

Conclusion

The OpenStack Image service is central to Infrastructure-as-a-Service (IaaS). Glance accepts API requests for server or disk images, and metadata definitions from end users, or Compute component of OpenStack. Glance supports various repository types, including OpenStack Object Storage (Swift), Cinder, NFS, and Ceph RBD. We hope this article was helpful to you and thank you for visiting our website.

5
221.866,70