OpenStack Placement Project

目錄

背景

私有云的用戶,尤爲是傳統 IT 架構轉型的私有云用戶通常會擁有各式各樣的存量資源系統,與這些系統對接會讓 OpenStack 的資源體系變得複雜。html

從用戶的角度出發,或許你會但願python

  • 做爲使用共享存儲解決方案的用戶,我會但願 Nova 和 Horizon 可以正確報告共享存儲磁盤資源的總量和使用量信息。web

  • 做爲高級的 Neutron 用戶,我預期會使用外部的第三方路由網絡功能,但願 Nova 可以掌握和使用特定的網絡端口與特定的子網池相關聯,確保虛擬機可以在該子網池上啓動。數據庫

  • 做爲高級的 Cinder 用戶,我但願當我在 nova boot 命令中指定了 cinder volume-id 後 Nova 可以知道哪一些計算節點與 Request Volume 所在的 Cinder 存儲池相關聯。編程

因此,OpenStack 除了要處理計算節點 CPU,內存,PCI 設備、本地磁盤等內部資源外,還常常須要納管有如 SDS、NFS 提供的存儲服務,SDN 提供的網絡服務等外部資源。json

但在以往,Nova 只能處理由計算節點提供的資源。Nova Resource Tracker 假定全部資源均來自計算節點,所以在週期性上報資源情況時,Resource Tracker 只會單純對計算節點清單進行資源總量和使用量的加和統計。顯然,這沒法知足上述複雜的生產需求,也違背了 OpenStack 一貫賴以自豪的開放性原則。並且隨着 OpenStack 的定義被社區進一步升級爲「一個開源基礎設施集成引擎」,意味 OpenStack 的資源系統將會由更多外部資源類型構成。api

因此,當資源類型和提供者變得多樣時,天然就需求一種高度抽象且簡單統一的管理方法,讓用戶和代碼可以便捷的使用、管理、監控整個 OpenStack 的系統資源,這就是 Placement(佈局)服務器

Placement 簡介

Placement 肩負着這樣的歷史使命,最先在 Newton 版本被引入到 openstack/nova repo,以 API 的形式進行孵化,因此也常常被稱呼爲 Placement API。它參與到 nova-scheduler 選擇目標主機的調度流程中,負責跟蹤記錄 Resource Provider 的 Inventory 和 Usage,並使用不一樣的 Resource Classes 來劃分資源類型,使用不一樣的 Resource Traits 來標記資源特徵。網絡

NOTE:Ocata 版本的 Placement API 是一個可選項,建議用戶啓用並替代 CpuFilter、CoreFilter 和 DiskFilter。Pike 版本則強制要求啓動 Placement API 服務,不然 nova-compute service 沒法正常運行。數據結構

直至成文前段時間(2018/11),Placement API 開始了 openstack/nova repo 剝離流程,從 Placement API 蛻變爲 OpenStack Placement,並計劃在 Stein 版本中成爲獨立項目,指望最終能替代 nova-scheduler service。雖然如今的 OpenStack Placement 還不穩定,但毋容置疑,Placement 就是 OpenStack 雲平臺統一資源管理的將來,是開放集成引擎藍圖的地基。

OpenStack Placement provides an HTTP service for managing, selecting, and claiming providers of classes of inventory representing available resources in a cloud.

Placement 擁有獨立的 REST API。

[root@control01 ~]# openstack catalog show placement
+-----------+------------------------------------------+
| Field     | Value                                    |
+-----------+------------------------------------------+
| endpoints | RegionOne                                |
|           |   public: http://172.18.22.222/placement |
|           |                                          |
| id        | 9b5683b4a5284369bafad76944a0610f         |
| name      | placement                                |
| type      | placement                                |
+-----------+------------------------------------------+

Placement 擁有獨立的數據庫和數據模型。

MariaDB [(none)]> use placement

MariaDB [placement]> show tables;
+------------------------------+
| Tables_in_placement          |
+------------------------------+
| alembic_version              |
| allocations                  |
| consumers                    |
| inventories                  |
| placement_aggregates         |
| projects                     |
| resource_classes             |
| resource_provider_aggregates |
| resource_provider_traits     |
| resource_providers           |
| traits                       |
| users                        |
+------------------------------+

