Oracle VM Site Review - Oracle VM Health Check
view counter

The Oracle VM Manager Command Line Interface

Last update 08-14-09
 
The Oracle VM Manager Command Line Interface (CLI) chapter will start with an introduction to the Oracle VM Manager Command Line Interface. After the introduction, we will review how to download the Oracle VM Manager Command Line Interface from Oracle Unbreakable Linux Network (ULN). Next, we will review how to install and configure the Oracle VM Manager Command Line Interface. The chapter will conclude with example Oracle VM Manager Command Line Interface bulk command examples, batch scripting examples and programming examples.
 
Table of Contents
 
The Oracle VM Manager Command Line Interface is an Oracle VM Manager add on that is available to Oracle Unbreakable Linux support customers via the Oracle Unbreakable Linux Network.  The Oracle VM Manager Command Line Interface offers a command-line interface for Oracle VM Manager.  The Oracle VM Manager Command Line Interface allows Oracle VM Manager functions to be executed from the command-line. Oracle VM Manager Command Line Interface commands can be scripted allowing automation of administrative tasks, such as checking status, performing lifecycle management, and executing bulk actions.
 
List 1 highlights the most common use cases for the Oracle VM Manager Command Line Interface:
  • Guest, server and server pool lifecycle management:
    • Power On, Power Off, Clone, Save as Template, Import, Migrate, Pause, Unpause, Suspend, Resume and Delete virtual machines
    • Manage virtual machine resources, including ISO files, virtual machine templates and virtual machine images
    • Manage Oracle VM Manager users, and Oracle VM Manager groups
    • Create and configure server pools
    • Manage the Oracle VM Agent
  • Checking the status of guests, server, and server pools:
    • Get a list of running guests in server pool
    • Get a list of active pool servers
    • Diagnose and troubleshoot issues with guests, servers, and server pools
    • Get configuration and status information for guests, servers and server pools
  • Performing bulk operations:
    • With multiple guests
    • With multiple servers
    • With multiple server pools
The Oracle VM Manager Command Line Interface (ovmcli) is a stand-alone application that is written in Python that leverages the Oracle VM Manager Web Services API to communicate with Oracle VM Manager. The Oracle VM Manager Command Line Interface can be installed on any Oracle Enterprise Linux or RHEL host with connectivity to your Oracle VM Manager system.  The Oracle VM Manager Command Line Interface can be accessed from a local or remote console.
 
Figure 1 illustrates the Oracle VM Manager Command Line Interface intra-component communication and firewall requirements.


List 2 highlights the Oracle VM Manager Command Line Interface communication ports and system passwords:

Oracle VM Manager:
  • The default HTTP port of Oracle VM Manager UI is 8888.
  • Remote access to the Command Line Interface hosts via ssh on port 22
  • Guest console access uses ports 5900 through 5999.
  • Guest console access requires a password without a user name.
The Oracle VM Manager Command Line Interface has one prerequisite, namely the python-ZSI RPM. The ovmcli and python-ZSI RPMs are hosted at ULN. The ovmcli RPM is located in the el5_i386_oracle_addons and the el5_x86_64_oracle_addons channel. The python-ZSI RPM is located in the el5_i386_addons and el5_x86_64_addons channel.
 
In this section we will walk through the procedure to download the Oracle VM Manager Command Line Interface. We will start with a visit to ULN, to search for, and download, the ovmcli and python-ZSI RPMs. After the download section, we will walk through the installation and configuration of the Oracle VM Manager Command Line Interface on an Oracle Enterprise Linux host. If you have already downloaded the RPMs from ULN, please skip to the next section.
 
Note: ULN is password protected. To access ULN you will need a valid Oracle Unbreakable Linux support contract and a CSI number. Support contracts for Oracle VM can be purchased from your Oracle VM sales representative or directly from the Oracle Store. Once you have a valid support contract, you can register at the ULN portal or you can register by running the “up2date –register” command from one of your Oracle VM servers. Please review Oracle VM: How to update an Oracle VM Server for details about registering an Oracle VM server with ULN.
 
The Oracle VM Manager Command Line Interface (ovmcli) is hosted at ULN in the el5_i386_oracle_addons and el5_x86_64_oracle_addons channels. The Oracle VM Manager Command Line Interface prerequisite python-ZSI is hosted in the el5_i386_addons and el5_x86_64_addons channel.
 
