Show Table of Contents
1.5. 使用 CLI
CLI 是一个交换式的 shell,您可以使用它来通过命令行对 Red Hat Virtualization 环境进行控制。您可以在 shell 中输入所需的命令和选项。
例 1.1. 输入一个 shell 命令
[RHEVM shell (connected)]# show vm --name desktop_vms
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 键会列出这个命令可用的参数。假设选择了 show 命令,它会列出所有资源。
[RHEVM shell (connected)]# show TAB TAB
brick datacenter event group nic
quota statistic template vmpool cdrom
disk file host permission role
storagedomain user cluster domain glustervolume
network permit snapshot tag vm
双击
TAB 键会完成命令和参数输入。
[RHEVM shell (connected)]# show vmTAB TABkwargs name show-all storagedomain [RHEVM shell (connected)]# show vm naTAB TAB[RHEVM shell (connected)]# show vm --name
双击
TAB 键可以自动把 na 变为 --name 参数(包括 '--' 前缀)。
如果未完成的参数和多个参数匹配,双击
TAB 将会列出所有匹配的参数。
[RHEVM shell (connected)]# show vTAB TAB
vmpool vm
CLI 提供了使用
shell 命令或 ! 来运行 Linux 命令的功能。
例 1.3. 运行 Linux shell 命令
使用
shell 命令:
[RHEVM shell (connected)]# shell ls -la
或使用
!:
[RHEVM shell (connected)]# !ls -la
和 Linux shell 相似,CLI 可以使用管道(pipe)把数据传递给其它命令或资源。
例 1.4. 在 CLI 中使用管道(pipe)
把 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 后执行特定的命令(命令格式是 "command resource"),并把命令输出打印到 STDIO
例 1.6. 连接到 Manager 来执行特定的命令
使用
--execute 或 -E 参数连接到 Manager 来执行特定命令。
# ovirt-shell -c -l "https://[server]/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

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.