The pyvix2.cli module is the comman line API for PyVix2. It allows a number of operations on local or remote hosts.
python -m pyvix2.cli
This is not a complete implementation of the various features of VIX. It’s an implementation that allows an administrator some of the more common VIX operations.
Further, it can easily be extended to modify the implementation or add features.
There are several layers of context which are maintained by VMware and PyVIX2.cli.
There are several commands for interacting with VMware services, and VM’s.
vm< help
Documented commands (type help <topic>):
========================================
EOF bye get host login ls python remsnap running start vm
bash check getsnap list logout put quit revert snapshot stop
Other Commands
==============
help
There are two host commands: host [name] and list.
This will connect with a given VMware service provider. This also sets the host context. The context is changed by exiting the progam or issuing another host command.
The host connection parameters are fetched from the configuration file. Each connection has a name and a dictionary of additional parameters. This dictionary becomes keyword parameters for the pyvix2.Host.connect() method.
If no name is provided, then the configuration named by the default_host parameter is used.
Once connected, this will list VM’s running under control of the current host.
The vm [name], start [name], and stop [name] commands all make a named VM the current working VM. The start command also does power on. The stop command also does power off.
The host VM filenames are fetched from the configuration file. Each VM has an alias and a local filename.
If the name is omitted, then the list of names from the configuration file are shown.
Opens the VM. If it’s running, checks for tools.
The vm< prompt indicates no specific VM has been selected.
The SUSE< prompt shows that the current VM is now the one identified by SUSE in the configuration.
Opens the VM, powers it on, and checks for tools. Since VM’s take time to start, this will wait as long as 120 seconds to determine of tools are present.
Opens the VM, powers it off. If tools are present, does a power off from within the VM. If tools are absent, simply powers it off.
In order to access VM resources, it’s essential that (1) the VM be powered on, (2) the VM have tools installed, and (3) the user has credentials on the VM. The login [name] and logout command will login to the VM.
Once logged in, then the commands running, check word..., python script and bash command can be used.
This will login to the VM. The user remains logged in until (1) another login, (2) logout or (3) the VM is powered off.
SUSE< login slott
password:
VM login 0
SUSE<
Logout from the VM.
This is a list of processes running on the VM.
SUSE< running VM wait_for_tools_in_guest 0 VIX_PROPERTY_VM_TOOLS_STATE: running VM process_list 0 Processes: 91 1 root Tue Oct 04 11:36:40 2011 init [5] 2 root Tue Oct 04 11:36:40 2011 kthreadd 3 root Tue Oct 04 11:36:40 2011 migration/0 4 root Tue Oct 04 11:36:40 2011 ksoftirqd/0 etc.
This will check the list of processes for any of the supplied words. If a process has a name with a given word, that’s shown.
SUSE< check mysql
VM wait_for_tools_in_guest 0
VIX_PROPERTY_VM_TOOLS_STATE: running
VM process_list 0
Processes: 91
Looking for ['mysql']
3891 root Tue Oct 04 11:38:12 2011 /bin/sh /usr/bin/mysqld_safe --mysqld=mysqld
--user=mysql --pid-file=/var/run/mysql/mysqld.pid --socket=/var/run/mysql/mysql.
sock --datadir=/var/lib/mysql
4122 mysql Tue Oct 04 11:38:12 2011 /usr/sbin/mysqld --basedir=/usr --datadir=/v
ar/lib/mysql --user=mysql --log-error=/var/log/mysql/mysqld.log --pid-file=/var/
run/mysql/mysqld.pid --socket=/var/run/mysql/mysql.sock --port=3306
SUSE<
Two processes were found with mysql in their name: 3891 and 4122.
The one-line bash command is executed.
bash date >/home/slott/timestamp
This command doesn’t produce any output. To see if a command was started properly, use running or check word.... Or, be sure that the bash command creates an output file, and get that file.
The given Python script file is executed. Note that the filename must (generally) be fully qualified.
python /path/to/script.py
This command doesn’t produce any output. Be sure that the Python script creates an output file, and get that file.
In order to access VM resources, it’s essential that (1) the VM be powered on, (2) the VM have tools installed, and (3) the user has credentials on the VM. The login [name] and logout command will login to the VM.
Copy a file from the guest to the host.
SUSE< bash date >/home/slott/timestamp
VM script_run 0
SUSE< get /home/slott/timestamp here
VM file_copy_from_guest 0
here
>>> Tue Oct 4 11:02:04 CDT 2011
The >>> line shows the content of the file fetched from the VM.
Copy a file from the host to the guest.
Get a directory listing of files on the guest OS. The path should be fully specified.
SUSE< ls /home/slott
VM directory_list 0
Files: 57
d Templates Fri Feb 25 08:47:33 2011
timestamp Tue Oct 04 11:46:15 2011
hello.py Wed Sep 28 16:37:04 2011
d Public Fri Feb 25 08:47:33 2011
d Pictures Fri Feb 25 08:47:33 2011
d public_html Fri Feb 25 08:37:09 2011
d Desktop Fri Feb 25 08:48:01 2011
d bin Fri Feb 25 08:37:09 2011
status Wed Sep 28 16:39:14 2011
d Documents Sun Oct 02 11:30:01 2011
d Music Fri Feb 25 08:47:33 2011
hostfile Sun Oct 02 16:04:27 2011
d Videos Fri Feb 25 08:47:33 2011
d Downloads Wed Jun 22 11:56:01 2011
See the VMware and VIX documentation for details on snapshots and how they work.
Creates a snapshot. This also becomes the “current” snapshot for further operations.
Locate the named snapshot. This becomes the current snapshot.
If a name is provided, the snapshot is found by name.
If a name is not provided, the existing current snapshot is found.
Remove the current snapshot.
Revert the VM to the given snapshot.