Table 1 shows the Oracle VM Manager Command Line Interface package names with the associated ULN channel names.
Package
ULN Channel
ovmcli-1.0-1.el5.noarch.rpm
el5_i386_oracle_addons and el5_x86_64_oracle_addons
python-ZSI-2.1-a1.el5.noarch.rpm
el5_i386_addons and el5_x86_64_addons
1- Point your browser to http://linux.oracle.com as shown in Figure 2. Enter you user name and password and click the Login button to access ULN.

 2- From the ULN home page click on the Channels tab as shown in Figure 3.

 
3- From the Channels page click the i386_oracle_addons channel for the x86 platform or click the el5_x86_64_oracle_addons channel for the x86-64 platform to download the appropriate ovmcli RPM.
 
In our example we are looking for the el5_x86_64_oracle_addons channel which is not displayed on the current page. We will need to access the next page to locate the el5_x86_64_oracle_addons channel. Click the Next button at the bottom of the page as shown in Figure 4 to display the next page.
 
4- From the Channels page click the el5_x86_64_oracle_addons channel as shown in Figure 5.
 
5- From the Oracle Software addons for Enterprise Linux 5 (X86-64) page, click the Packages link as shown in Figure 6.
 
6- From the Oracle Software addons for Enterprise Linux 5 (X86-64) > Packages page, click the ovmcli-1.0-1.el5.noarch link as shown in Figure 7 to display the ovmcli-1.0-1.el5.noarch RPM Package Details page.
 
7- From the Oracle Software addons for Enterprise Linux 5 (X86-64) > Packages > ovmcli-1.0-1.el5.noarch page, click the ovmcli-1.0-1.el5.noarch.rpm link as shown in Figure 8 to download the ovmcli-1.0-1.el5.noarch RPM.
 
Note: The File list link lists the details about all the files for the ovmcli-1.0-1.el5.noarch RPM. The Requires link lists the requirements for the ovmcli-1.0-1.el5.noarch RPM. The Provides link lists what the ovmcli-1.0-1.el5.noarch RPM provides, i.e. the ovmcli. The Obsoletes link lists what application(s) the ovmcli-1.0-1.el5.noarch RPM obsoletes. The Conflicts link lists the conflicts for the ovmcli-1.0-1.el5.noarch RPM.
 
8- From the Oracle Software addons for Enterprise Linux 5 (X86-64) > Packages > ovmcli-1.0-1.el5.noarch page, click the Channel link as shown in Figure 9 to return to the Channel page to download the python-ZSI RPM.
 
9- From the Channels page locate and click the el5_x86_64_addons channel link as shown in Figure 10 to access the Enterprise Linux 5 Add ons (X86-64) > Packages page.
 
10- From the Oracle Enterprise Linux 5 Add ons (x86-64) > Packages page click the python-ZSI-2.1-a1.el5.noarch.rpm link as shown in Figure 11 to display the Enterprise Linux 5 Add ons (X86-64) > Packages >  python-ZSI-2.1-a1.el5.noarch.rpm page.
 
11- From the Enterprise Linux 5 Add ons (X86-64) > Packages >  python-ZSI-2.1-a1.el5.noarch.rpm page, click the python-ZSI-2.1-a1.el5.noarch.rpm link as shown in Figure 12 to download the python-ZSI-2.1-a1.el5.noarch.rpm RPM.
 
Note: The File list link lists the details about all the files for the python-ZSI-2.1-a1.el5.noarch.rpm RPM. The Requires link lists the requirements for the python-ZSI-2.1-a1.el5.noarch.rpm RPM. The Provides link lists what the python-ZSI-2.1-a1.el5.noarch.rpm RPM provides, i.e. python-ZSI. The Obsoletes link lists what application(s) the python-ZSI-2.1-a1.el5.noarch.rpm RPM obsoletes. The Conflicts link lists the conflicts for the python-ZSI-2.1-a1.el5.noarch.rpm RPM. 
 

In the Oracle VM Manager Command Line Interface Download section we visted ULN and downloaded the ovmcli and python-ZSI RPM. In the next section we will walk through the installation and configuration of the Oracle VM Manager Command Line Interface.

 
In the Oracle VM Manager Command Line Interface installation and configuration section we will first walk through the Oracle VM Manager Command Line Interface installation followed by the Oracle VM Manager Command Line Interface configuration.
 