NOTE:本篇主要分析、記錄 1.0 版本的 Placement 實現。

[root@control01 ~]# openstack versions show --service placement
+-------------+--------------+---------+---------+---------------------------------+------------------+------------------+
| Region Name | Service Type | Version | Status  | Endpoint                        | Min Microversion | Max Microversion |
+-------------+--------------+---------+---------+---------------------------------+------------------+------------------+
| RegionOne   | placement    | 1.0     | CURRENT | http://172.18.22.222/placement/ | 1.0              | 1.30             |
+-------------+--------------+---------+---------+---------------------------------+------------------+------------------+

基本概念

Resource Provider:資源提供者,實際提供資源的實體,例如:Compute Node、Storage Pool、IP Pool 等。

Resource Class:資源種類,即資源的類型,Placement 爲 Compute Node 缺省了下列幾種類型,同時支持 Custom Resource Classes。

[root@control01 ~]# export OS_PLACEMENT_API_VERSION=1.17

[root@control01 ~]# openstack resource class list
+----------------------------+
| name                       |
+----------------------------+
| VCPU                       |
| MEMORY_MB                  |
| DISK_GB                    |
| PCI_DEVICE                 |
| SRIOV_NET_VF               |
| NUMA_SOCKET                |
| NUMA_CORE                  |
| NUMA_THREAD                |
| NUMA_MEMORY_MB             |
| IPV4_ADDRESS               |
| VGPU                       |
| VGPU_DISPLAY_HEAD          |
| NET_BW_EGR_KILOBIT_PER_SEC |
| NET_BW_IGR_KILOBIT_PER_SEC |
+----------------------------+

Inventory:資源清單,資源提供者所擁有的資源清單,例如:Compute Node 擁有的 vCPU、Disk、RAM 等 inventories。

Provider Aggregate:資源聚合,相似 HostAggregate 的概念,是一種聚合類型。

Traits:資源特徵,不一樣資源提供者可能會具備不一樣的資源特徵。Traits 做爲資源提供者特徵的描述,它不可以被消費,但在某些 Workflow 或者會很是有用。例如:標識可用的 Disk 具備 SSD 特徵,有助於 Scheduler 靈活匹配 Launch Instance 的請求。

Resource Allocations:資源分配情況,包含了 Resource Class、Resource Provider 以及 Consumer 的映射關係。記錄消費者使用了該類型資源的數量。

數據模型解析

Data Models

  • ResourceProvider:資源提供者
  • Inventory:資源提供者的資源清單
  • ResourceClass:資源種類
  • ResourceProviderAggregate:資源聚合,其實是資源提供者和主機聚合的映射關係
  • Trait:資源特徵描述類型
  • ResourceProviderTrait:資源提供者和特徵描述的對應關係
  • Allocation:分配給消費者的資源情況
  • Consumer:消費者,本質是一串 UUID
  • User:Keystone User

Resource Provider Inventory 的屬性

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 的 1U/256M/1G 的 CPU/RAM/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 |

如何查看消費者分配了的資源情況?e.g. 查看分配給消費者(虛擬機 648bda64-1d7a-44d2-ba38-20c84959dabe)的資源情況。

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 分配的數量

Command Line

Placement CLI 以 OS Client Placement Plugin 的形式提供,是 openstackclient 子命令的擴展。

Installation

pip install python-openstackclient
pip install osc-placement

EXAMPLE

[root@control01 ~]# export OS_PLACEMENT_API_VERSION=1.17

[root@control01 ~]# openstack resource provider list
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+
| uuid                                 | name      | generation | root_provider_uuid                   | parent_provider_uuid |
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+
| 5c5a578f-51b0-481c-b38c-7aaa3394e585 | control01 |         25 | 5c5a578f-51b0-481c-b38c-7aaa3394e585 | None                 |
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+

[root@control01 ~]# openstack resource provider inventory list 5c5a578f-51b0-481c-b38c-7aaa3394e585
+----------------+------------------+----------+----------+-----------+----------+-------+
| resource_class | allocation_ratio | max_unit | reserved | step_size | min_unit | total |
+----------------+------------------+----------+----------+-----------+----------+-------+
| VCPU           |             16.0 |       32 |        0 |         1 |        1 |    32 |
| MEMORY_MB      |              1.5 |    40959 |      512 |         1 |        1 | 40959 |
| DISK_GB        |              1.0 |       49 |        0 |         1 |        1 |    49 |
+----------------+------------------+----------+----------+-----------+----------+-------+

