主机预留

先决条件

应安装以下软件包

  • blazar

  • blazar-nova

  • python-blazarclient

1. 将主机添加到空闲池

  1. 使用 host-create 命令将主机添加到 Blazar 空闲池

# Using the blazar CLI
blazar host-create compute-1

# Using the openstack CLI
openstack reservation host create compute-1
  1. 检查空闲池中的主机

# Using the blazar CLI
blazar host-list

# Using the openstack CLI
openstack reservation host list

结果

+----+---------------------+-------+-----------+----------+
| id | hypervisor_hostname | vcpus | memory_mb | local_gb |
+----+---------------------+-------+-----------+----------+
| 1  | compute-1           |     2 |      3951 |       38 |
+----+---------------------+-------+-----------+----------+
  1. (可选) 为主机添加额外的能力以添加其他属性。这些可用于在创建预留时过滤主机。

# Using the blazar CLI
blazar host-update --extra gpu=True compute-1

# Using the openstack CLI
openstack reservation host set --extra gpu=True compute-1

结果

Updated host: compute-1

可以包含多个 --extra 参数。它们也可以在 host-create 中指定。属性可以设为私有或公共。默认情况下,它们是公共的。

# Using the blazar CLI
blazar host-capability-update gpu --private

# Using the openstack CLI
openstack reservation host capability update gpu --private

结果

Updated host extra capability: gpu

2. 创建租赁

  1. 使用 lease-create 命令创建租约(计算主机预留)

# Using the blazar CLI
blazar lease-create --physical-reservation min=1,max=1,hypervisor_properties='[">=", "$vcpus", "2"]' --start-date "2020-06-08 12:00" --end-date "2020-06-09 12:00" lease-1

# Using the openstack CLI
openstack reservation lease create --reservation resource_type=physical:host,min=1,max=1,hypervisor_properties='[">=", "$vcpus", "2"]' --start-date "2020-06-08 12:00" --end-date "2020-06-09 12:00" lease-1

注意

在 openstack 客户端中不可用 --physical-reservation 标志,而是使用 --reservation resource_type=physical:host,如上所示。

结果