The Oracle VM Manager Command Line Interface installation is a quick and simple process that requires two RPMs, a) ovmcli and b) python-ZSI. As soon as you have downloaded both RPMs and a) placed them on the host or b) mounted a share with the RPMs you can install the Command Line Interface RPMs by running “rpm –Uvh ovmcli-1.0-1.el5.noarch.rpm python-ZSI-2.1-a1.el5.noarch.rpm” on the Enterprise Linux host as root.
 
Table 2 shows a successful Oracle VM Manager Command Line Interface installation.
# rpm -Uvh ovmcli-1.0-1.el5.noarch.rpm python-ZSI-2.1-a1.el5.noarch.rpm
Preparing...                ########################################### [100%]
   1:python-ZSI             ########################################### [ 50%]
   2:ovmcli                 ########################################### [100%]
#
Once you have installed the Oracle VM Manager Command Line Interface you can configure the Oracle VM Manager Command Line Interface by running "ovm config" as root.  The Oracle VM Manager Command Line Interface configuration will ask for the following five pieces of information as shown in List 3:
  1. Oracle VM Manager hostname
  2. Oracle VM Manager port number (the default is 8888)
  3. Deploy path (use the default)
  4. Location of vncviewer (required for vncviewer command, e.g. /usr/bin/vncviewer – i.e. run ”which vncviewer” to find the path to vncviewer)
  5. Enable or disable HTTPS support (depends on Oracle VM Manager setup)
 The next example shows a complete "ovm config" session.
# ovm config
This is a wizard for configuring the Oracle VM Manager Command Line Interface.
CTRL-C to exit.
Oracle VM Manager hostname: ovm1.sf.seo.com
Oracle VM Manager port number: 8888
Deploy path (leave blank for default):
Location of vncviewer (leave blank to skip): /usr/bin/vncviewer
Enable HTTPS support? (Y/n): n
Configuration complete.
Please rerun the Oracle VM Manager Command Line Interface.
#
You have successfully configured the Oracle VM Manager Command Line Interface. The Oracle VM Manager Command Line Interface is now ready for use and can be accessed from local or remote console by typing "ovm". 
 
The next section introduces how to use the Oracle VM Manager Command Line Interface starting with a single command, then a bulk command and concluding with batch script examples. 
This section will start with an introduction to using the Oracle VM Manager Command Line Interface. After the Oracle VM Manager Command Line Interface introduction we will walk through various example Oracle VM Manager Command Line Interface use cases starting with single operation command followed by bulk commands and batch scripting examples.
 
The Oracle VM Manager Command Line Interface can be accessed from the local or remote console from the server hosting the Oracle VM Manager Command Line Interface. Commands can be executed directly from the command line or from within the Oracle VM Manager Command Line Interface shell.
 
The Oracle VM Manager Command Line Interface shell can be accessed by typing “ovm –u username –p your_password shell” as shown in the following example:
# ovm -u username -p password shell
ovm>
You would substitute username with a valid Oracle VM Manager user name and substitute password with a valid password to authenticate into the shell.
 
Once you have successfully authenticated in to the Oracle VM Manager Command Line Interface shell you will be presented with the “ovm>” prompt. From the “ovm>” prompt you can enter the desired subcommands. From the Oracle VM Manager Command Line Interface shell, type “ovm help”, to display an abbreviated list of the help messages, as shown below.
ovm> help
Usage: subcommand [suboptions]
 
Oracle VM Manager Command Line Interface
 
Subcommands:
 
group             ---   Group management
img               ---   Virtual machine image management
iso               ---   ISO image management
sd                ---   Shared virtual disk management
svr               ---   Server management
svrp              ---   Server pool management
tmpl              ---   Virtual machine template management
user              ---   User management
val               ---   System parameter management
vm                ---   Virtual machine management
config            ---   CLI configuration
connect           ---   Connect to Oracle VM Manager from CLI shell
exit              ---   Exit
help              ---   Show help
shell             ---   Launch an interactive shell
use               ---   Specify a server pool to use
vncviewer         ---   Start a VNC console
 
"help <subcommand>" displays help message for that subcommand.
"help all" displays complete list of subcommands.
 
ovm>
Tip: Help messages for subcommands, i.e. "help <subcommand>" will display the help message for that subcommand. The "help all" command displays a complete list of all the subcommands.
 
