1.5. 与 CLI 交互
CLI 是一个交互式 shell,用于从命令行控制 Red Hat Virtualization 环境。输入所需的命令和任何其他参数。
例 1.1. 输入 shell 命令
[RHEVM shell (connected)]# show vm RHEL6-Server
为了支持命令和参数组合的结构,CLI 包括通过按
TAB
键两次来列出和自动完成命令和参数的功能,类似于 bash shell。
例 1.2. 列出和自动完成命令和参数
在空白提示符处按双
TAB
来列出所有可用的命令。
[RHEVM shell (connected)]# TAB TAB
EOF clear echo history remove summary
action connect exit info shell update
add console file list show
capabilities disconnect help ping status
选择一个命令并按双
TAB
查看 命令的下一个可用参数集合。对于 add 命令,这将列出所有资源。
[RHEVM shell (connected)]# add TAB TAB
affinitygroup datacenter event group nic
quota label template vmpool cdrom
disk filter host permission role
storagedomain user cluster qos glustervolume
network permit snapshot tag vm
双重
TAB
也完成命令和参数。
[RHEVM shell (connected)]# add vmTAB TAB
comment console-enabled cpu-architecture delete_protected description disks-clone display-type io-threads memory name os-type rng_device-source stateless soundcard_enabled start_paused timezone [RHEVM shell (connected)]# add vm naTAB TAB
[RHEVM shell (connected)]# add vm --name
请注意,双
TAB
还自动格式化 na
到 --name
参数,包括前缀。
如果不完整的参数与多个参数匹配,则双重
TAB
列出它们。
[RHEVM shell (connected)]# add vTAB TAB
vmpool vm
CLI 提供了使用 shell 命令或感叹号(
!
)字符运行 Linux 命令的功能。
例 1.3. 运行 Linux shell 命令
使用 shell 命令:
[RHEVM shell (connected)]# shell ls -la
或者使用 bang (
!
)字符:
[RHEVM shell (connected)]# !ls -la
与 Linux shell 类似,CLI 可以管道数据到其他命令和源。
例 1.4. 传送CLI命令
将 CLI 数据传送到 Linux shell 命令:
[RHEVM shell (connected)]# list vms --show-all | grep "Example" name : Example1 name : Example2 name : ExampleEngineering description : An Example description name : BestExampleVM
将 CLI 数据传送到文件:
[RHEVM shell (connected)]# list vms --show-all > list vms --show-all > VM_List.txt
CLI 还包含通过 help 命令提供每个命令的描述和语法的在线 帮助系统。
例 1.5. 在 show 命令中使用在线帮助
[RHEVM shell (connected)]# help show
您也可以从 Linux shell 连接到 Manager,以"命令资源"的形式执行特定的命令,并将其打印到 STDIO
例 1.6. 连接到 Manager 以执行特定命令
使用
--execute
或 -E
参数连接到 Manager 以执行特定的命令。
# ovirt-shell -c -l "https://[server]/ovirt-engine/api" -P [port] -u "[user@domain]" -A "[certificate]" -E "list vms;list hosts" [RHEVM shell (connected)]# list vms id : 9e6977f4-4351-4feb-bba0-dc7c22adec30 name : desktop-01 id : 60b12e28-7965-4296-86bf-c991aa32c2d5 name : server-01 [RHEVM shell (connected)]# list hosts id : 3598cdb9-d21b-49bd-9491-59faff89b113 name : Gluster id : a0c384f9-0940-4562-9c42-4ceaadf8f1f1 name : Host-01 id : 593ec966-c3ea-4bdc-84ad-5dc3f9fe64c7 name : Host-03