nova 命令汇总四

——计算相关命令

 

      本节叙述一下计算资源相关的命令,重点分为管理计算节点的命令和虚拟机生命周期的管理命令。

 管理计算节点的命令:

 1. aggregate-add-host         

功能: 将计算节点添加到指定的主机集合

用法: nova aggregate-add-host <aggregate> <host>

参数:<aggregate>  聚合的名称或ID;  <host>   添加到指定聚合的主机

2. aggregate-create         

功能:创建一个新的主机集合

用法:nova aggregate-create <name> [<availability-zone>]

参数: <name>   集合的名称; <availability-zone>  集合的可用域

3. aggregate-delete          

功能: 删除指定的主机集合

用法:nova aggregate-delete <aggregate>

参数:<aggregate> 聚合的名称或ID

4. aggregate-list              

功能:列举所有主机集合的详细信息usage: nova aggregate-list

用法: nova aggregate-list

参数:无

5. aggregate-remove-host     

功能:将计算节点从指定主机集合中移除

用法:nova aggregate-remove-host <aggregate> <host>

参数:<aggregate>  聚合的名称或ID;  <host>   指定聚合的主机

6. evacuate                 

功能:从故障主机疏散撤离虚拟机

用法:nova evacuate [--password <password>] [--on-shared-storage]

                                    <server> [<host>]

参数:

  <server>           故障主机中的虚拟机

  <host>                目标主机的名称或ID。如果没有指定主机,则调度器将选择一个。

  --password <password>  设置已疏散服务器上的密码。不适用于共享存储标志

  --on-shared-storage   指定服务器文件是否位于共享存储器上

7. host-action                

功能:开启、关闭或者重启计算节点

用法:nova host-action [--action <action>] <hostname>

参数:

  <hostname>        主机名.

  --action <action>  A power action: startup, reboot, or shutdown.

8. hypervisor-list

功能:虚拟机监控程序列表

用法:nova hypervisor-list [--matching <hostname>]

参数:--matching <hostname> 列表管理程序,匹配指定的<主机名>

9. hypervisor-servers          

功能:列举出一个计算节点下的所有虚拟机

用法:nova hypervisor-servers <hostname>

参数: <hostname>  计算节点名(可通过'nova host-list | grep compute' 获得)

10. hypervisor-show           

功能: 显示指定的管理程序的详细信息

用法:nova hypervisor-show <hypervisor>

参数: <hypervisor>  hypervisor的名称或ID,以显示详细信息(可通过'nova hypervisor-list'获得)

11. hypervisor-stats           

功能:获得所有计算节点上的hypervisor统计信息。

用法:nova hypervisor-stats

参数:无

 

 

 虚拟机生命周期的管理命令,包括:虚拟机的创建、开机、关机、迁移等。

1.backup

      功能:通过创建一个backup类型的快照来备份虚拟机

      用法:nova backup <server> <name> <backup-type> <rotation>

   参数: <server> 虚拟机的名称或者UUID<name> 备份镜像的名称; <backup-type> 备份类型,如 "daily" or "weekly"<rotation> 整数用来代表轮询的数量

  

2.  boot                       

功能:启动一个新的虚拟机

用法: nova boot [--flavor <flavor>] [--image <image>]

                 [--image-with <key=value>] [--boot-volume <volume_id>]

                 [--snapshot <snapshot_id>] [--min-count <number>]

                 [--max-count <number>] [--meta <key=value>]

                 [--file <dst-path=src-path>] [--key-name <key-name>]

                 [--user-data <user-data>]

                 [--availability-zone <availability-zone>]

                 [--security-groups <security-groups>]

                 [--block-device-mapping <dev-name=mapping>]

                 [--block-device key1=value1[,key2=value2...]]

                 [--swap <swap_size>]

                 [--ephemeral size=<size>[,format=<format>]]

                 [--hint <key=value>]

                 [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr                                                               ,port-id=port-uuid>]

                 [--config-drive <value>] [--poll]

                 <name>

参数:

