概览

[root@cc07 ~]# nova help | grep flavor
flavor-access-add Add flavor access for the given tenant.
flavor-access-list Print access information about the given
flavor.
flavor-access-remove Remove flavor access for the given tenant.
flavor-create Create a new flavor.
flavor-delete Delete a specific flavor
flavor-key Set or unset extra_spec for a flavor.
flavor-list Print a list of available 'flavors' (sizes of
flavor-show Show details about the given flavor.
flavor-update Update the description of an existing flavor.

列表

[root@cc07 ~]# nova flavor-list
+------------------------------------------------------------+------------------------------------------------------------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+------------------------------------------------------------+------------------------------------------------------------+-----------+------+-----------+------+-------+-------------+-----------+
| boshen_ram_1024_disk_1_vcpus_1 | boshen_ram_1024_disk_1_vcpus_1 | | | | | | 1.0 | True |
| e6e7ffa7-52e5-47b0-8a74-669adcbe64c2 | warm_wocloud_vpn_2_2048 | | | | | | 1.0 | True |
| ubuntu_1604 | ubuntu_1604 | | | | | | 1.0 | True |
| vcpus_16_cpu_cores_8_cpu_sockets_2_ram_16384_disk_50_eph_0 | vcpus_16_cpu_cores_8_cpu_sockets_2_ram_16384_disk_50_eph_0 | | | | | | 1.0 | True |
| vcpus_16_cpu_cores_8_cpu_sockets_2_ram_32768_disk_50_eph_0 | vcpus_16_cpu_cores_8_cpu_sockets_2_ram_32768_disk_50_eph_0 | | | | | | 1.0 | True |
| vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_10_eph_0 | vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_10_eph_0 | | | | | | 1.0 | True |
| vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_1_eph_0 | vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_1_eph_0 | | | | | | 1.0 | True |
| vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_2_eph_0 | vcpus_1_cpu_cores_1_cpu_sockets_1_ram_1024_disk_2_eph_0 | | | | | | 1.0 | True |
+------------------------------------------------------------+------------------------------------------------------------+-----------+------+-----------+------+-------+-------------+-----------+

创建自定义的flavor

格式:nova flavor-create --is-public true FLAVOR_NAME FLAVOR_ID RAM_IN_MB ROOT_DISK_IN_GB NUMBER_OF_VCPUS

例子:

[root@cc07 ~]# nova flavor-create --is-public true boshen_ram_1024_disk_1_vcpus_1 boshen_ram_1024_disk_1_vcpus_1
+--------------------------------+--------------------------------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------+--------------------------------+-----------+------+-----------+------+-------+-------------+-----------+
| boshen_ram_1024_disk_1_vcpus_1 | boshen_ram_1024_disk_1_vcpus_1 | | | | | | 1.0 | True |
+--------------------------------+--------------------------------+-----------+------+-----------+------+-------+-------------+-----------+

查看详情

[root@cc07 ~]# nova flavor-show boshen_ram_1024_disk_1_vcpus_1
+----------------------------+--------------------------------+
| Property | Value |
+----------------------------+--------------------------------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | |
| disk | |
| extra_specs | {} |
| id | boshen_ram_1024_disk_1_vcpus_1 |
| name | boshen_ram_1024_disk_1_vcpus_1 |
| os-flavor-access:is_public | True |
| ram | |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | |
+----------------------------+--------------------------------+

设置flavor的extra_specs属性

[root@cc07 ~]# nova flavor-key boshen_ram_1024_disk_1_vcpus_1 set aggregate_instance_extra_specs:ssd=true
[root@cc07 ~]# nova flavor-show boshen_ram_1024_disk_1_vcpus_1
+----------------------------+------------------------------------------------+
| Property | Value |
+----------------------------+------------------------------------------------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | |
| disk | |
| extra_specs | {"aggregate_instance_extra_specs:ssd": "true"} |
| id | boshen_ram_1024_disk_1_vcpus_1 |
| name | boshen_ram_1024_disk_1_vcpus_1 |
| os-flavor-access:is_public | True |
| ram | |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | |
+----------------------------+------------------------------------------------+

创建flavor后,指定一个或多个键值对,让这些键值对与主机集群上的键值对匹配,范围为aggregate_instance_extra_specs。 在这种情况下,设置格式为:aggregate_instance_extra_specs:ssd = true键值对。

当用户请求具有 boshen_ram_1024_disk_1_vcpus_1 规格的实例时,调度程序仅考虑具有ssd = true键值对的主机

将flavor赋给tenant

(nova-api)[root@cc07 /]# openstack project list |grep hzb
| 26a8e1feb372493d831c19d4d9e28d73 | hzb_tenant |
| c49b95e8961249ea9e87a4507c10e122 | hzb_tenant2
[root@cc07 ~]# nova flavor-access-add boshen_ram_1024_disk_1_vcpus_1 26a8e1feb372493d831c19d4d9e28d73
+--------------------------------+----------------------------------+
| Flavor_ID | Tenant_ID |
+--------------------------------+----------------------------------+
| boshen_ram_1024_disk_1_vcpus_1 | 26a8e1feb372493d831c19d4d9e28d73 |
+--------------------------------+----------------------------------+
[root@cc07 ~]# nova  flavor-access-list --flavor boshen_ram_1024_disk_1_vcpus_1
ERROR (CommandError): Access list not available for public flavors.
[root@cc07 ~]# nova  flavor-access-list --flavor boshen_ram_1024_disk_1_vcpus_1
ERROR (CommandError): Access list not available for public flavors.

解除租户

[root@cc07 ~]# nova flavor-access-remove boshen_ram_1024_disk_1_vcpus_1 26a8e1feb372493d831c19d4d9e28d73
+-----------+-----------+
| Flavor_ID | Tenant_ID |
+-----------+-----------+
+-----------+-----------+

删除flavor

nova flavor-delete boshen_ram_1024_disk_1_vcpus_1
05-08 08:43