Subcommands can also be run directly from the command line outside of the Oracle VM Manager Command Line Interface shell. The next example shows how to display the help message from the command line, not from the Oracle VM Manager Command Line Interface shell.
# ovm -u username -p password help
Usage: ovm [options] subcommand [suboptions]
 
Oracle VM Manager Command Line Interface
 
Subcommands:
 
group             ---   Group management
img               ---   Virtual machine image management
iso               ---   ISO image management
sd                ---   Shared virtual disk management
svr               ---   Server management
svrp              ---   Server pool management
tmpl              ---   Virtual machine template management
user              ---   User management
val               ---   System parameter management
vm                ---   Virtual machine management
config            ---   CLI configuration
connect           ---   Connect to Oracle VM Manager from CLI shell
exit              ---   Exit
help              ---   Show help
shell             ---   Launch an interactive shell
use               ---   Specify a server pool to use
vncviewer         ---   Start a VNC console
#
To recap, subcommands can be entered from the Oracle VM Manager Command Line Interface shell or directly from the server’s console. Table 3 shows the same “help” command run from the Oracle VM Manager Command Line Interface shell and from the Oracle VM Manager Command Line Interface server’s console.
Command Line Interface shell
Server console
# ovm -u username -p password shell
ovm> help
# ovm -u username -p password help
In this section, we will start with an introduction to Oracle VM Manager Command Line Interface bulk commands and batch scripting. After the introduction, we will walk through two Oracle VM Manager Command Line Interface use case examples. The first use case will show how to suspend and then resume four guests, to accommodate a backup schedule. The last example will show how to add an Oracle VM server to an existing server pool.
 
Note: We will be adding new example Oracle VM Manager Command Line Interface use cases to this chapter on a regular bases. Stay tuned!
 
Bulk commands can be run from the command line or via batch scripts. For example, if you wanted to suspend multiple guests with a single command i.e. “vm suspend”, this could be accomplished by typing multiple “vm suspend” commands separated by a semi-colon.
 
Before we execute our fist “vm suspend” bulk command, lets check the status of our virtual machines using the “vm ls” command. The “vm ls” command can be entered from the Oracle VM Manager Command Line Interface shell or directly from the console.
 
The next example shows the “vm ls” command entered at the server console which will list the status of all of the virtual machines in your Oracle VM server farm.
# ovm -u admin -p password vm ls
Name                  Size(MB) Mem VCPUs Status      Server_Pool
node4                     13313    256       1      Running     SF-HQ
node1                     13313    256       1      Running     SF-HQ
node3                     13313    256       1      Running     SF-HQ
node2                     13313    256       1      Running     SF-HQ
The same command can be executed from the Oracle VM Manager Command Line Interface shell as shown in the next example.
# ovm -u admin -p password shell
Type "help" for a list of commands.
ovm> vm ls
Name                  Size(MB) Mem VCPUs Status      Server_Pool
node4                     13313    256       1      Running     SF-HQ
node1                     13313    256       1      Running     SF-HQ
node3                     13313    256       1      Running     SF-HQ
node2                     13313    256       1      Running     SF-HQ
ovm>
Now that we have checked that status of the guests in our Oracle VM farm we will suspend four “Running” guests named node1, node2, node3, and node4 with a single bulk command. Enter the bulk command from the command line, not the Oracle VM Manager Command Line Interface shell to suspend all four guests as shown in the next example.
# ovm -u admin -p password vm suspend -s serverpool_name -n node1; ovm -u admin -p password vm suspend -s serverpool_name -n node2; ovm -u admin -p password vm suspend -s serverpool_name -n node3; ovm -u admin -p password vm suspend -s serverpool_name -n node4
Suspending.
Suspending.
Suspending.
Suspending.
#
The above example shows four separate “vm suspend” commands separated by a semi-colon. You would replace the password, serverpool_name and hostnames with yours to use this bulk command example in your environment.
 
Tip: The help message for “vm suspend” can be displayed by typing “ovm -u admin -p password help vm suspend” or from the shell by typing “help vm suspend”.
 
