Add Virtual Machine images in Glance. For example on here, create and add CentOS 7 virtual machine image.

Install KVM HyperVisor, refer to here . It’s unnecessarry to set Bridge networking on the section [2] of the link.

Create CentOS 7 image on Glance Host.

# create a directory for disk image
[root@dlp ~(keystone)]# mkdir -p /var/kvm/images
# create a disk image
[root@dlp ~(keystone)]# qemu-img create -f qcow2 /var/kvm/images/centos7.img 10G
# install
[root@dlp ~(keystone)]# virt-install \ --name centos7 \ --ram 2048 \ --disk path=/var/kvm/images/centos7.img,format=qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant rhel7 \ --graphics none \ --console pty,target_type=serial \ --location 'http://ftp.iij.ad.jp/pub/linux/centos/7/os/x86_64/' \ --extra-args 'console=ttyS0,115200n8 serial'
Starting install...
# installation starts

After installation, change settings in virtual machine like follows and shutdown it. * Delete or comment out the line [HWADDR] and [UUID] in [/etc/sysconfig/network-scripts/ifcfg-eth0] * Set [dhcp] for [BOOTPROTO] in [/etc/sysconfig/network-scripts/ifcfg-eth0] * Install [cloud-init] package and enable [cloud-init] service, and also add a user whose name is [centos]

Add the virtual image to Glance.

[root@dlp ~(keystone)]# openstack image create "CentOS7" --file /var/kvm/images/centos7.img --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------------------------------+
| checksum | adf98f346668ff3b67907a133ed7e5f3 |
| container_format | bare |
| created_at | 2019-10-25T04:44:36Z |
| disk_format | qcow2 |
| file | /v2/images/c742c8ed-9d0f-4555-9844-7f063a0b585f/file |
| id | c742c8ed-9d0f-4555-9844-7f063a0b585f |
| min_disk | 0 |
| min_ram | 0 |
| name | CentOS7 |
| owner | 4f93fd3e6e184c859641b017115016a4 |
| properties | os_hash_algo='sha512', os_hash_value='c163656fec8a6b0fb2f6106856565b2d0115...|
| protected | False |
| schema | /v2/schemas/image |
| size | 1695154176 |
| status | active |
| tags | |
| updated_at | 2019-10-25T04:44:45Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------------------------------+
[root@dlp ~(keystone)]# openstack image list
+--------------------------------------+---------+--------+
| ID | Name | Status |
+--------------------------------------+---------+--------+
| c742c8ed-9d0f-4555-9844-7f063a0b585f | CentOS7 | active |
+--------------------------------------+---------+--------+

By the way, if you got an image from internet, it’s OK to simply add it like follows.

[root@dlp ~(keystone)]# wget cloud-images.ubuntu.com/releases/18.04/release/ubuntu-18.04-server-cloudimg-amd64.img -P /var/kvm/images 

[root@dlp ~(keystone)]# openstack image create "Ubuntu1804" --file /var/kvm/images/ubuntu-18.04-server-cloudimg-amd64.img --disk-format qcow2 --container-format bare --public 
+------------------+----------------------------------------------------------------------------------+
| Field | Value |
+------------------+----------------------------------------------------------------------------------+
| checksum | 8f92c8890165448793cee1f03264165a |
| container_format | bare |
| created_at | 2019-04-11T02:32:59Z |
| disk_format | qcow2 |
| file | /v2/images/21050ab6-dbd7-487f-abf2-cabbab507abe/file |
| id | 21050ab6-dbd7-487f-abf2-cabbab507abe |
| min_disk | 0 |
| min_ram | 0 |
| name | Ubuntu1804 |
| owner | e52584cf60234bc090c7d437b8ca7b62 |
| properties | os_hash_algo='sha512', os_hash_value='3e1ef6f0d9f90a9a2c21e7c2976c1762e9765'...' |
| protected | False |
| schema | /v2/schemas/image |
| size | 343736320 |
| status | active |
| tags | |
| updated_at | 2019-04-11T02:33:02Z |
| virtual_size | None |
| visibility | public |
+------------------+----------------------------------------------------------------------------------+

摘自 OpenStack Train : Add VM Images · Server World,版权归原作者所有,此处仅作个人学习整理。