+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| Field         | Value                                                                                                                                       |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| action        |                                                                                                                                             |
| created_at    | 2020-06-08 02:43:40                                                                                                                         |
| end_date      | 2020-06-09T12:00:00.000000                                                                                                                  |
| events        | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "before_end_lease", "created_at": "2020-06-08        |
|               | 02:43:40", "updated_at": null, "time": "2020-06-08T12:00:00.000000", "id": "420caf25-dba5-4ac3-b377-50503ea5c886"}                          |
|               | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "start_lease", "created_at": "2020-06-08 02:43:40",  |
|               | "updated_at": null, "time": "2020-06-08T12:00:00.000000", "id": "b9696139-55a1-472d-baff-5fade2c15243"}                                     |
|               | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "end_lease", "created_at": "2020-06-08 02:43:40",    |
|               | "updated_at": null, "time": "2020-06-09T12:00:00.000000", "id": "ff9e6f52-db50-475a-81f1-e6897fdc769d"}                                     |
| id            | 6638c31e-f6c8-4982-9b98-d2ca0a8cb646                                                                                                        |
| name          | lease-1                                                                                                                                     |
| project_id    | 4527fa2138564bd4933887526d01bc95                                                                                                            |
| reservations  | {"status": "pending", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "resource_id": "8", "max": 1, "created_at": "2020-06-08           |
|               | 02:43:40", "min": 1, "updated_at": null, "hypervisor_properties": "[\">=\", \"$vcpus\", \"2\"]", "resource_properties": "", "id":           |
|               | "4d3dd68f-0e3f-4f6b-bef7-617525c74ccb", "resource_type": "physical:host"}                                                                   |
| start_date    | 2020-06-08T12:00:00.000000                                                                                                                  |
| status        |                                                                                                                                             |
| status_reason |                                                                                                                                             |
| trust_id      | ba4c321878d84d839488216de0a9e945                                                                                                            |
| updated_at    |                                                                                                                                             |
| user_id       |                                                                                                                                             |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  1. 检查租赁

# Using the blazar CLI
blazar lease-list

# Using the openstack CLI
openstack reservation lease list

结果

+--------------------------------------+---------+----------------------------+----------------------------+
| id                                   | name    | start_date                 | end_date                   |
+--------------------------------------+---------+----------------------------+----------------------------+
| 6638c31e-f6c8-4982-9b98-d2ca0a8cb646 | lease-1 | 2020-06-08T12:00:00.000000 | 2020-06-09T12:00:00.000000 |
+--------------------------------------+---------+----------------------------+----------------------------+
  1. 或者,使用资源属性创建租约。首先列出属性。

# Using the blazar CLI
blazar host-capability-list

# Using the openstack CLI
openstack reservation host capability list

结果

+----------+
| property |
+----------+
| gpu      |
+----------+

列出属性的可能值

# Using the blazar CLI
blazar host-capability-show gpu

# Using the openstack CLI
openstack reservation host capability show gpu

结果

+-------------------+-------+
| Field             | Value |
+-------------------+-------+
| capability_values | True  |
|                   | False |
| private           | False |
| property          | gpu   |
+-------------------+-------+

创建租约。

# Using the blazar CLI
blazar lease-create --physical-reservation min=1,max=1,resource_properties='["=", "$gpu", "True"]' --start-date "2020-06-08 12:00" --end-date "2020-06-09 12:00" lease-1

# Using the openstack CLI
openstack reservation lease create --reservation resource_type=physical:host,min=1,max=1,resource_properties='[">=", "$vcpus", "2"]' --start-date "2020-06-08 12:00" --end-date "2020-06-09 12:00" lease-1

结果

+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| Field         | Value                                                                                                                                       |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| action        |                                                                                                                                             |
| created_at    | 2020-06-08 02:43:40                                                                                                                         |
| end_date      | 2020-06-09T12:00:00.000000                                                                                                                  |
| events        | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "before_end_lease", "created_at": "2020-06-08        |
|               | 02:43:40", "updated_at": null, "time": "2020-06-08T12:00:00.000000", "id": "420caf25-dba5-4ac3-b377-50503ea5c886"}                          |
|               | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "start_lease", "created_at": "2020-06-08 02:43:40",  |
|               | "updated_at": null, "time": "2020-06-08T12:00:00.000000", "id": "b9696139-55a1-472d-baff-5fade2c15243"}                                     |
|               | {"status": "UNDONE", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "event_type": "end_lease", "created_at": "2020-06-08 02:43:40",    |
|               | "updated_at": null, "time": "2020-06-09T12:00:00.000000", "id": "ff9e6f52-db50-475a-81f1-e6897fdc769d"}                                     |
| id            | 6638c31e-f6c8-4982-9b98-d2ca0a8cb646                                                                                                        |
| name          | lease-1                                                                                                                                     |
| project_id    | 4527fa2138564bd4933887526d01bc95                                                                                                            |
| reservations  | {"status": "pending", "lease_id": "6638c31e-f6c8-4982-9b98-d2ca0a8cb646", "resource_id": "8", "max": 1, "created_at": "2020-06-08           |
|               | 02:43:40", "min": 1, "updated_at": null, "hypervisor_properties": "", "resource_properties": "[\"=\", \"$gpu\", \"True\"]", "id":           |
|               | "4d3dd68f-0e3f-4f6b-bef7-617525c74ccb", "resource_type": "physical:host"}                                                                   |
| start_date    | 2020-06-08T12:00:00.000000                                                                                                                  |
| status        |                                                                                                                                             |
| status_reason |                                                                                                                                             |
| trust_id      | ba4c321878d84d839488216de0a9e945                                                                                                            |
| updated_at    |                                                                                                                                             |
| user_id       |                                                                                                                                             |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------+

3. 使用已租用的资源

  1. 创建服务器:请将预留 ID 指定为调度器提示。

openstack server create --flavor <flavor> --image <image> --network <network> --hint reservation=4d3dd68f-0e3f-4f6b-bef7-617525c74ccb <server-name>