Let’s validate that the status of the four virtual machines has changed, from “Running” to “Suspended”, by typing “ovm -u admin -p password vm ls” from the server console, as shown in the next example.
# ovm -u admin -p password vm ls
Name        Size(MB) Mem VCPUs Status      Server_Pool
node4            13313    256 1     Suspended   SF-HQ
node1            13313    256 1     Suspended   SF-HQ
node3            13313    256 1     Suspended   SF-HQ
node2            13313    256 1     Suspended   SF-HQ
The above “vm ls” example validated that our “vm suspend” bulk command was successfully completed.
 
Next we will review how to create a vmsuspend batch script. If you would like to test the vmsuspend batch script, you will need to resume your suspended guest. We will cover how to resume your guests in great detail in a couple of paragraphs. If you need to resume your guests to test our next example vmsuspend batch script, please run the following bulk command from the server console.
# ovm -u admin -p password vm resume -s serverpool_name -n node1; ovm -u admin -p password vm resume -s serverpool_name -n node2; ovm -u admin -p password vm resume -s serverpool_name -n node3; ovm -u admin -p password vm resume -s serverpool_name -n node4
Resuming.
Resuming.
Resuming.
Resuming.
#
The same “vm suspend” bulk command could be run as a batch script. The commands in an Oracle VM Manager Command Line Interface batch script are executed in sequence, identical to how sqlplus runs a sql script. There is no error handling with Oracle VM Manager Command Line Interface batch scripts which means when the previous command finishes, regardless of success or failure, the next command will run.
 
The first step to create an Oracle VM Manager Command Line Interface batch script is to create a file. Let’s call the example file vmsuspend. Save the example commands shown below in the vmsuspend file.
 
vm suspend -s serverpool_name -n node1;
vm suspend -s serverpool_name -n node2;
vm suspend -s serverpool_name -n node3;
vm suspend -s serverpool_name -n node4;
 
Now that we have created the file vmsuspend, we can run the vmsuspend file as a batch script in one of two ways; this assumes that the vmsuspend file is located in the current working directory, i.e. /home/user/vmsuspend. You can run the batch script from the server console or from the Oracle VM Manager Command Line Interface shell.
 
The next example shows how to run our example vmsuspend batch script from the server console. 
# ovm shell -s vmsuspend
Login: admin
Password:
Suspending.
Suspending.
Suspending.
Suspending.
#
The above example runs our batch script from the servers console using the “-s” or script option. As shown in the example, it is necessary to authenticate into the shell to run the vmsuspend batch script. Once the script completes you are dropped back to the server console.
 
Our other option to run the vmsuspend batch script is from the Oracle VM Manager Command Line Interface shell. The next example shows how to run the vmsuspend batch script from the Oracle VM Manager Command Line Interface shell. The example assumes that the vmsuspend file is located in the current working directory, i.e. /home/user/vmsuspend.
# ovm -u admin -p password shell
ovm> @vmsuspend
Suspending.
Suspending.
Suspending.
Suspending.
ovm>
The above example runs our batch script from the Oracle VM Manager Command Line Interface shell. Once the script completes, you are dropped back to the Oracle VM Manager Command Line Interface shell prompt.
 
Let’s validate the status of the four virtual machines by typing “vm ls” from the Oracle VM Manager Command Line Interface shell as shown on the next example.
# ovm> vm ls
Name        Size(MB) Mem VCPUs Status      Server_Pool
node4            13313    256 1     Suspended   SF-HQ
node1            13313    256 1     Suspended   SF-HQ
node3            13313    256 1     Suspended   SF-HQ
node2            13313    256 1     Suspended   SF-HQ
Typing “vm ls” from the Oracle VM Manager Command Line Interface shell validated that our previous vmsuspend batch script did successfully run and suspend all four of the guests. You can also list the status of your virtual machines from the server console, as shown in the next example.
# ovm -u admin -p password vm ls
Name        Size(MB) Mem VCPUs Status      Server_Pool
node4            13313    256 1     Suspended   SF-HQ
node1            13313    256 1     Suspended   SF-HQ
node3            13313    256 1     Suspended   SF-HQ
node2            13313    256 1     Suspended   SF-HQ
Now that we have reviewed running a “vm suspend” bulk command and a vmsuspend batch script along with “vm ls”, let’s examine how to resume our guests. First we will review a “vm resume” bulk command, followed with a vmresume batch script.
 