[root@control01 ~]# openstack resource provider usage show 5c5a578f-51b0-481c-b38c-7aaa3394e585
+----------------+-------+
| resource_class | usage |
+----------------+-------+
| VCPU           |     5 |
| MEMORY_MB      |  3648 |
| DISK_GB        |     7 |
+----------------+-------+

[root@control01 ~]# openstack allocation candidate list --resource VCPU=1
+---+------------+--------------------------------------+-------------------------+--------------------------------------------------------------+
| # | allocation | resource provider                    | inventory used/capacity | traits                                                       |
+---+------------+--------------------------------------+-------------------------+--------------------------------------------------------------+
| 1 | VCPU=1     | 5c5a578f-51b0-481c-b38c-7aaa3394e585 | VCPU=5/512              | HW_CPU_X86_SSE2,HW_CPU_X86_SSE,HW_CPU_X86_MMX,HW_CPU_X86_SVM |
+---+------------+--------------------------------------+-------------------------+--------------------------------------------------------------+

更多詳細請瀏覽 Command Line Reference

NOTE:這裏指定 micro-version 爲 1.17,經過環境變量 OS_PLACEMENT_API_VERSION 指定,也能夠經過 request header OpenStack-API-Version: placement 1.17 指定。詳細的版本 ChangeLog 請瀏覽 Placement API

Placement Web Application 的實現與分析

要分析 Placement 的實現,實際是分析 placement-api service 的實現,當前 Placement 只提供單一的 API 服務。placement-api 是一個標準的 Python WSGI 實現,WSGI Script 爲 placement-api,存放在 usr/bin 或 /usr/local/bin 目錄下,WSGI-capable web servers 加載啓動。e.g.

/usr/bin/uwsgi --procname-prefix placement --ini /etc/placement/placement-uwsgi.ini

**WSGI(Web Server Gateway Interface,Web 服務器網關接口)**指代一種編程規範,將 Web 系統抽象爲 Web Server、Middleware 和 Application 三個層次,實現讓不一樣協議之間的實現能夠互相通訊,故稱之爲 「網關」。實現了 WSGI 規範的程序可稱爲 WSGI 組件,常見的 WSGI 組件有 mod_wsgi、uwsgi 等,Python 代碼能夠運行在 Apache、Nginx 等 HTTP Server 上也得益於此。簡而言之,WSGI 定義了 Web Server 如何與 Python Web Application 進行交互的規則。OpenStack 項目常使用 Apache + WSGI 的組合來支撐 REST API 服務。
— — 範桂颶’s 博客

NOTE:若是是 Devstack 部署的環境,會應用 Apache ProxyPass 機制將 http://<ip>/placement 的訪問重定向到 devstack@placement-api service 處理。因此從 catalog 看見的 URL 纔會長成這個樣子。

ProxyPass "/placement" "unix:/var/run/uwsgi/placement-api.socket|uwsgi://uwsgi-uds-placement-api/" retry=0.

固然了,這種方式對於開發調試有着諸多不便,因此做爲開發者能夠直接執行指令 placement-api 來啓動一個用於測試的 API 服務進程。

[root@control01 placement]# placement-api
...
********************************************************************************
STARTING test server placement.wsgi.init_application
Available at http://control01:8000/
DANGER! For testing only, do not use in production
********************************************************************************

回到正題,這裏咱們只關注 Web Application 層面的實現。經過 setup.cfg 咱們能夠找到 placement-api 的程序入口。

wsgi_scripts =
    placement-api = placement.wsgi:init_application

順着入口往下擼,很快就能找到 placement-api 的實現模塊和 Application 類:

# file: /opt/master/placement/placement/handler.py

class PlacementHandler(object):
    """Serve Placement API. Dispatch to handlers defined in ROUTE_DECLARATIONS. """

    def __init__(self, **local_config):
        self._map = make_map(ROUTE_DECLARATIONS)
        self.config = local_config['config']

