OpenStack Glance通过add location方式上传镜像到Ceph

前提:

需要将所有控制节点glance中show_multiple_locations设置为true。

/etc/glance/glance-api.conf
show_multiple_locations = true

修改后需要重启glance-api服务

systemctl restart openstack-glance-api
1 创建一个空的镜像记录
glance image-create --visibility public --disk-format raw --container-format bare --name test-image.raw
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | None                                 |
| container_format | bare                                 |
| created_at       | 2019-12-19T11:38:52Z                 |
| disk_format      | raw                                  |
| id               | 1572527c-3282-49cc-a63b-6a67b0898aab |
| locations        | []                                   |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | test-image.raw                       |
| owner            | 11091103fa834c7eb6f8d6db1f065471     |
| protected        | False                                |
| size             | None                                 |
| status           | queued                               |
| tags             | []                                   |
| updated_at       | 2019-12-19T11:38:52Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+
2 确认本地镜像文件为raw
qemu-img info /root/cirros
image: cirros
file format: raw
virtual size: 39M (41126400 bytes)
disk size: 39M
3 将本地镜像文件导入到ceph

这里上传到compute池,名字保存为镜像id

rbd import /root/cirros compute/1572527c-3282-49cc-a63b-6a67b0898aab
rbd snap create compute/1572527c-3282-49cc-a63b-6a67b0898aab@snap
rbd snap protect compute/1572527c-3282-49cc-a63b-6a67b0898aab@snap

确认镜像文件成功上传到ceph的compute池

rbd ls -l compute |grep 1572527c-3282-49cc-a63b-6a67b0898aab
1572527c-3282-49cc-a63b-6a67b0898aab      40162k         
1572527c-3282-49cc-a63b-6a67b0898aab@snap 40162k
4 给空的镜像记录增加location

url格式为rbd://cluster_id/pool_name/image_id/snap
其中cluster_id通过ceph -s查询

ceph -s
    cluster d1c2aad7-beda-41aa-b537-833eed731acb
glance location-add 1572527c-3282-49cc-a63b-6a67b0898aab --url rbd://d1c2aad7-beda-41aa-b537-833eed731acb/compute/1572527c-3282-49cc-a63b-6a67b0898aab/snap 
+------------------+----------------------------------------------------------------------------------+
| Property         | Value                                                                            |
+------------------+----------------------------------------------------------------------------------+
| checksum         | None                                                                             |
| container_format | bare                                                                             |
| created_at       | 2019-12-19T11:38:52Z                                                             |
| direct_url       | rbd://d1c2aad7-beda-41aa-b537-833eed731acb/compute/1572527c-3282-49cc-a63b-      |
|                  | 6a67b0898aab/snap                                                                |
| disk_format      | raw                                                                              |
| file             | /v2/images/1572527c-3282-49cc-a63b-6a67b0898aab/file                             |
| id               | 1572527c-3282-49cc-a63b-6a67b0898aab                                             |
| locations        | [{"url": "rbd://d1c2aad7-beda-41aa-b537-833eed731acb/compute/1572527c-3282-49cc- |
|                  | a63b-6a67b0898aab/snap", "metadata": {}}]                                        |
| min_disk         | 0                                                                                |
| min_ram          | 0                                                                                |
| name             | test-image.raw                                                                   |
| owner            | 11091103fa834c7eb6f8d6db1f065471                                                 |
| protected        | False                                                                            |
| schema           | /v2/schemas/image                                                                |
| size             | 41126400                                                                         |
| status           | active                                                                           |
| tags             | []                                                                               |
| updated_at       | 2019-12-19T11:42:23Z                                                             |
| virtual_size     | None                                                                             |
| visibility       | public                                                                           |
+------------------+----------------------------------------------------------------------------------+

你可能感兴趣的:(openstack,ceph)