OpenStack Nova Placement API 统一资源管理接口的未来
2018-07-28 19:16 云物互联 阅读(849) 评论(0) 编辑 收藏 举报目录
Placement API
nova-placement-api,Nova provides a nova-placement-api WSGI script for running the service with Apache, nginx or other WSGI-capable web servers.
Placement API 在 Newton 版本中被引入 Nova,主要用于跟踪记录 Resource Provider 的 Inventory 和 Usage,并使用不同的 Resource Classes 来标记资源类型。例如:一个 resource provider 可以是一个 compute node,一个 shared storage pool,或者是一个 IP allocation pool。Placement API 是一个独立的 REST API 和 DB Models,所以拥有着属于自己的 Endpoint 和 DB tables。
Endpoint URL:
[root@control01 ~]# openstack catalog list
...
| placement | placement | RegionOne |
| | | internal: http://172.18.22.215:8780 |
| | | RegionOne |
| | | public: http://172.18.22.215:8780 |
| | | RegionOne |
| | | admin: http://172.18.22.215:8780
...
DB tables:
MariaDB [(none)]> use nova_api;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [nova_api]> show tables;
+------------------------------+
| Tables_in_nova_api |
+------------------------------+
| aggregate_hosts |
| aggregate_metadata |
| aggregates |
| allocations |
| build_requests |
| cell_mappings |
| consumers |
| flavor_extra_specs |
| flavor_projects |
| flavors |
| host_mappings |
| instance_group_member |
| instance_group_policy |
| instance_groups |
| instance_mappings |
| inventories |
| key_pairs |
| migrate_version |
| placement_aggregates |
| project_user_quotas |
| projects |
| quota_classes |
| quota_usages |
| quotas |
| request_specs |
| reservations |
| resource_classes |
| resource_provider_aggregates |
| resource_provider_traits |
| resource_providers |
| traits |
| users |
+------------------------------+
为何称之为 “未来”
以往 Nova 的资源管理全由 nova-compute service 完成,资源使用情况的统计也只是简单的将所有 compute node 的资源相加得出。但在整个 OpenStack 资源体系中不仅只有 compute node 提供的计算资源(CPU/RAM),还可能存在各类外部存储和外部网络资源,例如:Ceph、NFS 提供的存储服务,SDN 提供的网络服务,这些资源由外部系统提供。可见,当 resources provider 变得多样时,自然会需求一种简单且统一的管理方法,让管理员得以清晰、便捷的掌握资源系统中含有的资源类型及其使用情况,这就是 Placement API。
现阶段(Queue),Placement API 更多的作用在「资源记录与调度」层面,例如:Launch Instance,那么 instance 就是一个消费者,消费了:
- compute node resource provider 的 CPU/RAM
- External shared storage pool resource provider 的 Disk
- External IP pool allocation resource provider 的 IP Addr
在 Ocata 版本,用户还可以自主选择是否启用 Placement API 来辅助 nova-scheduler service 进行 compute node 调度,并以此替代 RAMFilter、CoreFilter 和 DiskFilter。但在 Pike 版本,这种选择的机制被删除了,用户必须启用 Placement API 服务,否则 nova-compute service 无法正常运作。笔者认为,Nova 社区甚至会更倾向于在未来使用 Placement API 对 HostAggregate、Hypervisor 等资源对象进行统一的管理。
操作对象基本概念
Resource Class:资源种类,资源的类型被定义为 classes,Placement API 默认实现了下列 3 种标准 resource classes,也提供了 custom resource classes 的接口。
- DISK_GB
- MEMORY_MB
- VCPU
Resource Provider:资源提供者,实际提供资源的对象,例如:compute node、storage pool
Inventory:资源清单,资源提供者所拥有的资源清单,例如:compute node 拥有的 vCPU、Disk、RAM 等 inventories。
Provider Aggregate:资源聚合,类似 HostAggregate 的概念
Traits:资源特征,不同资源提供者可能会具有不同的资源特征。Traits 作为资源提供者特征的描述,它不能够被消费,但在某些 Workflow 或者会需要这些信息。例如:标识可用的 Disk 是一个 SSD,可以帮助 Scheduler 更好的匹配 instance boot 请求。
Resource Allocations:资源分配状况,包含了 Resource Class、Resource Provider 以及 Consumer 的映射关系。记录消费者使用了多少该类型的资源数量。
在 nova_api database 中也实现了相应的数据模型:
resource_providers
table:存放资源提供者inventories
table:存在资源提供者的资源清单resource_classes
table:存在资源种类resource_provider_aggregates
table:存放资源聚合,实际上是资源提供者和主机聚合的映射关系traits
table:存放自定义的特征描述类型resource_provider_traits
table:存在资源提供者和特征描述的对应关系allocations table
:存放消费者使用了哪一个资源提供者的哪几种资源种类及容量
数据库操作样例
- Resource Provider 的资源清单记录
MariaDB [nova_api]> desc inventories;
+----------------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+----------+------+-----+---------+----------------+
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
| resource_provider_id | int(11) | NO | MUL | NULL | |
| resource_class_id | int(11) | NO | MUL | NULL | |
| total | int(11) | NO | | NULL | | 总大小
| reserved | int(11) | NO | | NULL | | 保留大小
| min_unit | int(11) | NO | | NULL | | 最小分配单位
| max_unit | int(11) | NO | | NULL | | 最大分配单位
| step_size | int(11) | NO | | NULL | | 步长
| allocation_ratio | float | NO | | NULL | | 超分比
+----------------------+----------+------+-----+---------+----------------+
- 每个 compute node 都会自动生成 3 条 inventories 记录 0,1,2 分别对应 3 种默认的资源种类 CPU(s)、RAM(MB) 和 DISK(GB)
MariaDB [nova_api]> select * from resource_providers;
+---------------------+---------------------+-----+--------------------------------------+------------------------------------------------------+------------+----------+
| created_at | updated_at | id | uuid | name | generation | can_host |
+---------------------+---------------------+-----+--------------------------------------+------------------------------------------------------+------------+----------+
| 2018-05-03 09:07:01 | 2018-07-02 07:03:57 | 1 | e367ded8-9501-42b1-a18d-e7f3bab233c6 | domain-c69.22bebe01-eb68-4a5c-839d-11398df43232 | 252 | NULL |
MariaDB [nova_api]> select * from inventories;
+---------------------+---------------------+----+----------------------+-------------------+--------+----------+----------+----------+-----------+------------------+
| created_at | updated_at | id | resource_provider_id | resource_class_id | total | reserved | min_unit | max_unit | step_size | allocation_ratio |
+---------------------+---------------------+----+----------------------+-------------------+--------+----------+----------+----------+-----------+------------------+
| 2018-05-03 09:07:07 | 2018-07-02 07:03:57 | 1 | 1 | 0 | 42 | 0 | 1 | 42 | 1 | 2 |
| 2018-05-03 09:07:07 | 2018-07-02 07:03:57 | 2 | 1 | 1 | 407562 | 2048 | 1 | 407562 | 1 | 1 |
| 2018-05-03 09:07:07 | 2018-07-02 07:03:57 | 3 | 1 | 2 | 736 | 2 | 1 | 736 | 1 | 1 |
- 存放消费者使用了哪一个资源提供者的哪几种资源种类及容量
# e.g. 消费者(虚拟机 648bda64-1d7a-44d2-ba38-20c84959dabe)使用了资源提供者 97 的 1CPU/256M RAM/1G DISK 资源
MariaDB [nova_api]> select * from allocations;
+---------------------+------------+-----+----------------------+--------------------------------------+-------------------+------+
| created_at | updated_at | id | resource_provider_id | consumer_id | resource_class_id | used |
+---------------------+------------+-----+----------------------+--------------------------------------+-------------------+------+
| 2018-05-23 10:40:49 | NULL | 97 | 97 | 648bda64-1d7a-44d2-ba38-20c84959dabe | 0 | 1 |
| 2018-05-23 10:40:49 | NULL | 98 | 97 | 648bda64-1d7a-44d2-ba38-20c84959dabe | 1 | 256 |
| 2018-05-23 10:40:49 | NULL | 99 | 97 | 648bda64-1d7a-44d2-ba38-20c84959dabe | 2 | 1 |
- 存放为消费者分配了多少该类型的资源数量
MariaDB [nova_api]> select * from allocations;
+---------------------+------------+----+----------------------+--------------------------------------+-------------------+------+
| created_at | updated_at | id | resource_provider_id | consumer_id | resource_class_id | used |
+---------------------+------------+----+----------------------+--------------------------------------+-------------------+------+
| 2018-08-01 10:52:15 | NULL | 7 | 1 | f8d55035-389c-47b8-beea-02f00f25f5d9 | 0 | 1 |
| 2018-08-01 10:52:15 | NULL | 8 | 1 | f8d55035-389c-47b8-beea-02f00f25f5d9 | 1 | 512 |
| 2018-08-01 10:52:15 | NULL | 9 | 1 | f8d55035-389c-47b8-beea-02f00f25f5d9 | 2 | 1 |
+---------------------+------------+----+----------------------+--------------------------------------+-------------------+------+
# consumer_id 消费者
# resource_class_id 资源类型
# resource_provider_id 资源提供者
# used 分配的数量
# 上述记录表示为虚拟机分配了 vCPU 1颗,RAM 512MB,Disk 1GB
Placement API 在创建虚拟机时的调度过程
注:图源至互联网
当新建一台 instance 时,nova-api 接收用户请求,转发到 nova-scheduler,nova-scheduler 首先通过 Placement API 来确定 Allocation Candidates 候选资源集合(一般返回的是 Hypervisor 列表)。Allocation Candidates 是可能分配资源的 resource provider 的集合,这些 resource provider 可以满足特定的资源请求。
Placement REST API 摘要
Resource Provider:
/resource_providers
/resource\_providers?member\_of=in:{agg1\_uuid},{agg2\_uuid},{agg3\_uuid}
/resource_providers?resources=\$RESOURCE\_CLASS\_NAME:\$AMOUNT,\$RESOURCE\_CLASS\_NAME:\$AMOUNT
/resource_providers/inventories
/resource_providers/{uuid}/inventories
/resource_providers/usages
/resource_providers/{uuid}/traits
Resource Classes:
GET /resource_classes
POST /resource_classes
PUT /resource_classes/{name}
DELETE /resource_classes/{name}
GET /resource_classes/{name}
Resource Traits:
GET /traits
GET /traits/{name}
PUT /traits/{name}
DELETE /traits/{name}
Placement Client
OS Client Placement Plugin Usage:Placement Plugin 是 openstackclient 的插件模块,让 openstack 指令扩展 resource [provider|class]
子命令。
安装:
pip install python-openstackclient
pip install osc-placement
测试:
root@devstack:~# openstack resource help
Did you mean one of these?
resource class create
resource class delete
resource class list
resource class show
resource provider aggregate list
resource provider aggregate set
resource provider allocation delete
resource provider allocation set
resource provider allocation show
resource provider create
resource provider delete
resource provider inventory class set
resource provider inventory delete
resource provider inventory list
resource provider inventory set
resource provider inventory show
resource provider list
resource provider set
resource provider show
resource provider usage show
recordset create
recordset delete
recordset list
recordset set
recordset show
service create
service delete
service list
service show
使用举例:
(plm_dev) [root@localhost ~]# openstack resource provider list
+--------------------------------------+-----------+------------+
| uuid | name | generation |
+--------------------------------------+-----------+------------+
| 6d89387f-bc6e-44ca-93ce-fb5cafb73985 | localhost | 2 |
+--------------------------------------+-----------+------------+
(plm_dev) [root@localhost ~]# openstack resource provider inventory list 6d89387f-bc6e-44ca-93ce-fb5cafb73985
+----------------+------------------+----------+----------+-----------+----------+-------+
| resource_class | allocation_ratio | max_unit | reserved | step_size | min_unit | total |
+----------------+------------------+----------+----------+-----------+----------+-------+
| VCPU | 16.0 | 4 | 0 | 1 | 1 | 4 |
| MEMORY_MB | 1.5 | 16118 | 512 | 1 | 1 | 16118 |
| DISK_GB | 1.0 | 49 | 0 | 1 | 1 | 49 |
+----------------+------------------+----------+----------+-----------+----------+-------+
(plm_dev) [root@localhost ~]# openstack resource provider usage show 6d89387f-bc6e-44ca-93ce-fb5cafb73985
+----------------+-------+
| resource_class | usage |
+----------------+-------+
| VCPU | 0 |
| MEMORY_MB | 0 |
| DISK_GB | 0 |
+----------------+-------+