Next, we will resume four “Suspended” guests named node1, node2, node3, and node4 with a single bulk command. Enter the bulk command from the command line, not the Oracle VM Manager Command Line Interface shell, to resume all four guests as shown in the next example.
# ovm -u admin -p password vm resume -s serverpool_name -n node1; ovm -u admin -p password vm resume -s serverpool_name -n node2; ovm -u admin -p password vm resume -s serverpool_name -n node3; ovm -u admin -p password vm resume -s serverpool_name -n node4
Resuming.
Resuming.
Resuming.
Resuming.
#
You can validate the status of the four virtual machines by typing “ovm -u admin -p password vm ls” from the server console or “vm ls” from the Oracle VM Manager Command Line Interface shell.
 
The same “vm resume” bulk command could be run as a batch script. As discussed in the “vm suspend” section the commands in an Oracle VM Manager Command Line Interface batch script are executed in sequence, identical to how sqlplus runs a sql script. There is no error handling with Oracle VM Manager Command Line Interface batch scripts which means when the previous command finishes, regardless of success or fail, the next command will run.
 
The first step to create our example “vm resume” Oracle VM Manager Command Line Interface batch script, is to create a file. Let’s call the example file vmresume. Save the example commands shown below in the vmsuspend file.
 
vm resume -s serverpool_name -n node1;
vm resume -s serverpool_name -n node2;
vm resume -s serverpool_name -n node3;
vm resume -s serverpool_name -n node4;
 
Now that we have created the file vmresume, we can run the vmreseume file as a batch script in one of two ways; this assumes that the vmreseume file is located in the current working directory, i.e. /home/user/vmresume. You can run the batch script from the server console or from the Oracle VM Manager Command Line Interface shell.
 
The next example shows how to run our example vmresume batch script from the server console. 
# ovm shell -s vmresume
Login: admin
Password:
Resuming.
Resuming.
Resuming.
Resuming.
#
The above example runs our batch script from the servers console using the “-s” or script option. As shown in the example it is necessary to authenticate into the shell to run the vmsuspend batch script. Once the script completes, you are dropped back to the server console.
 
Our other option to run the vmresume batch script is from the Oracle VM Manager Command Line Interface shell. The next example shows how to run the vmresume batch script from the Oracle VM Manager Command Line Interface shell. The example assumes that the vmresume file is located in the current working directory, i.e. /home/user/vmresume.
# ovm -u admin -p password shell
ovm> @vmresume
Resuming.
Resuming.
Resuming.
Resuming.
ovm>
The above example runs our batch script from the Oracle VM Manager Command Line Interface shell. Once the script completes, you are dropped back to the Oracle VM Manager Command Line Interface shell prompt.
 
You can validate the status of the four virtual machines by typing “ovm -u admin -p password vm ls” from the console or “vm ls” from the Oracle VM Manager Command Line Interface shell.
 
We have just completed our review of the “vm suspend” and “vm resume” bulk command and batch scripting. The next example expands from our previous “vm suspend” and “vm resume” with a detailed use case called Guest Backup. The Guest Backup use case will use a batch script that suspends four guests, pauses for 120 seconds and then resumes the guests to accommodate an Oracle VM repository scheduled backup job.
 
Our first example use case “Guest Backup”, builds upon what we learned in the previous section with regards to the vm suspend and vm resume examples. The use case shows us how to create a batch script to suspend four guests, pause for 120 seconds and then resume the guests to accommodate a scheduled snapshots/cloning of an Oracle VM extended repository.
 
There are numerous strategies to back up Oracle VM guests. For example, you can use the same agent based backup solution you have always used for your physical machines or you could leverage the snapshots/cloning functionality from your storage solution. Our goal, with the Guest Backup use case, is to provide an Oracle VM Manager Command Line Interface solution to work with the snapshots/cloning functionality from your existing storage.
 
To capture a clean snapshot or backup of a running guest, the guest should be in the suspended state when the snapshot or backup job is executed. When a guest is suspended, the status of the guest operating system is written to disk and removed from system memory. Conversely, when a guest operating system is paused, the system state continues to reside in memory. For the Guest Backup use case we will use the “vm suspend” and “vm resume” commands to ensure that the status of the guest operating system is written to disk and removed from system memory for the duration of the snapshot or backup job.
 