API 的 URL Routes、HTTP Method 以及 View function 的 Mapping 實現到了 ROUTE_DECLARATIONS 字典類型對象,全部的 API Resources Class 都被封裝在 plcement.handlers 包下,是一個風格很是典型的 REST API 實現。很少贅述。

Placement 在啓動虛擬機時的調度過程

在這裏插入圖片描述

圖1. Launch Instance 流程圖

上圖可見(紅色部分)Placement 主要參與到了 nova-scheduler 選擇主機的過程。以此切入,繼續深刻其中的調用細節。

在這裏插入圖片描述
圖2. nova-scheduler 調度主機 UML 圖

對於上面整個流程,咱們主要關心 nova-scheduler 對 placement-api 的兩次調用。第一次,nova-scheduler 向 placement-api 獲取一組 Allocation Candidates(分配候選人),所謂 Allocation Candidates 就是可以知足資源需求的 Resource Provider。

EXAMPLE

GET /allocation_candidates?resources=VCPU:1,MEMORY_MB:2048,DISK_GB:100

NOTE:獲取 Allocation Candidates 的實現是一系列複雜的數據庫級聯查詢與過濾操做,以 query params 做爲過濾條件。該例子傳遞了 Launch Instance 所需的 vCPU、RAM 和 Disk 資源,除此以外,還能夠提供 required 和 member_of 參數,分別用於指定 Resource Traits 和 Resource Provider Aggregate 特性,使 Allocation Candidates 的獲取方式更加靈活。更多詳情請瀏覽 Allocation candidates

PS:版本較新的 placement-api 還支持 allocation candidate 指令行操做。

[root@control01 ~]# openstack allocation candidate list --resource VCPU=1,MEMORY_MB=2048,DISK_GB=10 --required HW_CPU_X86_SSE2
+---+----------------------------------+--------------------------------------+----------------------------------------------+--------------------------------------------------------------+
| # | allocation                       | resource provider                    | inventory used/capacity                      | traits                                                       |
+---+----------------------------------+--------------------------------------+----------------------------------------------+--------------------------------------------------------------+
| 1 | VCPU=1,MEMORY_MB=2048,DISK_GB=10 | 5c5a578f-51b0-481c-b38c-7aaa3394e585 | VCPU=5/512,MEMORY_MB=3648/60670,DISK_GB=7/49 | HW_CPU_X86_SSE2,HW_CPU_X86_SSE,HW_CPU_X86_MMX,HW_CPU_X86_SVM |
+---+----------------------------------+--------------------------------------+----------------------------------------------+--------------------------------------------------------------+

placement-api 返回給 nova-scheduler 的 JSON object with a list of allocation requests and a JSON object of provider summary objects 數據結構以下,關鍵在於 allocation_requests 和 provider_summaries 兩個字段,它們在後續的 Scheduler Filters 邏輯中也發揮着重要的做用。

{
  "allocation_requests": [
    <ALLOCATION_REQUEST_1>,
    ...
    <ALLOCATION_REQUEST_N>
  ],
  "provider_summaries": {
    <COMPUTE_NODE_UUID_1>: <PROVIDER_SUMMARY_1>,
    ...
    <COMPUTE_NODE_UUID_N>: <PROVIDER_SUMMARY_N>,
  }
}
  • allocation_requests:包含了全部可以知足需求的 resource provider 及其預期分配的資源清單。
"allocation_requests": [
        {
            "allocations": {
                "a99bad54-a275-4c4f-a8a3-ac00d57e5c64": {
                    "resources": {
                        "DISK_GB": 100
                    }
                },
                "35791f28-fb45-4717-9ea9-435b3ef7c3b3": {
                    "resources": {
                        "VCPU": 1,
                        "MEMORY_MB": 1024
                    }
                }
            }
        },
        {
            "allocations": {
                "a99bad54-a275-4c4f-a8a3-ac00d57e5c64": {
                    "resources": {
                        "DISK_GB": 100
                    }
                },
                "915ef8ed-9b91-4e38-8802-2e4224ad54cd": {
                    "resources": {
                        "VCPU": 1,
                        "MEMORY_MB": 1024
                    }
                }
            }
        }
    ],

