1.在创建volume时将所有的日志都实时打开以便记笔记2.在运行完创建volume的过程,停掉xshell,否则由于xshell显示屏有数量限制,新生成的日志会冲掉之前的日志。而且日志本身也有大小限制,时间
太久的日志也会丢失。
描述 | 详细 |
- 客户(可以是 OpenStack最终用户,也可以是其他程序)向 cinder-api发送请求:“帮我创建一个 volume。GUI 上操作的菜单为 Project -> Volumes -> Volumes -> Create Volume
- 设置 volume 的名称,volume type,大小,Availability Zone 等基本信息
- 这里我们没有设置 Volume Source,这样会创建一个空白的 volume。
| |
- 查看 cinder-api 日志仅摘录重要的日志,后同 :
- cinder-api 接收到一个 POST 类型的 REST API,经过对 HTTP body 的分析,该请求是:创建一个 1GB 的 volume。
| | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
INFO cinder.api.openstack.wsgi [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
POST http://192.168.32.73/volume/v3/20c966be6e644bdfa8858d7940d0781f/volumes |
1.WSGI是Web Server Gateway Interface的缩写 当使用RESTful web服务的时候:GET用于从服务器取回数据;POST请求通常用来创建一个实体;PUT请求和POST请求类似,但是一般用来更新一个已有的实体;DELETE方法用来从服务器上删除资源;HEAS请求和GET请求资源类似,但是仅仅返回响应的头部(没有具体的响应体) 2.http://192.168.32.73/volume/v3/20c966be6e644bdfa8858d7940d0781f/volumes可以通过openstack endpoint list查到 | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.api.v3.volumes [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Create volume request body: {u'volume': {u'status': u'creating', u'size': 1, u'backup_id':
None, u'user_id': None, u'name': u'vol-1', u'imageRef': None, u'availability_zone': u'nova',
...
|
| Jun 11 16:51:13 controller devstack@c-api.service[28558]:
INFO cinder.api.v3.volumes [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Create volume of 1 GB |
|
- 紧接着,cinder-api 启动了一个 Flow(工作流)volume_create_api。 Flow 的执行状态依次为 PENDING, RUNNING 和 SUCCESS。volume_create_api 当前的状态由 PENDING 变为 RUNNING。
| | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Flow 'volume_create_api' (3c60509d-1a85-43c9-96fb-be0a949d0eea) transitioned into state
'RUNNING' from state 'PENDING' {{(pid=28564) _flow_receiver
/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:145 | 当执行工作流时,就会调用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_flow_receiver函数 |
- volume_create_api 工作流包含若干 Task,每个 Task 完成特定的任务。 这些任务依次为 ExtractVolumeRequestTask, QuotaReserveTask, EntryCreateTask, QuotaCommitTask, VolumeCastTask,这几个任务在源码中都是类,在源码中的位置是
| /opt/stack/cinder/cinder
/volume/flows/api/create_volume.py
|
| 。 Task 的执行状态也会经历 PENDING, RUNNING 和 SUCCESS 三个阶段
|
|
- ExtractVolumeRequestTask 获取 request 信息Processes an api request values into a validated set of values.(将api请求值处理为经过验证的值集。)
| | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.ExtractVolumeRequestTask;volume:create'
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state 'RUNNING' from state 'PENDING'
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
| 当执行task时,就会调用/usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py文件中的_task_receiver函数 | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.ExtractVolumeRequestTask;volume:create'
(4865720e-3012-4135-8683-e14e5ac151f9) transitioned into state 'SUCCESS' from state 'RUNNING'
with result '{'volume_type_id': u'e3695232-2b2d-4e2d-a184-1bcde93cd8fa', 'backup_id': None,
...
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183 |
|
- QuotaReserveTask 预留配额 [ˈkwoʊtə](N-COUNT) 定量;定额;配额(分配的数额) Reserves a single volume with the given size & the given volume type(用给定大小和给定卷类型预留单个卷)
| | Jun 11 16:51:13 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.QuotaReserveTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
| Jun 11 16:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.quota [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Created reservations ['ca6af98f-f4fc-4798-b457-0c80cd44fb80', ...
{{(pid=28564) reserve /opt/stack/cinder/cinder/quota.py:1029
|
| Jun 11 16:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.QuotaReserveTask;volume:create' ...
transitioned into state 'SUCCESS' from state 'RUNNING' with result
'{'reservations': ['ca6af98f-f4fc-4798-b457-0c80cd44fb80', ...
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183
|
|
- EntryCreateTask 在数据库中创建 volume 条目Creates an entry for the given volume creation in the database
| | Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.EntryCreateTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194 |
| Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.EntryCreateTask;volume:create' ...
transitioned into state 'SUCCESS' from state 'RUNNING' with result ...
|
|
- QuotaCommitTask 确认配额 Commits the reservation
| | Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.QuotaCommitTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
| Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.QuotaCommitTask;volume:create' ...
transitioned into state 'SUCCESS' from state 'RUNNING' with result '{'volume_properties': ...
{{(pid=28564) _task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183 |
|
- 最后 VolumeCastTask 是向 cinder-sheduler 发送消息,开始调度工作 Performs a volume create cast to the scheduler or to the volume manager
| | Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.VolumeCastTask;volume:create' ...
transitioned into state 'RUNNING' from state 'PENDING' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:194
|
| Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Task 'cinder.volume.flows.api.create_volume.VolumeCastTask;volume:create' ...
transitioned into state 'SUCCESS' from state 'RUNNING' with result 'None' {{(pid=28564)
_task_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:183 |
|
- 至此,Flow volume_create_api 已经完成,状态由 RUNNING 变为 SUCCESS,创建volume 请求成功发布cinder-api 已经成功处理了 volume create 请求,将消息发给了 cinder-scheduler
| | Jun 11 11:51:14 controller devstack@c-api.service[28558]:
DEBUG cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Flow 'volume_create_api' (3c60509d-1a85-43c9-96fb-be0a949d0eea)
transitioned into state 'SUCCESS' from state 'RUNNING'
{{(pid=28564) _flow_receiver /usr/local/lib/python2.7/dist-packages/taskflow/listeners/logging.py:145
|
| Jun 11 11:51:14 controller devstack@c-api.service[28558]:
INFO cinder.volume.api [None req-4111af2f-99a8-4166-8647-569b038786d9 admin admin]
Create volume request issued successfully. |
|
- cinder-api 向 RabbitMQ 发送了一条消息:“让cinder-scheduler 创建一个 volume”,消息是由 VolumeCastTask 发出的,因为 VolumeCastTask 没有打印相关日志,我们只能通过源代码查看 /opt/stack/cinder/cinder/volume/flows/api/create_volume.py ,方法为 create_volume。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | class VolumeCastTask(flow_utils.CinderTask):
"""Performs a volume create cast to the scheduler or to the volume manager.
This will signal a transition of the api workflow to another child and/or
related workflow on another component.
Reversion strategy: rollback source volume status and error out newly
created volume.
"""
#...
def _cast_create_volume(self, context, request_spec, filter_properties):
#...
self.scheduler_rpcapi.create_volume(
context,
volume,
snapshot_id=snapshot_id,
image_id=image_id,
request_spec=request_spec,
filter_properties=filter_properties,
backup_id=backup_id)
#... | 如果我们需要将一个函数运行在远程计算机上并且等待从那儿获取结果时,该怎么办呢?这就是另外的故事了。这种模式通常被称为远程过程调用(Remote Procedure Call)或者 RPC,使用 RabbitMQ 来构建一个 RPC 系统 |