2.8 Sample Scripts

There are a number of shell scripts provided with Oracle VM to help you use the CLI. If a password is required for any of these scripts, you are prompted at the command line to enter it. The shell scripts use key-based authentication, which is available after the first log in to the CLI.

These scripts are located in:

/u01/app/oracle/ovm-manager-3/ovm_cli/scripts

Table 2.2 Sample scripts

Script Name

Purpose

ackAllEvents

A shell script that acknowledges all events that a user can acknowledge. This script does not acknowledge system events.

This script uses localhost as the default host. If you run this script from another host, you can specify the Oracle VM Manager location using the syntax:

ackAllEvents -l user@host

inventory

A shell script that displays an inventory of all objects managed by Oracle VM Manager.


There are a also a set of shell scripts provided to get you started scripting in the CLI. These scripts are located in:

/u01/app/oracle/ovm-manager-3/ovm_cli/scripts/createdeletescripts

To use any of these scripts, you should first overwrite the default values in the associated *.properties file with values that match those of your environment. Each parameter within the associated properties file is commented to provide guidelines on the information that must be provided within these files. Additional information on how to run the scripts are contained as comments at the start of each script.

Table 2.3 Sample create/delete scripts

Script Name

Purpose

create-fc-based-VM.sh

A shell script that sets up a complete Oracle VM environment, including storage, server pool, networking, virtual machine resources and a virtual machine, using fibre channel-based storage.

To use this script, edit the fc-based-VM.properties file in the same directory and change the parameters to suit your environment.

delete-fc-based-VM.sh

A shell script that deletes the set up created using the create-fc-based-VM.sh script.

To use this script, edit the fc-based-VM.properties file in the same directory and change the parameters to suit your environment.

create-iscsi-based-VM.sh

A shell script that sets up a complete Oracle VM environment, including storage, server pool, networking, virtual machine resources and a virtual machine, using ISCSI-based storage.

This script uses a fibre channel LUN for the server pool's clustered file system. The Oracle VM Server must have access to an unmanaged fibre channel storage array. This script creates a storage array using the Oracle NetApp Filer plug-in.

To use this script, edit the iscsi-based-VM.properties file in the same directory and change the parameters to suit your environment.

delete-iscsi-based-VM.sh

A shell script that deletes the set up created using the create-iscsi-based-VM.sh script.

To use this script, edit the iscsi-based-VM.properties file in the same directory and change the parameters to suit your environment.

create-nfs-based-VM.sh

A shell script that sets up a complete Oracle VM environment, including storage, server pool, networking, virtual machine resources and a virtual machine, using NFS-based storage.

To use this script, edit the nfs-based-VM.properties file in the same directory and change the parameters to suit your environment.

delete-nfs-based-VM.sh

A shell script that deletes the set up created using the create-nfs-based-VM.sh script.

To use this script, edit the nfs-based-VM.properties file in the same directory and change the parameters to suit your environment.

common.sh

A shell script that contains the common functions used by other scripts in this directory. Do not run this script directly, instead call it from other scripts. You can see a list of the common functions in this script in Table 2.4, “Sample scripts common functions”.


To customize any of these scripts for your environment, copy them to a directory outside of the Oracle VM Manager installation tree, edit the script with a text editor and change the variables to suit your environment, or extend further to provide additional functionality.

When you run any of these scripts, the output is displayed to the screen; spool it to a file or other process or script as required.

The common.sh file provides some common functions used by the sample scripts. The functions available in this script are listed in Table 2.4, “Sample scripts common functions”.

Table 2.4 Sample scripts common functions

FunctionDescription

getPass

Prompts for a password. You may want to prompt for an Oracle VM Server, or storage server pasword. When prompted, the input is not echoed on screen. The password can then be securely used with other CLI commands, such as discoverServer.

No password is required for authentication with Oracle VM Manager as this uses certificate authentication.

validateCLI command

Script continues if the CLI command returns success, and terminates if the command returns a failure.

runCLI command

Script continues, regardless of the outcome of the CLI command.

deleteRepo repository

Deletes a storage repository and all of its contents.

deleteServerpool serverpool

Remove all Oracle VM Servers from a server pool, and deletes the server pool.

addVnicFromClonedVmToNetwork vm network

Use this command when cloning a virtual machine that includes a VNIC. This command associates the VNIC with a network, so enables the virtual machine to be started.


Performance Monitoring, Script Logging and Debugging

Optional timer functionality is built into the validateCLI and runCLI functions, which are used by all of the sample scripts to initiate connections to the CLI. This allows you to gather useful performance data, when running any of the sample scripts, by accurately timing and logging how long each of the commands within the scripts take to run. This tool also provides a useful log of every single command run for any of the scripts, providing debugging information that can be used to determine script failure or to understand the sequence of commands being issued by the script.

By default, the timer functionality is disabled, however it can be enabled by using the command line switch: -tfilename.txt. For instance:

./create-nfs-based-VM.sh -t report.txt

Output generated within the specified file for a script where the timer functionality has been enabled may look similar to the following:

TIME(Seconds) Command
18.621        discoverServer ipAddress='10.172.76.80' password=******** takeOwnership=yes
5.587         create serverpool virtualIP='0.0.0.0' clusterEnable=no name='MyServerPool' \ 
              description='this is nfs pool MyServerPool'
...

It is worth noting that output logged for the timer functionality is appended to the file specified. This means that if you re-use the same filename, the file is not overwritten with the new data. Instead, the output is simply appended to the bottom of the file.

If no filename is specified for the timer switch, the output is dumped to STDOUT.