NOTE:有趣的是,能夠看見提供 VCPU/MEMORY 和 DISK 的 resource provider 並不相同,說明一臺虛擬機的資源並不是只能由一個 ComputeNode 提供,也能夠是 ComputeNode 與外部 Storage Pool 組合提供。

  • provider_summaries:包含了全部知足需求的 resource providers 的各項資源總量和使用量信息。
"provider_summaries": {
        "a99bad54-a275-4c4f-a8a3-ac00d57e5c64": {
            "resources": {
                "DISK_GB": {
                    "used": 0,
                    "capacity": 1900
                }
            },
            "traits": ["MISC_SHARES_VIA_AGGREGATE"],
            "parent_provider_uuid": null,
            "root_provider_uuid": "a99bad54-a275-4c4f-a8a3-ac00d57e5c64"
        },
        "35791f28-fb45-4717-9ea9-435b3ef7c3b3": {
            "resources": {
                "VCPU": {
                    "used": 0,
                    "capacity": 384
                },
                "MEMORY_MB": {
                    "used": 0,
                    "capacity": 196608
                }
            },
            "traits": ["HW_CPU_X86_SSE2", "HW_CPU_X86_AVX2"],
            "parent_provider_uuid": null,
            "root_provider_uuid": "35791f28-fb45-4717-9ea9-435b3ef7c3b3"
        },
        "915ef8ed-9b91-4e38-8802-2e4224ad54cd": {
            "resources": {
                "VCPU": {
                    "used": 0,
                    "capacity": 384
                },
                "MEMORY_MB": {
                    "used": 0,
                    "capacity": 196608
                }
            },
            "traits": ["HW_NIC_SRIOV"],
            "parent_provider_uuid": null,
            "root_provider_uuid": "915ef8ed-9b91-4e38-8802-2e4224ad54cd"
        },
        "f5120cad-67d9-4f20-9210-3092a79a28cf": {
            "resources": {
                "SRIOV_NET_VF": {
                    "used": 0,
                    "capacity": 8
                }
            },
            "traits": [],
            "parent_provider_uuid": "915ef8ed-9b91-4e38-8802-2e4224ad54cd",
            "root_provider_uuid": "915ef8ed-9b91-4e38-8802-2e4224ad54cd"
        }
    }

NOTE:能夠看出 SRIOV_NET_VF 亦被當作爲一種資源類型,由專門的 resource provider 提供。

nova-scheduler 在得到了 Allocation Candidates 以後再進一步經過 Filtered 和 Weighed 機制來最終肯定目標主機。而後再根據 allocation requests 和 provider summaries 的數據來扣除(claim_resources)目標主機對應的 resource provider 的資源使用量,這就是 nova-scheduler 第二次調用 placement-api 所作的事情。回顧一下 allocations tables 的內容:

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

顯然,其中的 Consumer 消費者就是要建立的虛擬機了。

Resource provider aggregates 功能測試

Resource provider aggregates 是一個相似於 Host Aggregate 的功能,獲取 Allocation Candidates 時,支持經過 member_of request query parameter 從特定的 Aggregate 中獲取。Resource provider aggregates 很是適用於擁有不一樣主機聚合( e.g. 高性能主機聚合,大存儲容量主機聚合)類型的生產場景中。

  • Create resource provider aggregates
[root@control01 ~]# openstack aggregate create --zone nova host_aggregate_1
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | nova                       |
| created_at        | 2018-12-08T05:49:55.051678 |
| deleted           | False                      |
| deleted_at        | None                       |
| id                | 1                          |
| name              | host_aggregate_1           |
| updated_at        | None                       |
+-------------------+----------------------------+

[root@control01 ~]# openstack aggregate add host host_aggregate_1 control01
+-------------------+---------------------------------+
| Field             | Value                           |
+-------------------+---------------------------------+
| availability_zone | nova                            |
| created_at        | 2018-12-08T05:49:55.000000      |
| deleted           | False                           |
| deleted_at        | None                            |
| hosts             | [u'control01']                  |
| id                | 1                               |
| metadata          | {u'availability_zone': u'nova'} |
| name              | host_aggregate_1                |
| updated_at        | None                            |
+-------------------+---------------------------------+

[root@control01 ~]# openstack aggregate show host_aggregate_1
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | nova                       |
| created_at        | 2018-12-08T05:49:55.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | [u'control01']             |
| id                | 1                          |
| name              | host_aggregate_1           |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+