Prerequisites:
  • A storage solution that supports snapshots or cloning.
  • Our example batch script named vmbackup will be scheduled to run each night at 3:00 AM as a cron job.
  • The vmbackup job will run 2 minutes before the scheduled snapshot or clone job.
  • The target guests are in the Running state.
 
List 3 shows the work flow to execute the Guest Backup use case.
  1. Create the vmbackup batch script
  2. Test the vmbackup batch script
  3. Automate the vmbackup batch script with cron.
 
1- The first step is to create an Oracle VM Manager Command Line Interface batch script on the machine hosting the Oracle VM Manager Command Line Interface. Let’s create a file named vmbackup. Save the example commands shown below in the vmbackup file.
 
vm suspend -s serverpool_name -n node1;
vm suspend -s serverpool_name -n node2;
vm suspend -s serverpool_name -n node3;
vm suspend -s serverpool_name -n node4;
sleep 120;
vm resume -s serverpool_name -n node1;
vm resume -s serverpool_name -n node2;
vm resume -s serverpool_name -n node3;
vm resume -s serverpool_name -n node4;
 
2- Next we will test the example vmbackup batch script from the server console, as shown in the example. 
# ovm -u admin -p password shell -s vmbackup
Suspending.
Suspending.
Suspending.
Suspending.
Sleeping for 120 seconds
Resuming.
Resuming.
Resuming.
Resuming.
#
 3- The final step is to automate the vmbackup batch script to run at 3:00 AM every day with cron, as shown in the example.
# crontab –e
* 3 * * * ovm -u admin -p password shell -s vmbackup
:wq!
#
We have just completed our first use case that showed us how to create a batch script to suspend four guests, pause for 120 seconds, and then resume the guests to accommodate a scheduled snapshot or backup job of an Oracle VM extended repository.
 
The next example batch script shows how to create a server pool.
vm ls;
svrp ls;
svrp new -H ovstest19.cn.test.com --serverpool_name=ovstest19 -a -A oracle -U root -P password -L BJ -D "ovstest19 serverpool";
use -s ovstest19;
svrp info;
sleep 10;
svrp status;
svr ls;
 
This section will provide an example of a more advanced method of programming with the Oracle VM Manager Command Line Interface commands.
 
You can program Oracle VM Manager Command Line Interface commands to determine whether a command is successfully executed or not. You’re also able to get the return result of commands in a programming friendly way.
 
The following example script will a) Create a serverpool b) Register all the discoverable ISOs c) Create a hvm guest by one of the ISOs and d) Check the status of the guest created, if the status is "Running", then power off the guest.
from ovmcli.Ovm import Ovm
from ovmcli.errorcode import *
import time
 
ovm = Ovm(username='admin', password='oracle')
_ = ovm.runcmd
 
serverpool_name = "ovstest19"
vm_name = "hvmbyiso1"
server_ip = "ovstest19.cn.oracle.com"
# Delete a serverpool
if OVM_OK == _("svrp del -s %s --force" % serverpool_name):
    print "OK serverpool_del"
 
# Create a serverpool
cmd = 'svrp new -H %s --serverpool_name=%s -a -A oracle -U root -P oracle -L BJ ' % (server_ip, serverpool_name)
if OVM_OK == _(cmd):
    print "OK serverpool_create"
 
# Discover and Register ISOs
discoverable_isos = _("iso disc -s %s" % serverpool_name)
for iso in discoverable_isos:
    cmd = "iso reg -s %s -g el51 -l %s" % (serverpool_name, iso)
    if OVM_OK == _(cmd):
        print "OK iso reg %s" % iso
 
isos = _("iso ls -s %s" % serverpool_name)
 
iso = isos[0][1]
 
# Create a VM
cmd = 'vm new --method=iso -x -s %s -n %s -c 1 -i %s -o Other -y 512 -d 1024' % (serverpool_name, vm_name, iso)
if OVM_OK == _(cmd):
    print "OK vm new"
 
 
while 1:
    cmd = "vm status -s %s -n %s" % (serverpool_name, vm_name)
    status = _(cmd)
    if type(status) == type([]):
        vm_status = status[0]
        if vm_status != 'Running':
            print "vm_status:" + vm_status
            print "sleep 10s"
            time.sleep(10)
        else:
            print vm_status
            cmd = 'vm poweroff -s %s -n %s' % (serverpool_name, vm_name)
            if OVM_OK == _(cmd):
                print "OK poweroff"
            break

 

view counter