--flavor <flavor>            flavor的名称或ID (通过'nova flavor-list'获得)

  --image <image>              镜像的名称或ID (通过'nova image-list'获得)

  --image-with <key=value>      镜像元数据特性(通过'nova image-show'获得)

  --boot-volume <volume_id>   从云硬盘启动的云硬盘ID

  --snapshot <snapshot_id>      从快照中启动(将会创建一个云硬盘)

  --min-count <number>         创建虚机的最小个数(受配额限制)

  --max-count <number>        创建虚机额最大个数(受配额限制)

  --meta <key=value>            虚拟机的元数据

  --file <dst-path=src-path>   在新创建的虚拟机上从源地址到目的地址存储任意文件(受注入文件的配额值限制)

  --key-name <key-name>        密钥对的名称

  --user-data <user-data>       通过元数据服务器传输的用户数据文件

  --availability-zone <availability-zone>          可用域,用于承载虚拟机

  --security-groups <security-groups>           安全组名称

  --block-device-mapping <dev-name=mapping>     块设备映射的格式(挂载的云硬盘)

                                              <dev-name>=<id>:<type>: <size(GB)>:<delete-on-terminate>.

  --block-device key1=value1[,key2=value2...]

                                 块设备映射键值: id=UUID

                                (image_id, snapshot_id or volume_id only if

                                using source image, snapshot or volume)

                                source=source type (image, snapshot, volume or

                                blank), dest=destination type of the block

                                device (volume or local), bus=device's bus

                                (e.g. uml, lxc, virtio, ...; if omitted,

                                hypervisor driver chooses a suitable default,

                                honoured only if device type is supplied)

                                type=device type (e.g. disk, cdrom, ...;

                                defaults to 'disk') device=name of the device

                                (e.g. vda, xda, ...; if omitted, hypervisor

                                driver chooses suitable device depending on

                                selected bus), size=size of the block device

                                in GB (if omitted, hypervisor driver

                                calculates size), format=device will be

                                formatted (e.g. swap, ntfs, ...; optional),

                                bootindex=integer used for ordering the boot

                                disks (for image backed instances it is equal

                                to 0, for others need to be specified) and

                                shutdown=shutdown behaviour (either preserve

                                or remove, for local destination set to

                                remove).

  --swap <swap_size>           创建并附加一个本地交换块设备<swap_size> MB.

  --ephemeral size=<size>[,format=<format>]

                                创建并挂载本地临时的块设备<size> GB and format it to <format>.

  --hint <key=value>           向调度器发送任意键/值对以供自定义使用

  --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uu                                                               id>

                                 配置驱动

  --config-drive <value>        启用配置驱动

  --poll                       报告最新虚机启动的过程直到完成

 

3.  delete

功能:直接关闭并删除一个或者多个虚拟机

用法:nova delete <server> [<server> ...]

参数:<server>虚拟机名称或ID

4.  diagnostics

功能:获取虚拟机CPU、内存等的使用情况

用法:nova diagnostics <server>

参数:<server>虚拟机名称或ID

5. list

功能: 列举当前用户所有虚拟机

用法:nova list [--reservation-id <reservation-id>] [--ip <ip-regexp>]

                 [--ip6 <ip6-regexp>] [--name <name-regexp>]

                 [--instance-name <name-regexp>] [--status <status>]

                 [--flavor <flavor>] [--image <image>] [--host <hostname>]

                 [--all-tenants [<0|1>]] [--tenant [<tenant>]] [--deleted]

                 [--fields <fields>] [--minimal]

参数:

  --reservation-id <reservation-id>         只返回匹配预定id的服务器

  --ip <ip-regexp>             搜索,用ip进行正则表达式匹配地址

  --ip6 <ip6-regexp>         搜索与正则表达式匹配IPv6地址

  --name <name-regexp>          搜索,使用正则表达式匹配的名称

  --instance-name <name-regexp>

                                通过服务器名称搜索正则表达式匹配项

  --status <status>             搜索服务器状态

  --flavor <flavor>           搜索的flavor的名称或ID

  --image <image>              搜索image的名称或ID

  --host <hostname>           搜索服务器,主机名为它们所在的主机名指定(只管理)

  --all-tenants [<0|1>]         显示来自所有租户的信息 (Admin  only).

  --tenant [<tenant>]           从单个租户显示信息(Admin  only).

  --deleted                   仅显示已删除服务器 (Admin only).

  --fields <fields>           逗号分隔的字段列表显示。使用show命令查看哪些字段可用

  --minimal                     只能得到虚拟机的uuid和名称

举例:nova list --all-tenants  --tenant    tenant_id              查看一个租户下的所有云主机信息

5. live-migration           

功能:  执迁移

用法: nova live-migration [--block-migrate] [--disk-over-commit]

                           <server> [<host>]

参数:

  --block-migrate           块迁移(Default=False:live_migration)

  --disk-over-commit      允许过量使用(Default=False)

<server>    虚拟机名称或ID

<host>       迁移到指定的主机名

6. force-delete

功能:强制删除虚拟机

用法: nova force-delete <server>

参数:<server> 要删除虚机的名称或者ID

 

本节举例了平时常用的与计算相关的命令,其它命令可参考nova help