[root@control01 ~]# openstack resource provider list
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+
| uuid                                 | name      | generation | root_provider_uuid                   | parent_provider_uuid |
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+
| 5c5a578f-51b0-481c-b38c-7aaa3394e585 | control01 |         26 | 5c5a578f-51b0-481c-b38c-7aaa3394e585 | None                 |
+--------------------------------------+-----------+------------+--------------------------------------+----------------------+

[root@control01 ~]# openstack resource provider aggregate list 5c5a578f-51b0-481c-b38c-7aaa3394e585
+--------------------------------------+
| uuid                                 |
+--------------------------------------+
| 5eea7084-0207-44f0-bbeb-c759e8c766a1 |
+--------------------------------------+
  • List allocation cadidates filter by aggregates
# REQ
curl -i "http://172.18.22.222/placement/allocation_candidates?resources=VCPU:1,MEMORY_MB:512,DISK_GB:5&member_of=5eea7084-0207-44f0-bbeb-c759e8c766a1" \
-X GET \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Project-Id: admin' \
-H 'OpenStack-API-Version: placement 1.21' \
-H 'X-Auth-Token:gAAAAABcC12qN3GdLvjYXSSUODi7Dg9jTHUfcnF7I_ljmcffZjs3ignipGLj6iqDvDJ1gXkzGIDW6rRRNcXary-wPfgsb3nCWRIEiAS8LrReI4SYL1KfQiGW7j92b6zTz7RoSEBXACQ9z7UUVfeJ06n8WqVMBaSob4BeFIuHiVKpYCJNv7LR6cI'

# RESP
{
	"provider_summaries": {
		"5c5a578f-51b0-481c-b38c-7aaa3394e585": {
			"traits": ["HW_CPU_X86_SSE2", "HW_CPU_X86_SSE", "HW_CPU_X86_MMX", "HW_CPU_X86_SVM"],
			"resources": {
				"VCPU": {
					"used": 5,
					"capacity": 512
				},
				"MEMORY_MB": {
					"used": 3648,
					"capacity": 60670
				},
				"DISK_GB": {
					"used": 7,
					"capacity": 49
				}
			}
		}
	},
	"allocation_requests": [{
		"allocations": {
			"5c5a578f-51b0-481c-b38c-7aaa3394e585": {
				"resources": {
					"VCPU": 1,
					"MEMORY_MB": 512,
					"DISK_GB": 5
				}
			}
		}
	}]
}

Resource traits 功能測試

Resource traits 特徵標籤功能,用於標識 Resource Provider 的特徵性質,每一個 Resource Provider 有着其各自的缺省 traits,也支持爲指定的 Resource Provider 自定義 traits。

Resource traits 是很是靈活的一種設計,相似於 「標籤」 的做用,用戶能夠創建起 「標籤雲」 並決定爲某一個 Resource Provider 貼上 「標籤」,是一種資源概括分類需求的輔助工具。

  • List traits
curl -i "http://172.18.22.222/placement/traits" \
-X GET \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Project-Id: admin' \
-H 'OpenStack-API-Version: placement 1.21' \
-H 'X-Auth-Token:gAAAAABcC12qN3GdLvjYXSSUODi7Dg9jTHUfcnF7I_ljmcffZjs3ignipGLj6iqDvDJ1gXkzGIDW6rRRNcXary-wPfgsb3nCWRIEiAS8LrReI4SYL1KfQiGW7j92b6zTz7RoSEBXACQ9z7UUVfeJ06n8WqVMBaSob4BeFIuHiVKpYCJNv7LR6cI'
  • Create custom traits
curl -i "http://172.18.22.222/placement/traits/CUSTOM_FANGUIJU_HOST" \
-X PUT \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Project-Id: admin' \
-H 'OpenStack-API-Version: placement 1.21' \
-H 'X-Auth-Token:gAAAAABcC12qN3GdLvjYXSSUODi7Dg9jTHUfcnF7I_ljmcffZjs3ignipGLj6iqDvDJ1gXkzGIDW6rRRNcXary-wPfgsb3nCWRIEiAS8LrReI4SYL1KfQiGW7j92b6zTz7RoSEBXACQ9z7UUVfeJ06n8WqVMBaSob4BeFIuHiVKpYCJNv7LR6cI'

