Glance是一项映像服务,可让您发现,提供,注册甚至删除磁盘和/或服务器映像。 它是在OpenStack和TripleO (代表“ OpenStack-On-OpenStack”)上管理映像的基本部分。
在本文中,我将解释如何将图像上传到Glance。 将映像上传到服务后,该映像可用于私有云中的实例。 此外,当您部署Overcloud时,它将使映像可用,以便可以使用它们来部署裸机节点。
在Undercloud中,执行以下命令:
$ openstack overcloud image upload --image-path / home / stack / images /
这会将以下Overcloud图像上传到Glance:
- 满云
- overcloud-full-initrd
- overcloud-full-vmlinuz
几秒钟后,图像将成功上传。 通过运行以下命令检查结果:
( undercloud
)
[ stack
@ undercloud ~
] $ openstack image list
+--------------------------------------+------------------------+--------+
| ID
| Name
| Status
|
+--------------------------------------+------------------------+--------+
| 09ca88ea-
2771 -459d-94a2-9f87c9c393f0
| overcloud-full
| active
|
| 806b6c35-2dd5-478d-a384-217173a6e032
| overcloud-full-initrd
| active
|
| b2c96922-161a-
4171 -829f-be73482549d5
| overcloud-full-vmlinuz
| active
|
+--------------------------------------+------------------------+--------+
这是部署Overcloud的过程中必不可少的简单步骤,它会在几秒钟内完成,这使您很难看清底层。 但是,如果您想知道发生了什么呢?
要记住的一件事:Glance使用通过REST API进行的客户端-服务器通信来工作。 因此,通过使用tcpdump接收一些TCP数据包,您可以看到发生了什么。
另一件重要的事情是:有一个数据库(总是有一个数据库,对吧?),它在所有OpenStack平台组件之间共享,并且包含Glance(和其他组件)需要操作的所有信息。 (在我的情况下,MariaDB是后端。)我不介绍如何访问SQL数据库,因为我不建议您玩弄它,但是我将展示在上传过程中数据库的外观。 (这是一个完全用于测试的OpenStack安装,因此在此示例中无需使用数据库。)
数据库
此示例练习的基本流程是:
已创建图片->已排队图片->已保存图片->已激活图片
您需要获得许可才能通过此流程,因此,首先,您必须请求OpenStack的身份服务Keystone进行授权。 我的Keystone目录条目如下所示; 当我在Undercloud时,我将访问公共端点:
| keystone
| identity
| regionOne
|
|
|
| public: https:
// 172.16.0.20:
13000
|
|
|
| regionOne
|
|
|
| internal: http:
// 172.16.0.19:
5000
|
|
|
| regionOne
|
|
|
| admin: http:
// 172.16.0.19:
35357
|
对于Glance:
| glance
| image
| regionOne
|
|
|
| public: https:
// 172.16.0.20:
13292
|
|
|
| regionOne
|
|
|
| internal: http:
// 172.16.0.19:
9292
|
|
|
| regionOne
|
|
|
| admin: http:
// 172.16.0.19:
9292
|
我将在捕获中找到这些端口和TCP端口3306; 后者是这样,我可以捕获SQL数据库的情况。 要捕获数据包,请使用tcpdump命令:
$ tcpdump -nvs0 -i ens3 host 172.16.0.20 and port 13000 or port 3306 or port 13292
在引擎盖下,这看起来像:
认证方式:
初始请求(发现API版本信息):
https://172.16.0.20: 13000 "GET / HTTP/1.1"
响应:
Content
- Length
:
268 Content
- Type
: application
/ json
Date
: Tue
,
18 Feb
2020 04
:
49
:
55 GMT Location
: https
:
//172.16.0.20:13000/v3/ Server: Apache Vary: X-Auth-Token x-openstack-request-id: req-6edc6642-3945-4fd0-a0f7-125744fb23ec
{
"versions"
:
{
"values"
:
[
{
"id"
:
"v3.13"
,
"status"
:
"stable"
,
"updated"
:
"2019-07-19T00:00:00Z"
,
"links"
:
[
{
"rel"
:
"self"
,
"href"
:
"https://172.16.0.20:13000/v3/"
}
]
,
"media-types"
:
[
{
"base"
:
"application/json"
,
"type"
:
"application/vnd.openstack.identity-v3+json"
}
]
}
]
}
}
认证请求
https://172.16.0.20: 13000 "POST /v3/auth/tokens HTTP/1.1"
在此步骤之后,将为管理员用户分配令牌以使用服务。 (出于安全原因,无法显示该令牌。)该令牌告诉其他服务,例如:“我已经使用Keystone登录了正确的凭据;请让我直接进入该服务,不再询问有关我的身份的问题上午。”
此时,命令:
$ openstack overcloud image upload --image-path / home / stack / images /
执行,并且有权将图像上传到Glance服务。
当前状态为:
已创建 图片->已排队图片->已保存图片->已激活图片
该服务检查此图像是否已经存在:
https://172.16.0.20: 13292 "GET /v2/images/overcloud-full-vmlinuz HTTP/1.1"
从客户端的角度来看,请求看起来像:
curl -g -i -X GET -H 'b' Content-Type ': b' application / octet-stream '' -H 'b' X-Auth-Token ': b' gAAAAABeS2zzWzAZBqF-whE7SmJt_Atx7tiLZhcL8mf6wJPrO3RBdv4SdnWImxbeSQSqEQdZJnwBT79SWhrtt7QDn-2o6dsAtpUb1Rb7w6xe7Qg_AHQfD5P1rU7tXXtKu2DyYFhtPg2TRQS5viV128FyItyt49Yn_ho3lWfIXaR3TuZzyIz38NU '' -H 'User-Agent: python-glanceclient' -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'Connection: keep-alive' --cacert / etc / pki / ca-trust / source / anchors / cm-local-ca.pem --cert None --key None https: // 172.16.0.20: 13292 / v2 / images / overcloud-full-vmlinuz
在这里,您可以看到fernet令牌,指示Glance正在讲话的用户代理以及TLS证书; 这就是为什么您在tcpdump中看不到任何内容的原因。
由于图像不存在,因此可以为此请求获取404错误。
接下来,查询当前图像:
https://172.16.0.20: 13292 "GET /v2/images?limit=20 HTTP/1.1" 200 78
并从服务中检索:
HTTP
/
1.1
200 OK
Content
- Length
:
78
Content
- Type
: application
/ json
X
- Openstack
- Request
- Id
: req
- 0f117984
- f427
- 4d35
- bec3
- 956432865dd1
Date
: Tue
,
18 Feb
2020 04
:
49
:
55 GMT
{
"images"
:
[
]
,
"first"
:
"/v2/images?limit=20"
,
"schema"
:
"/v2/schemas/images"
}
是的,它仍然是空的。
同时,对数据库进行了相同的检查,在该数据库中已触发了具有相同结果的巨大查询。 (要同步时间戳,我在连接和查询完成后检查了tcpdump,然后将它们与API调用的时间戳进行了比较。)
为了确定Glance-DB调用的开始位置,我在tcpdump文件中用单词“ glance”进行了全包搜索。 与搜索所有其他数据库调用相比,这节省了大量时间,因此这是检查每个数据库调用的起点。
![在tcpdump中搜索“一览” Searching "glance" inside tcpdump](https://opensource.com/sites/default/files/uploads/glance-db-calls.png)
第一个查询在字段中不返回任何内容,因为该图像仍然不存在:
SELECT images
. created_at
AS images_created_at
, images
. updated_at
AS images_updated_at
, images
. deleted_at
AS images_deleted_at
, images
. deleted
AS images_deleted
, images
. id
AS images_id
, images
. name
AS images_name
, images
. disk_format
AS images_disk_format
, images
. container_format
AS images_container_format
, images
. size
AS images_size
, images
. virtual_size
AS images_virtual_size
, images
. status
AS images_status
, images
. visibility
AS images_visibility
, images
. checksum
AS images_checksum
, images
. os_hash_algo
AS images_os_hash_algo
, images
. os_hash_value
AS images_os_hash_value
, images
. min_disk
AS images_min_disk
, images
. min_ram
AS images_min_ram
, images
. owner
AS images_owner
, images
. protected
AS images_protected
, images
. os_hidden
AS images_os_hidden
, image_properties_1
. created_at
AS image_properties_1_created_at
, image_properties_1
. updated_at
AS image_properties_1_updated_at
, image_properties_1
. deleted_at
AS image_properties_1_deleted_at
, image_properties_1
. deleted
AS image_properties_1_deleted
, image_properties_1
. id
AS image_properties_1_id
, image_properties_1
. image_id
AS image_properties_1_image_id
, image_properties_1
. name
AS image_properties_1_name
, image_properties_1
. value
AS image_properties_1_value
, image_locations_1
. created_at
AS image_locations_1_created_at
, image_locations_1
. updated_at
AS image_locations_1_updated_at
, image_locations_1
. deleted_at
AS image_locations_1_deleted_at
, image_locations_1
. deleted
AS image_locations_1_deleted
, image_locations_1
. id
AS image_locations_1_id
, image_locations_1
. image_id
AS image_locations_1_image_id
, image_locations_1
. value
AS image_locations_1_value
, image_locations_1
. meta_data
AS image_locations_1_meta_data
, image_locations_1
. status
AS image_locations_1_status
FROM images
LEFT
OUTER
JOIN image_properties
AS image_properties_1
ON images
. id
= image_properties_1
. image_id
LEFT
OUTER
JOIN image_locations
AS image_locations_1
ON images
. id
= image_locations_1
. image_id
WHERE images
. id
=
'overcloud-full-vmlinuz'
接下来,图像将开始上载,因此需要进行API调用并写入数据库。
在API方面,可以通过在以下位置咨询服务来检索图像方案:
https://172.16.0.20: 13292 "GET /v2/schemas/image HTTP/1.1"
然后,在某些字段中填充图像信息。 该方案如下所示: