Red Hat Training
A Red Hat training course is available for Red Hat Virtualization
1.5. Interacting with the CLI
The CLI is an interactive shell for controlling your Red Hat Virtualization environment from the command line. Type the required command and any additional parameters.
Example 1.1. Entering a shell command
[RHEVM shell (connected)]# show vm RHEL6-Server
To support the construction of command and parameter combinations, the CLI includes the functionality to list and automatically complete commands and parameters by pressing the
TAB
key twice, similar to the bash shell.
Example 1.2. Listing and automatic completion of commands and parameters
Press double
TAB
at a blank prompt to list all available commands.
[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
Choose a command and press double
TAB
to view the next set of available parameters for the command. For the add
command, this lists all resources.
[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
Double
TAB
also completes commands and parameters.
[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
Note that the double
TAB
also automatically formats na
to the --name
parameter, including the prefix.
If the incomplete parameter matches multiple parameters, double
TAB
lists them.
[RHEVM shell (connected)]# add vTAB TAB
vmpool vm
The CLI provides functions to run Linux commands using either the
shell
command or the bang (!
) character.
Example 1.3. Running Linux shell commands
Use the
shell
command:
[RHEVM shell (connected)]# shell ls -la
Or use the bang (
!
) character:
[RHEVM shell (connected)]# !ls -la
Similar to the Linux shell, the CLI can pipe data to other commands and sources.
Example 1.4. Piping CLI commands
Pipe CLI data to a Linux shell command:
[RHEVM shell (connected)]# list vms --show-all | grep "Example" name : Example1 name : Example2 name : ExampleEngineering description : An Example description name : BestExampleVM
Pipe CLI data to a file:
[RHEVM shell (connected)]# list vms --show-all > list vms --show-all > VM_List.txt
The CLI also contains an online help system to provide descriptions and syntax for each command via the
help
command.
Example 1.5. Using online help for the show
command
[RHEVM shell (connected)]# help show
You can also connect to the Manager from the Linux shell to execute specific commands, in the form of "command resource" and print them to STDIO
Example 1.6. Connecting to the Manager to execute specific commands
Use the
--execute
or -E
parameter to connect to the Manager to execute the specific commands.
# 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