NOTE:自定義 traits 建議以 CUSTOM_ 開頭。

  • Update all traits for a specific resource provider
curl -i "http://172.18.22.222/placement/resource_providers/5c5a578f-51b0-481c-b38c-7aaa3394e585/traits" \
-X PUT \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Project-Id: admin' \
-H 'OpenStack-API-Version: placement 1.21' \
-H 'X-Auth-Token:gAAAAABcC12qN3GdLvjYXSSUODi7Dg9jTHUfcnF7I_ljmcffZjs3ignipGLj6iqDvDJ1gXkzGIDW6rRRNcXary-wPfgsb3nCWRIEiAS8LrReI4SYL1KfQiGW7j92b6zTz7RoSEBXACQ9z7UUVfeJ06n8WqVMBaSob4BeFIuHiVKpYCJNv7LR6cI' \
-d '{"resource_provider_generation": 28, "traits": ["HW_CPU_X86_SSE2", "HW_CPU_X86_SSE", "HW_CPU_X86_MMX", "HW_CPU_X86_SVM", "CUSTOM_FANGUIJU_HOST"]}'
  • Return all traits associated with a specific resource provider
[root@control01 ~]# openstack resource provider trait list 5c5a578f-51b0-481c-b38c-7aaa3394e585
+----------------------+
| name                 |
+----------------------+
| HW_CPU_X86_SSE2      |
| HW_CPU_X86_SSE       |
| HW_CPU_X86_MMX       |
| HW_CPU_X86_SVM       |
| CUSTOM_FANGUIJU_HOST |
+----------------------+
  • List allocation cadidates filter by traits
# REQ
curl -i "http://172.18.22.222/placement/allocation_candidates?resources=VCPU:1,MEMORY_MB:512,DISK_GB:5&member_of=5eea7084-0207-44f0-bbeb-c759e8c766a1&required=CUSTOM_FANGUIJU_HOST" \
-X GET \
-H 'Content-type: application/json' \
-H 'Accept: application/json' \
-H 'X-Auth-Project-Id: admin' \
-H 'OpenStack-API-Version: placement 1.21' \
-H 'X-Auth-Token:gAAAAABcC12qN3GdLvjYXSSUODi7Dg9jTHUfcnF7I_ljmcffZjs3ignipGLj6iqDvDJ1gXkzGIDW6rRRNcXary-wPfgsb3nCWRIEiAS8LrReI4SYL1KfQiGW7j92b6zTz7RoSEBXACQ9z7UUVfeJ06n8WqVMBaSob4BeFIuHiVKpYCJNv7LR6cI'

# RESP
{
	"provider_summaries": {
		"5c5a578f-51b0-481c-b38c-7aaa3394e585": {
			"traits": ["HW_CPU_X86_SSE2", "HW_CPU_X86_SSE", "HW_CPU_X86_MMX", "HW_CPU_X86_SVM", "CUSTOM_FANGUIJU_HOST"],
			"resources": {
				"VCPU": {
					"used": 5,
					"capacity": 512
				},
				"MEMORY_MB": {
					"used": 3648,
					"capacity": 60670
				},
				"DISK_GB": {
					"used": 7,
					"capacity": 49
				}
			}
		}
	},
	"allocation_requests": [{
		"allocations": {
			"5c5a578f-51b0-481c-b38c-7aaa3394e585": {
				"resources": {
					"VCPU": 1,
					"MEMORY_MB": 512,
					"DISK_GB": 5
				}
			}
		}
	}]
}

最後

至此,對目前最新的 Placement 實現作一個歸納性的介紹和分析。筆者認爲 Placement 的核心價值仍是在於其高度的 「靈活性」 上,能夠適配用戶在生產環境中的複雜多樣的資源管理需求,也爲雲平臺開發者帶來了一種代碼方案的可行性。若是之後可以提供 API 來支持可視化的資源管理面板,相信也會是一個不錯的用戶爽點。美中不足的是,筆者認爲 Placement 的數據庫設計彷佛缺少彈性,哪怕追加一個 metadata 字段,對開發者而言也算是隻一種慰藉。

擴展閱讀

《OpenStack 2018 年終盤點》

相關文章
相關標籤/搜索