Exalogic Virtual Tea Break Snippets – Simplified Exalogic IaaS Cli

In previous blogs I have built and documented a number of extensions to the standard Exalogic IaaS Cli that either simplify the Cli usage or provide additional functionality. Following feedback from the various user I have enhanced and amalgamated a number of my scripts into a new single “SimpleExCli.sh”. In addition the SimpleExCli.sh script contains a number of new options for creating and managing vServers within your Exalogic environment.

The aim of this blog entry is to introduce the new script and document the commands available providing a starting point for script usage. I will produce a number of additional short targeted tutorials that will work through the individual commands in more detail.

This script is not part of the Exalogic product and is provided as an example only and as such support tickets can not be opened against the script.

Replaced Blog Entries

The scripts described in the following blog entries have been amalgamated into the SimpleExaCli.sh.

SimpleExaCli.sh

Installing and Running

Because this is a wrapper around the standard Exalogic IaaS Cli to use the SimpleExaCli.sh script it need to be installed on a machine that already has the IaaS rpms installed. If they have not been installed then the following rpms will need to be installed.

  • rpm -i orcl-sysman-iaas-api-12.1.0-1629.noarch.rpm
  • rpm -i orcl-sysman-iaas-cli-12.1.0-1629.noarch.rpm
rpm -i orcl-sysman-iaas-api-12.1.0-1629.noarch.rpm
rpm -i orcl-sysman-iaas-cli-12.1.0-1629.noarch.rpm


Once the IaaS rpms have been installed the SimpleExaCli.sh can be executed using the following, general, format.

SimpleExaCli.sh <Command> <Parameters>

The Command options available and their associated Parameters will be discussed below.

Commands

–status-vservers

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • -v <vServer Name>

List the status all the vServers in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the vServers. To successfully achieve this the mandatory Username and Password must have access to all the accounts.

–start-vservers

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • -v <vServer Name>

Start all or the named -v vServer(s) in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC starting the vServers. To successfully achieve this the mandatory Username and Password must have access to all the accounts.

–reboot-vservers

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • -v <vServer Name>

Reboot all or the named -v vServer(s) in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC starting the vServers. To successfully achieve this the mandatory Username and Password must have access to all the accounts.

–stop-vservers

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • -v <vServer Name>

Stop all or the named -v vServer(s) in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC starting the vServers. To successfully achieve this the mandatory Username and Password must have access to all the accounts.

–list-vservers

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • –verbose

List all the vServers in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the vServers. To successfully achieve this the mandatory Username and Password must have access to all the accounts If –verbose is also specified the all available vServer information will be listed.

–list-vnets

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • –verbose

List all the vNets in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the vNets. To successfully achieve this the mandatory Username and Password must have access to all the accounts If –verbose is also specified the all available vNet information will be listed.

–list-distgroups

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • –verbose

List all the Distribution Groups in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the Distribution Groups. To successfully achieve this the mandatory Username and Password must have access to all the accounts." If –verbose is also specified the all available Distribution Group information will be listed.

–list-volumes

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • –verbose

List all the Volumes in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the Volumes. To successfully achieve this the mandatory Username and Password must have access to all the accounts If –verbose is also specified the all available Volumes information will be listed.

–list-templates

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
  • Optional
    • -a <Account Name>
    • –verbose

List all the Templates in the specified Account. If no Account is specified then it will loop through all Accounts within the vDC listing the Templates. To successfully achieve this the mandatory Username and Password must have access to all the accounts. If –verbose is also specified the all available Template information will be listed.

–create-vserver

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
    • -a <Account Name>
    • -v <vServer Name>
    • -vs-type <VServer Type Name>
    • -vs-template <VServer Template Name>
    • -vs-networks <Network Names>
    • -vs-ips <Network IPs>
  • Optional
    • -vs-dg <Distribution Group Name>
    • -vs-desc <Description>

Creates a single vServer based on the information provided in the parameters. All parameters are name based and the ids will be found based on the provided name.

–delete-vserver

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
    • -a <Account Name>
    • -v <vServer Name>

Deletes a single vServer based on the information provided in the parameters. All parameters are name based and the ids will be found based on the provided name.

–stop-vserver

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
    • -a <Account Name>
    • -v <vServer Name>

Stops a single vServer based on the information provided in the parameters. All parameters are name based and the ids will be found based on the provided name.

–start-vserver

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
    • -a <Account Name>
    • -v <vServer Name>

Starts a single vServer based on the information provided in the parameters. All parameters are name based and the ids will be found based on the provided name.

–restart-vserver

Parameters

  • Required
    • -u <Account User>
    • -p <Account Password>
    • -a <Account Name>
    • -v <vServer Name>

Restarts a single vServer based on the information provided in the parameters. All parameters are name based and the ids will be found based on the provided name.

–create-assets

Parameters

  • Required
    • -f <Asset Definition File>
  • Optional
    • -remove-ssh-key

Reads the specified Asset file and creates all the assets defined within it. If multiple projects are defined these are worked through. The file is processed sequentially and therefore must contain action in an appropriate sequence. Within the Asset file each line is a specific entry and has the following structure:

Account:Action|Asset Type|Parameters
Action Asset Type Parameters
Connect  
  1. Username
  2. Password
Upload ServerTemplate
  1. Template Name
  2. URL to the template location.
Create VirtualNetwork
  1. Network Name
  2. Size
Create DistributionGroup
  1. Distribution Group Name

When creating Distribution Groups from the command line they will have a size of 50,000.

Create vServer
  1. vServer Name
  2. vServer Type Name
  3. Template Name
  4. Comma separated list of network names which the vServer will connect to.
  5. Comma separated list of IPs for the specified networks. If the IP is to be assigned automatically the a "*" should be entered.
  6. Distribution Group [Optional]
  7. Description [Optional]
Create Volume
  1. Volume Name
  2. Volume Size
Attach Volume
  1. vServer Name
  2. Comma separated list of volume names
Disconnect    
Production:Connect|clouduser|welcome1

Production:Upload|ServerTemplate|Navstar40GBRootTemplate|http://172.17.0.9/shares/export/common/images/ah-templates/el_40gb_root_linux_vm_template_2.0.4.0.0_64.tgz

Production:Create|VirtualNetwork|VN001|96

Production:Create|DistributionGroup|DG001

Production:Create|vServer|VS006|VSTProduction|Navstar40GBRootTemplate||EoIB1-client-access,IPoIB-vserver-shared-storage,VN001|10.242.96.69,172.17.0.34,*|DG001
Production:Create|vServer|VS003|VSTProduction|Navstar40GBRootTemplate|vServer Description|EoIB1-client-access,IPoIB-vserver-shared-storage|10.242.96.75,*

Production:Create|Volume|VS006|5

Production:Attach|Volume|VS006|VS006

Production:Disconnect
–create-template

Parameters

  • Required
    • -v <vServer Name>
  • Optional
    • -lvm <Volume Group> <Logical Volume>
    • -r <Repository Directory>
    • -w <Working Directory>
    • -d <Destination Directory>

Takes the specified vServer name and identifies the associated img files which will then be copied to a working directory before being opened and edited thus converting them to a template. If multiple images exist (because vServers uses volumes) it will be converted to a single template with multiple img files and hence larger size. This command must be executed on a physical compute node preferably cn01. The Working and Destination directories should be mounted on the ZFS and it is assumed that these will be below /u01/common/images.

–capture-vserver

Parameters

  • Required
    • -v <vServer Name>
  • Optional
    • -lvm <Volume Group> <Logical Volume>
    • -r <Repository Directory>
    • -w <Working Directory>
    • -d <Destination Directory>
    • -keep-resolv
    • -keep-hosts
    • -vs-dg <Distribution Group Name>
    • -vs-type <vServer Type Name>

Access the Exalogic EMOC system and retrieve the information about the specified vServer. This information is recorded in an Asset file that can be used with –create-assets. The script also takes the existing vServer image files and converts them into a template adding an upload to the Asset file. If the ikeep-resolv flag is passed on the command line the resolv.conf within the vServer will be kept otherwise it will be re-initialised. Specifying the -keep-hosts flag indicates the hosts file within the vServer must not be initialised and hence kept as is. Because the current vServer Distribution Group is not accessible through the IaaS Cli the required Distribution Group can be passed on the command line and it will be added to the Asset file. If the capture command is being used so that a vServer can have it’s memory and/or CPU reconfigured then the -vs-type parameter will allow the user to specify a new vServer Type that will be written to the Asset file rather than the one currently associated with the vServer.

 

download

#!/bin/bash

################################################################################
#
# 	Exalogic Virtual (Linux x86-64) Simplified CLI
#  HEADER START
# 
#  THIS SCRIPT IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY KIND, 
#  EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT 
#  THE COVERED SCRIPT IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR 
#  PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE 
#  OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE 
#  DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER 
#  CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION.
#  NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS 
#  DISCLAIMER.
#
#  When distributing this Code, include this HEADER in each file.
#  If applicable, add the following below this this HEADER, with the fields
#  enclosed by brackets "[]" replaced with your own identifying information:
#       Portions Copyright [yyyy] [name of copyright owner]
# 
#  HEADER END
# 
# 
#       Copyright 2013 Andrew Hopkinson, Oracle Corporation UK Ltd.
#
################################################################################

export OCCLI=/opt/sun/occli/bin
export IAAS_HOME=/opt/oracle/iaas/cli
export IAAS_BASE_URL=https://localhost
export BASE_IAAS_ACCESS_KEY_FILE=iaas_access.key
export BASE_KEY_NAME=cli.asset.create
export BASE_KEY_FILE=iaas_access.pub
export RUN_DATE=`date +"%Y%m%d-%H%M"`"."$$
#export RUN_DATE=$$
#CloudUser used to create vServers &amp; Volumes
export IAAS_USER=CloudUser
export IAAS_PASSWORD_FILE=.iaas.pwd.$$
#export ASSET_FILE=CreateAssets.$$.in

function testCli() {
	$IAAS_HOME/bin/akm-describe-accounts --sep "|"
}

function getAccounts() {
	accountsArray=( $($IAAS_HOME/bin/akm-describe-accounts --sep "|" | sed 's/ /_/g') )
}

function getVServers() {
	vserversArray=( $($IAAS_HOME/bin/iaas-describe-vservers --sep "|" | sed 's/ /_/g') )
}

function getNetworks() {
	vnetsArray=( $($IAAS_HOME/bin/iaas-describe-vnets --sep "|" | sed 's/ /_/g') )
}

function getDistributionGroups() {
	distGrpsArray=( $($IAAS_HOME/bin/iaas-describe-distribution-groups --sep "|" | sed 's/ /_/g') )
}

function getTemplates() {
	templatesArray=( $($IAAS_HOME/bin/iaas-describe-server-templates --sep "|" | sed 's/ /_/g') )
}

function getVolumes() {
	volumesArray=( $($IAAS_HOME/bin/iaas-describe-volumes --sep "|" | sed 's/ /_/g') )
}

function getVSTypes() {
	vsTypesArray=( $($IAAS_HOME/bin/iaas-describe-vserver-types --sep "|" | sed 's/ /_/g') )
}

function connectToAccount() {
	# Set run specific key information
	export IAAS_ACCESS_KEY_FILE=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_IAAS_ACCESS_KEY_FILE
	export KEY_NAME=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_KEY_NAME
	export KEY_FILE=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_KEY_FILE
	#echo "IAAS_ACCESS_KEY_FILE=$IAAS_ACCESS_KEY_FILE"
	#echo "KEY_NAME=$KEY_NAME"
	#echo "KEY_FILE=$KEY_FILE"
	#echo "Found Account $line"
	AK=`$IAAS_HOME/bin/akm-create-access-key --account $ACCOUNT_ID --access-key-file $IAAS_ACCESS_KEY_FILE`
	KEYPAIR=`$IAAS_HOME/bin/iaas-create-key-pair --key-name $KEY_NAME --key-file $KEY_FILE`
	#echo "Connected to $ACCOUNT_NAME"
}

function disconnectFromAccount() {
        $IAAS_HOME/bin/iaas-delete-key-pair --key-name $KEY_NAME --access-key-file $IAAS_ACCESS_KEY_FILE
        $IAAS_HOME/bin/akm-delete-access-key $AK
        if  "$KEEP_PUB_KEY" == "" 
        then
            rm -f $KEY_FILE
        fi
        rm -f $IAAS_ACCESS_KEY_FILE
}

#############################################################
##
## stopVServer
## ===========
##
## Find and stop a vServer.
##
#############################################################

function stopVServer() {
#	echo "Stopping vServer $VSERVER_NAME"
	getVServers
	getVServerId
	echo "Stopping vServer $VSERVER_NAME $VSERVER_ID"
	$IAAS_HOME/bin/iaas-stop-vservers --vserver-ids $VSERVER_ID --force
	pauseUntilVServerShutdown
}

#############################################################
##
## startVServer
## ============
##
## Find and stop a vServer.
##
#############################################################

function startVServer() {
#	echo "Starting vServer $VSERVER_NAME"
	getVServers
	getVServerId
	echo "Starting vServer $VSERVER_NAME $VSERVER_ID"
	$IAAS_HOME/bin/iaas-start-vservers --vserver-ids $VSERVER_ID
	pauseUntilVServerRunning
}

#############################################################
##
## deleteVServer
## =============
##
## Find and delete a vServer.
##
#############################################################

function deleteVServer() {
#	echo "Deleting vServer $VSERVER_NAME"
	getVServers
	getVServerId
	echo "Deleting vServer $VSERVER_NAME $VSERVER_ID"
	$IAAS_HOME/bin/iaas-terminate-vservers --force --vserver-ids $VSERVER_ID
}

#############################################################
##
## stopVServers
## ============
##
## Stop one or more vServers running within the currently
## connected Account. If a specific vServer Name is passed in
## $VSERVER as specified on the command line using -v then 
## this will be the one stopped. If no VSERVER is specified
## then all vServers in the Account will be stopped.
##
#############################################################

function stopVServers() {
	getVServers
	VSERVER_IDS=""
	VSERVER_NAMES=""
	for vserver in "${vserversArray[@]}"
	do
		VSERVER_ID=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_NAME=${vserver%%|*}
		if | "$VSERVER" == "$VSERVER_NAME" 
		then
			if  "$VSERVER_IDS" == "" 
			then
				VSERVER_IDS=$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAME
			else
				VSERVER_IDS=$VSERVER_IDS","$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAMES","$VSERVER_NAME
			fi
		fi
	done
	if  "$VSERVER_IDS" != "" 
	then
		echo "Stopping vServer(s) [$VSERVER_NAMES] [$VSERVER_IDS]"
		$IAAS_HOME/bin/iaas-stop-vservers --vserver-ids $VSERVER_IDS --force
	else
		echo "No vServers to stop"
	fi
}

#############################################################
##
## startVServers
## =============
##
## Start one or more vServers stopped within the currently
## connected Account. If a specific vServer Name is passed in
## $VSERVER as specified on the command line using -v then 
## this will be the one started. If no VSERVER is specified
## then all vServers in the Account will be started.
##
#############################################################

function startVServers() {
	getVServers
	VSERVER_IDS=""
	VSERVER_NAMES=""
	for vserver in "${vserversArray[@]}"
	do
		VSERVER_ID=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_NAME=${vserver%%|*}
		if | "$VSERVER" == "$VSERVER_NAME" 
		then
			if  "$VSERVER_IDS" == "" 
			then
				VSERVER_IDS=$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAME
			else
				VSERVER_IDS=$VSERVER_IDS","$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAMES","$VSERVER_NAME
			fi
		fi
	done
	if  "$VSERVER_IDS" != "" 
	then
		echo "Starting vServer(s) [$VSERVER_NAMES] [$VSERVER_IDS]"
		$IAAS_HOME/bin/iaas-start-vservers --vserver-ids $VSERVER_IDS
	else
		echo "No vServers to start"
	fi
}

#############################################################
##
## rebootVServers
## ==============
##
## Reboot one or more vServers stopped within the currently
## connected Account. If a specific vServer Name is passed in
## $VSERVER as specified on the command line using -v then 
## this will be the one started. If no VSERVER is specified
## then all vServers in the Account will be started.
##
#############################################################

function rebootVServers() {
	getVServers
	VSERVER_IDS=""
	VSERVER_NAMES=""
	for vserver in "${vserversArray[@]}"
	do
		VSERVER_ID=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_NAME=${vserver%%|*}
		if | "$VSERVER" == "$VSERVER_NAME" 
		then
			if  "$VSERVER_IDS" == "" 
			then
				VSERVER_IDS=$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAME
			else
				VSERVER_IDS=$VSERVER_IDS","$VSERVER_ID
				VSERVER_NAMES=$VSERVER_NAMES","$VSERVER_NAME
			fi
		fi
	done
	if  "$VSERVER_IDS" != "" 
	then
		echo "Rebooting vServer(s) [$VSERVER_NAMES] [$VSERVER_IDS]"
		$IAAS_HOME/bin/iaas-reboot-vservers --vserver-ids $VSERVER_IDS
	else
		echo "No vServers to reboot"
	fi
}

#############################################################
##
## listVServers
## ============
##
## List the vServers running on the specified Account is 
## the verbose flag is set then all vServer details will be 
## displayed otherwise simple the Acc and Name.
##
#############################################################

function listVServers() {
    getVServers
    for vserver in "${vserversArray[@]}"
    do
        VSERVER_ID=${vserver%%|*}
        vserver=${vserver#*|}
        VSERVER_NAME=${vserver%%|*}
        vserver=${vserver#*|}
        if | "$VSERVER" == "$VSERVER_NAME" 
        then
            if  "$VERBOSE" == "true" 
            then
                if  "$HRF" == "true" 
                then
                    DESCRIPTION=${vserver%%|*}
                    vserver=${vserver#*|}
                    STATE=${vserver%%|*}
                    vserver=${vserver#*|}
                    NETWORK_IDS=${vserver%%|*}
                    vserver=${vserver#*|}
                    NETWORK_IPS=${vserver%%|*}
                    vserver=${vserver#*|}
                    TEMPLATE_ID=${vserver%%|*}
                    vserver=${vserver#*|}
                    SSH_KEY=${vserver%%|*}
                    vserver=${vserver#*|}
                    VSTYPE_ID=${vserver%%|*}
                    vserver=${vserver#*|}
                    getNetworks
                    getTemplates
                    getVSTypes
                    # Get VServer Type Name
                    getVSTypeName
                    # Get Template Type Name
                    getTemplateName
                    echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_ID"
                    echo "     Name        : $VSERVER_NAME"
                    echo "     Description : "$(echo $DESCRIPTION | sed 's/_/ /g')
                    echo "     State       : $STATE"
                    for NETWORK_ID in ${NETWORK_IDS//,/ }
                    do
                        NETWORK_IP=${NETWORK_IPS%%,*}
                        NETWORK_IPS=${NETWORK_IPS#*,}
                        getNetworkName
                        echo "     Network     : $NETWORK_NAME ($NETWORK_IP) [$NETWORK_ID]"
                    done
                    echo "     Template    : $TEMPLATE_NAME [$TEMPLATE_ID]"
                    echo "     Server Type : $VSTYPE_NAME [$VSTYPE_ID]"
                else
                    echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_ID|"$(echo $vserver | sed 's/_/ /g')
                fi
            else
                echo "$ACCOUNT_NAME|$VSERVER_NAME"
            fi
        fi
    done
}

#############################################################
##
## listVServerStatus
## =================
##
## List the Status of the vServers within an Account.
##
#############################################################

function listVServerStatus() {
	getVServers
	for vserver in "${vserversArray[@]}"
	do
		VSERVER_ID=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_NAME=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_DESC=${vserver%%|*}
		vserver=${vserver#*|}
		VSERVER_STATUS=${vserver%%|*}
		if | "$VSERVER" == "$VSERVER_NAME" 
		then
			echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_STATUS"
		fi
	done
}

#############################################################
##
## listVNets
## =========
##
## List the Networks within an Account.
##
#############################################################

function listVNets() {
	getNetworks
	for vnet in "${vnetsArray[@]}"
	do
		VNET_ID=${vnet%%|*}
		vnet=${vnet#*|}
		VNET_NAME=${vnet%%|*}
		vnet=${vnet#*|}
		if  "$VERBOSE" == "true" 
		then
			echo "$ACCOUNT_NAME|$VNET_NAME|$VNET_ID|"$(echo $vnet | sed 's/_/ /g')
		else
			VNET_DESC=${vnet%%|*}
			vnet=${vnet#*|}
			VNET_STATUS=${vnet%%|*}
			vnet=${vnet#*|}
			VNET_IP=${vnet%%|*}
			echo "$ACCOUNT_NAME|$VNET_NAME|$VNET_IP"
		fi
	done
}

#############################################################
##
## listDistributionGroups
## ======================
##
## List the Distribution Groups within an Account.
##
#############################################################

function listDistributionGroups() {
	getDistributionGroups
	for distGrp in "${distGrpsArray[@]}"
	do
		DG_ID=${distGrp%%|*}
		distGrp=${distGrp#*|}
		DG_NAME=${distGrp%%|*}
		distGrp=${distGrp#*|}
		if  "$VERBOSE" == "true" 
		then
			echo "$ACCOUNT_NAME|$DG_NAME|$DG_ID|"$(echo $distGrp | sed 's/_/ /g')
		else
			DG_DESC=${distGrp%%|*}
			distGrp=${distGrp#*|}
			DG_STATUS=${distGrp%%|*}
			echo "$ACCOUNT_NAME|$DG_NAME|$VNET_IP"
		fi
	done
}

#############################################################
##
## listTemplates
## =============
##
## List the Templates within an Account.
##
#############################################################

function listTemplates() {
	getTemplates
	for template in "${templatesArray[@]}"
	do
		TEMPLATE_ID=${template%%|*}
		template=${template#*|}
		TEMPLATE_NAME=${template%%|*}
		template=${template#*|}
		if  "$VERBOSE" == "true" 
		then
			echo "$ACCOUNT_NAME|$TEMPLATE_NAME|$TEMPLATE_ID|"$(echo $template | sed 's/_/ /g')
		else
			TEMPLATE_DESC=${template%%|*}
			template=${template#*|}
			TEMPLATE_STATUS=${template%%|*}
			echo "$ACCOUNT_NAME|$TEMPLATE_NAME"
		fi
	done
}

#############################################################
##
## listVolumes
## ===========
##
## List the Volumes within an Account.
##
#############################################################

function listVolumes() {
	getVolumes
	for volume in "${volumesArray[@]}"
	do
		VOLUME_ID=${volume%%|*}
		volume=${volume#*|}
		VOLUME_NAME=${volume%%|*}
		volume=${volume#*|}
		if  "$VERBOSE" == "true" 
		then
			echo "$ACCOUNT_NAME|$VOLUME_NAME|$VOLUME_ID|"$(echo $volume | sed 's/_/ /g')
		else
			VOLUME_DESC=${volume%%|*}
			volume=${volume#*|}
			VOLUME_STATUS=${volume%%|*}
			volume=${volume#*|}
			VOLUME_SIZE=${volume%%|*}
			echo "$ACCOUNT_NAME|$VOLUME_NAME|$VOLUME_SIZE"
		fi
	done
}

#############################################################
##
## getAccountId
## ============
##
## Get the Account id based on the supplied name.
##
#############################################################

function getAccountId() {
echo $accountArray
    for account in "${accountsArray[@]}"
    do
        ACCOUNT_ID=${account%%|*}
        account=${account#*|}
        ACCOUNT_NAME=${account%%|*}
        if  "$ACCOUNT" == "$ACCOUNT_NAME" &amp;&amp; "$ACCOUNT_ID" == ACC-* 
        then
            break
        fi
        ACCOUNT_ID=""
    done
}

#############################################################
##
## getDistributionGroupId
## ======================
##
## Get the Distribution Group id based on the supplied name.
##
#############################################################

function getDistributionGroupId() {
    for line in "${distGrpsArray[@]}"
    do
            DISTGROUP_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            if  "$NAME" == "$DISTGROUP_NAME" 
            then
                    break
            fi
            DISTGROUP_ID=""
    done
}

#############################################################
##
## getIPAddress
## ============
##
## Get a static IP Address for a given network if an * is 
## supplied. If an IP Address is supplied it simple returns
## specified IP.
##
#############################################################

function getIPAddress() {
    echo "Checking IP Address $IP_ADDRESS"
    if  "$IP_ADDRESS" == "*" 
    then
            allocateIPAddress
    fi
    echo "Returning IP Address $IP_ADDRESS"
}

#############################################################
##
## allocateIPAddress
## =================
##
## Allocate a single IP Address from a specified Network.
##
#############################################################

function allocateIPAddress() {
    IP_ADDRESS=`$IAAS_HOME/bin/iaas-allocate-ip-addresses --vnet $NETWORK_ID --num 1`
}
#############################################################
##
## getNetworkId
## ============
##
## Get the Network id based on the supplied name.
##
#############################################################

function getNetworkId() {
    for line in "${vnetsArray[@]}"
    do
            NETWORK_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            if  "$NAME" == "$NETWORK_NAME" 
            then
                    break
            fi
            NETWORK_ID=""
    done
}

#############################################################
##
## getNetworkName
## ==============
##
## Gets the name of a network based on the Id.
##
#############################################################

function getNetworkName() {
    NETWORK_NAME=""
    for line in "${vnetsArray[@]}"
    do
        ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        if  "$ID" == "$NETWORK_ID" 
        then
            NETWORK_NAME=$NAME
            break
        fi
    done
}

#############################################################
##
## getVNetworkState
## ================
##
## Loop through the Networks associated with the Account 
## checking to see if the creation has completed and the 
## network has a status of OK. At this point return.
##
#############################################################

function getVNetworkState() {
    getNetworks
    for line in "${vnetsArray[@]}"
    do
            NETWORK_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            line=${line#*|}
            line=${line#*|}
            NETWORK_STATE=${line%%|*}
            if  "$NETWORK_NAME" == "$NAME" 
            then
                    break;
            fi
    done
}

#############################################################
##
## getTemplateId
## =============
##
## Get the Template id based on the supplied name.
##
#############################################################

function getTemplateId() {
    for line in "${templatesArray[@]}"
    do
            TEMPLATE_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            if  "$TEMPLATE_NAME" == "$NAME" 
            then
                    break
            fi
            TEMPLATE_ID=""
    done
}

#############################################################
##
## getTemplateState
## ================
##
## Loop through the Template associated with the Account 
## checking to see if the upload has completed and the 
## template has a status of OK. At this point return.
##
#############################################################

function getTemplateState() {
    getTemplates
    for line in "${templatesArray[@]}"
    do
        TEMPLATE_ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        line=${line#*|}
        line=${line#*|}
        TEMPLATE_STATE=${line%%|*}
        if  "$TEMPLATE_NAME" == "$NAME" 
        then
                break;
        fi
    done
}

#############################################################
##
## getTemplateName
## ===============
##
## Gets the name of a Template based on the Id.
##
#############################################################

function getTemplateName() {
    TEMPLATE_NAME=""
    for line in "${templatesArray[@]}"
    do
        ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        if  "$ID" == "$TEMPLATE_ID" 
        then
            TEMPLATE_NAME=$NAME
            break
        fi
    done 
}

#############################################################
##
## getVolumeId
## ===========
##
## Get the Volume id based on the supplied name.
##
#############################################################

function getVolumeId() {
    for line in "${volumesArray[@]}"
    do
            VOLUME_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            if  "$NAME" == "$VOLUME_NAME" 
            then
                    break;
            fi
            VOLUME_ID=""
    done 
}

#############################################################
##
## getVServerId
## ============
##
## Get the VServer id based on the supplied name.
##
#############################################################

function getVServerId() {
    for line in "${vserversArray[@]}"
    do
            VSERVER_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            if  "$VSERVER_NAME" == "$NAME" 
            then
                    break;
            fi
            VSERVER_ID=""
    done 
}

#############################################################
##
## getVServerState
## ===============
##
## Get the VServer running state based on the supplied name.
##
#############################################################

function getVServerState() {
    getVServers
    for line in "${vserversArray[@]}"
    do
            VSERVER_ID=${line%%|*}
            line=${line#*|}
            NAME=${line%%|*}
            line=${line#*|}
            DESCRIPTION=${line%%|*}
            line=${line#*|}
            VSERVER_STATE=${line%%|*}
            if  "$VSERVER_NAME" == "$NAME" 
            then
                    break;
            fi
    done 
}

#############################################################
##
## getVSTypeId
## ===========
##
## Get the VServer Type id based on the supplied name.
##
#############################################################

function getVSTypeId() {
    for line in "${vsTypesArray[@]}"
    do
        VSTYPE_ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        if  "$VSTYPE_NAME" == "$NAME" 
        then
            break
        fi
        VSTYPE_ID=""
    done
}

#############################################################
##
## getVSTypeName
## =============
##
## Gets the name of a vServer Type based on the Id.
##
#############################################################

function getVSTypeName() {
    VSTYPE_NAME=""
    for line in "${vsTypesArray[@]}"
    do
        ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        if  "$ID" == "$VSTYPE_ID" 
        then
            VSTYPE_NAME=$NAME
            break
        fi
    done 
}

#############################################################
##
## createDistributionGroup
## =======================
##
## Create a Distribution Group based on the supplied details.
##
#############################################################

function createDistributionGroup() {
    # Create Distribution Group
    echo "About to execute : $IAAS_HOME/bin/iaas-create-distribution-group --name $DISTGROUP_NAME"
    $IAAS_HOME/bin/iaas-create-distribution-group --name $DISTGROUP_NAME
    # Lets pause
    pauseUntilDistributionGroupCreated
}

#############################################################
##
## pauseUntilDistributionGroupCreated
## ==================================
##
## Pause the script until the Distribution Group has been created.
##
#############################################################

function pauseUntilDistributionGroupCreated() {
    getDistributionGroups
    getDistributionGroupId
    while  "$DISTGROUP_ID" == "" 
    do
        # Lets pause
        echo "Just Waiting 30 Seconds......"
        sleep 30
        getDistributionGroups
        getDistributionGroupId
    done
}

#############################################################
##
## createVirtualNetwork
## ====================
##
## Create a Virtual Private Network based on the name 
## supplied.
##
#############################################################

function createVirtualNetwork() {
    # 
    echo "About to execute : $IAAS_HOME/bin/iaas-create-vnet --name $NETWORK_NAME --size $NETWORK_IPS "
    $IAAS_HOME/bin/iaas-create-vnet --name $NETWORK_NAME --size $NETWORK_IPS
  # Lets pause
    pauseUntilVirtualNetworkCreated
}

#############################################################
##
## pauseUntilVirtualNetworkCreated
## ===============================
##
## Pause the script until the Virtual Private Network has
## been created.
##
#############################################################

function pauseUntilVirtualNetworkCreated() {
    echo "Pausing until Virtual Network creation has completed"
    getVNetworkState
    while  "$NETWORK_STATE" != "OK" 
    do
        echo "$NAME $NETWORK_STATE"
        if  "$NETWORK_STATE" != "SCHEDULED" 
        then
                echo "Sleeping......."
                sleep 30
        elif  "$NETWORK_STATE" != "RUNNING" 
        then
                echo "Sleeping......."
                sleep 30
        fi
        getVNetworkState
    done
}

#############################################################
##
## createVolume
## ============
##
## Create a Volume based on the supplied details.
##
#############################################################

function createVolume() {
    # Create Volume
    echo "About to execute : $IAAS_HOME/bin/iaas-create-volume --name $VOLUME_NAME --size $VOLUME_SIZE"
    $IAAS_HOME/bin/iaas-create-volume --name $VOLUME_NAME --size $VOLUME_SIZE
  # Lets pause
  pauseUntilVolumeCreated
}

#############################################################
##
## pauseUntilVolumeCreated
## =======================
##
## Pause the script until the Volume has been created.
##
#############################################################

function pauseUntilVolumeCreated() {
    getVolumes
    getVolumeId
    while  "$VOLUME_ID" == "" 
    do
        # Lets pause
        echo "Just Waiting 30 Seconds......"
        sleep 30
        getVolumes
        getVolumeId
    done
}

#############################################################
##
## createVServer
## =============
##
## Create a vServer based on the supplied details.
##
#############################################################

function createVServer() {
    echo "Creating vServer $VSERVER_NAME"

    # Get Ids associated with names
    getVSTypeId
    getTemplateId
    # Convert Network Names to Ids
    NETWORK_IDS=""
    # Validated IPs
    NETWORK_IPS=""
    # Reset SSH IP Address it will be used to disable SSH Key
    SSH_IP_ADDRESS=""
    while true
    do
            # Get ID and add to list
            NETWORK_NAME=${NETWORK_NAMES%%,*}
            NETWORK_NAMES=${NETWORK_NAMES#*,}
            getNetworkId
            if  "$NETWORK_IDS" != "" 
            then
                    NETWORK_IDS="$NETWORK_IDS,$NETWORK_ID"
            else
                    NETWORK_IDS=$NETWORK_ID
            fi
            # Check IPs
            IP_ADDRESS=${IP_ADDRESSES%%,*}
            IP_ADDRESSES=${IP_ADDRESSES#*,}
            getIPAddress
            if  "$NETWORK_IPS" != "" 
            then
                    NETWORK_IPS="$NETWORK_IPS,$IP_ADDRESS"
            else
                    NETWORK_IPS=$IP_ADDRESS
            fi
            # Set the SSH IP to the first IP address we will assume the server is accessible via this IP
            if  "$SSH_IP_ADDRESS" == "" 
            then
                    SSH_IP_ADDRESS=$IP_ADDRESS
            elif  "$NETWORK_NAME" == "IPoIB-vserver-shared-storage" 
            then
                    # Prefer the IPoIB-vserver-shared-storage if this is used
                    SSH_IP_ADDRESS=$IP_ADDRESS
            fi
            # If I've processed all then exit
            if  "$NETWORK_NAME" == "$NETWORK_NAMES" 
            then
                    break
            fi
    done
    getDistributionGroupId

    if  "$DESCRIPTION" == "" 
    then
        DESCRIPTION="Created by $0"
    fi

    # Create vServer
    if  "$DISTGROUP_ID" != "" 
    then
            echo "About to execute : $IAAS_HOME/bin/iaas-run-vserver --name $VSERVER_NAME --key-name $KEY_NAME --vserver-type $VSTYPE_ID --server-template-id $TEMPLATE_ID --vnets $NETWORK_IDS --ip-addresses $NETWORK_IPS --dist-group $DISTGROUP_ID"

            $IAAS_HOME/bin/iaas-run-vserver --name $VSERVER_NAME --key-name $KEY_NAME --vserver-type $VSTYPE_ID --server-template-id $TEMPLATE_ID --vnets $NETWORK_IDS --ip-addresses $NETWORK_IPS --dist-group $DISTGROUP_ID --desc "$DESCRIPTION"
    else
            echo "About to execute : $IAAS_HOME/bin/iaas-run-vserver --name $VSERVER_NAME --key-name $KEY_NAME --vserver-type $VSTYPE_ID --server-template-id $TEMPLATE_ID --vnets $NETWORK_IDS --ip-addresses $NETWORK_IPS"

            $IAAS_HOME/bin/iaas-run-vserver --name $VSERVER_NAME --key-name $KEY_NAME --vserver-type $VSTYPE_ID --server-template-id $TEMPLATE_ID --vnets $NETWORK_IDS --ip-addresses $NETWORK_IPS --desc "$DESCRIPTION"
    fi
    pauseUntilVServerRunning
    if  "$REMOVE_SSH_KEYS" == "true" 
    then
            removeSshKeyRequirement
    fi

    echo "vServer $VSERVER_NAME has been created"
}

#############################################################
##
## removeSshKeyRequirement
## =======================
##
## When a vServer is created using the cli the it is set up
## with a ssh key this function will remove that requirement.
##
#############################################################

function removeSshKeyRequirement() {
    SSH_FLAGS="-i $KEY_FILE -o StrictHostKeyChecking=no"

    SSH_IP_ADDRESS=""
    for IP in ${NETWORK_IPS//,/ }
    do
        # Test first with expect because IP is probably not in the list of known hosts
SSH_RESULT=$((expect - &lt;&lt; EOF
spawn ssh $SSH_FLAGS root@$IP  "hostname"
expect -re "assword" 
send "Password\r"
expect -re "~]#" 
send "hostname\r\n"
set timeout 10
EOF
) | while read line; do if test "${line#*$VSERVER_NAME}" != "$line"; then echo $VSERVER_NAME; fi; done)
if  "$SSH_RESULT" != "$VSERVER_NAME" 
then
SSH_RESULT=$((expect - &lt;&lt; EOF
spawn ssh $SSH_FLAGS root@$IP  "hostname"
expect -re "assword" 
send "Password\r"
expect -re "~]#" 
send "hostname\r\n"
set timeout 10
EOF
) | while read line; do if test "${line#*$VSERVER_NAME}" != "$line"; then echo $VSERVER_NAME; fi; done)
fi

        if  "$SSH_RESULT" == "$VSERVER_NAME" 
        then
                echo "$IP Address works for ssh"
                SSH_IP_ADDRESS=$IP
                break;
        else
                echo "$IP Address does not work for ssh"
        fi
    done

    if  "$SSH_IP_ADDRESS" != "" 
    then
        echo ""
        echo "Removing ssh key requirement for $VSERVER_NAME on $SSH_IP_ADDRESS"

        ssh $SSH_FLAGS root@$SSH_IP_ADDRESS "cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig"
        ssh $SSH_FLAGS root@$SSH_IP_ADDRESS "sed 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config.orig &gt; /etc/ssh/sshd_config"
        ssh $SSH_FLAGS root@$SSH_IP_ADDRESS "service sshd restart"

        echo "Removed ssh key requirement for $VSERVER_NAME"
    else
        echo ""
        echo "Unable to find a route to $VSERVER_NAME to remove the ssh key requirement you will need to do the following"
        echo ""
        echo "1. ssh into the vServer using: ssh -i $KEY_FILE -l root "
        echo "2. Edit /etc/ssh/sshd_config and replace \"PasswordAuthentication no\" with \"PasswordAuthentication yes\""
        echo "3. Restart sshd service: service sshd restart"
        echo ""
        echo "cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig"
        echo "sed \'s/PasswordAuthentication no/PasswordAuthentication yes/\' /etc/ssh/sshd_config.orig &gt; /etc/ssh/sshd_config"
        echo "service sshd restart"
        echo ""
        KEEP_PUB_KEY=true
    fi
}

#############################################################
##
## pauseUntilVServerRunning
## ========================
##
## Pause the script until the vServer is running.
##
#############################################################

function pauseUntilVServerRunning() {
	# Wait until the Server is running before creating the next
	echo "Pausing until vServer is Running"
  getVServerState
  while  "$VSERVER_STATE" != "RUNNING" 
  do
  	echo "$NAME $VSERVER_STATE"
  	if  "$VSERVER_STATE" != "RUNNING" 
  	then
  		echo "Sleeping......."
  		sleep 30
  	fi
  	if  "$VSERVER_STATE" == "FAILED" 
  	then
  		echo "$NAME Will Delete Automatically after remaining Failed for a period....."
   		break
  	fi
  	getVServerState
  done
  echo "$NAME $VSERVER_STATE"
  # Lets pause for a minute or two
  echo "Just Waiting 30 Seconds......"
  sleep 30
}

#############################################################
##
## pauseUntilVServerShutdown
## ========================
##
## Pause the script until the vServer is shutdown.
##
#############################################################

function pauseUntilVServerShutdown() {
    # Wait until the Server is shutdown before creating the next
  echo "Pausing until vServer has Shutdown"
  getVServerState
  while  "$VSERVER_STATE" != "SHUTDOWNDETACHED" 
  do
  	echo "$NAME $VSERVER_STATE"
  	if  "$VSERVER_STATE" != "SHUTDOWNDETACHED" 
  	then
  		echo "Sleeping......."
  		sleep 30
  	fi
  	getVServerState
  done
  echo "$NAME $VSERVER_STATE"
  # Lets pause for a minute or two
  echo "Just Waiting 30 Seconds......"
  sleep 30
}

#############################################################
##
## attachVolume
## =======================
##
## Attach a Volume to a vServer.
##
#############################################################

function attachVolume() {
    # Get vServer Id
    getVServerId
    # Convert Volume Names to Ids
    VOLUME_IDS=""
    while true
    do
        VOLUME_NAME=${VOLUME_NAMES%%,*}
        VOLUME_NAMES=${VOLUME_NAMES#*,}
        getVolumeId
        if  "$VOLUME_IDS" != "" 
        then
                VOLUME_IDS="$VOLUME_IDS,$VOLUME_ID"
        else
                VOLUME_IDS=$VOLUME_ID
        fi
        if  "$VOLUME_NAME" == "$VOLUME_NAMES" 
        then
            break
        fi
    done
    # Attach Volumes
    echo "About to execute : $IAAS_HOME/bin/iaas-attach-volumes-to-vserver --vserver-id $VSERVER_ID --volume-ids $VOLUME_IDS"
    $IAAS_HOME/bin/iaas-attach-volumes-to-vserver --vserver-id $VSERVER_ID --volume-ids $VOLUME_IDS
  # Lets pause
  echo "Just Waiting 30 Seconds......"
  sleep 30
}

#############################################################
##
## uploadServerTemplate
## ====================
##
## Upload a tgz file that defines a server template. It is 
## recommended these be copied to the ZFS first and then the
## appropriate URL from the ZFS be used.
##
#############################################################

function uploadServerTemplate() {
    # Upload Template
    echo "About to execute : $IAAS_HOME/bin/iaas-create-server-template-from-url --name $TEMPLATE_NAME --url $TEMPLATE_URL"
    $IAAS_HOME/bin/iaas-create-server-template-from-url --name $TEMPLATE_NAME --url $TEMPLATE_URL
  # Lets pause
    pauseUntilServerTemplateUploaded
}

function deleteServerTemplate() {
    $IAAS_HOME/bin/iaas-delete-server-template --force --server-template-id $TEMPLATE_ID
}

#############################################################
##
## pauseUntilServerTemplateUploaded
## ================================
##
## Pause the script until the Template file has been uploaded
## to the Account.
##
#############################################################

function pauseUntilServerTemplateUploaded() {
    echo "Pausing until Template upload has completed"
  getTemplateState
  while  "$TEMPLATE_STATE" != "OK" 
  do
  	echo "$NAME $TEMPLATE_STATE"
  	if  "$TEMPLATE_STATE" != "SCHEDULED" 
  	then
            echo "Sleeping......."
            sleep 30
  	elif  "$TEMPLATE_STATE" != "RUNNING" 
  	then
            echo "Sleeping......."
            sleep 30
  	elif  "$TEMPLATE_STATE" != "FAILED" 
  	then
            deleteServerTemplate
            echo "Sleeping......."
            sleep 30
  	fi
  	getTemplateState
  done
}

#############################################################
##
## createAssets
## ============
##
## This function loops through the information defined in
## the input file looking for actions to be executed. It will
## process the entries sequentially and simply call the
## appropriate sub-function to execute the iaas commands.
## Entries with invalid Actions will simply be ignored along
## with blank lines.
##
#############################################################

function createAssets() {
	# Read Entries into an Array
	assetArray=( $(grep ":" $ASSET_FILE) )
	# Process Array
	for line in "${assetArray[@]}"
	do
		#echo "Processing Line: $line"
		ACCOUNT=${line%%:*}
		line=${line#*:}
		ACTION=${line%%|*}
		line=${line#*|}
		if  "$ACTION" == "Connect" 
		then
                    ACCOUNT_USER=${line%%|*}
                    line=${line#*|}
                    ACCOUNT_PASSWORD=${line%%|*}
                    IAAS_USER=$ACCOUNT_USER
                    echo "$ACCOUNT_PASSWORD" &gt; $IAAS_PASSWORD_FILE
                    getAccounts
                    getAccountId
                    connectToAccount

                    ## Account Info
                    getNetworks
                    getVSTypes
                    getTemplates
		elif  "$ACTION" == "Create" 
		then
                    ASSET=${line%%|*}
                    line=${line#*|}
                    ASSET_DETAILS=$line
                    if  "$ASSET" == "vServer" 
                    then
                        getDistributionGroups

                        VSERVER_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        VSTYPE_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        TEMPLATE_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        NETWORK_NAMES=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        IP_ADDRESSES=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        DISTGROUP_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        DESCRIPTION=${ASSET_DETAILS%%|*}

                        createVServer
                    elif  "$ASSET" == "vServers" 
                    then
                        getDistributionGroups
                        createVServers
                    elif  "$ASSET" == "Volume" 
                    then
                        VOLUME_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        VOLUME_SIZE=${ASSET_DETAILS%%|*}
                        createVolume
                    elif  "$ASSET" == "DistributionGroup" 
                    then
                        DISTGROUP_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        # Size is never specified
                        # DISTGROUP_SIZE=${ASSET_DETAILS%%|*}
                        createDistributionGroup
                    elif  "$ASSET" == "VirtualNetwork" 
                    then
                        NETWORK_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        NETWORK_IPS=${ASSET_DETAILS%%|*}
                        createVirtualNetwork
                    fi
		elif  "$ACTION" == "Upload" 
		then
                    ASSET=${line%%|*}
                    line=${line#*|}
                    ASSET_DETAILS=$line
                    if  "$ASSET" == "ServerTemplate" 
                    then
                        TEMPLATE_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        TEMPLATE_URL=${ASSET_DETAILS%%|*}
                        uploadServerTemplate
                    fi
		elif  "$ACTION" == "Attach" 
		then
                    ASSET=${line%%|*}
                    line=${line#*|}
                    ASSET_DETAILS=$line
                    if  "$ASSET" == "Volume" 
                    then
                        getVolumes
                        getVServers
                        VSERVER_NAME=${ASSET_DETAILS%%|*}
                        ASSET_DETAILS=${ASSET_DETAILS#*|}
                        VOLUME_NAMES=${ASSET_DETAILS%%|*}
                        attachVolume
                    fi
		elif  "$ACTION" == "Disconnect" 
		then
                    disconnectFromAccount
		fi
	done
}

#export RUN_DATE=`date +"%Y%m%d-%H%M"`

#############################################################
##
## copyServerFiles
## ===============
##
## Copy the vServer img files to working location.
##
#############################################################

function copyServerFiles() {
    echo "Copying vServer Files"

    TEMPLATE_DIR=$WORKING_DIR/$VSERVER_NAME/template/BASE
    VIRTUAL_MACHINES_DIR=$REPOSITORY_DIR/VirtualMachines
    VIRTUAL_DISKS_DIR=$REPOSITORY_DIR/VirtualDisks
    ROOT_IMG_FILE=""

    GREP_VM_CFG=`grep "'$VSERVER_NAME'" $VIRTUAL_MACHINES_DIR/*/vm.cfg`
    VM_CFG=${GREP_VM_CFG%%:*}

    mkdir -p $TEMPLATE_DIR
    cp $VM_CFG $TEMPLATE_DIR

    DISKS=`grep disk $VM_CFG`
    FILES=${DISKS#*:}
    DISK_CNT=0
    VM_CFG_TEMPLATE_NAME=$VSERVER_NAME"_TEMPLATE"
    while  "$DISKS" != "$FILES" 
    do
        #echo "FILES = $FILES"
        #echo "DISKS = $DISKS"
        #echo "DISK_CNT = $DISK_CNT"
        IMG_FILE=${FILES%%,*}
        echo "Copying $IMG_FILE"
        # Set root image we assume the first
        if  "$ROOT_IMG_FILE" == "" 
        then
            cp $IMG_FILE $TEMPLATE_DIR/System.img
            SYSTEM_IMG=${IMG_FILE#*VirtualDisks/}
            ROOT_IMG_FILE=$TEMPLATE_DIR/$SYSTEM_IMG
            ROOT_IMG_FILE=$TEMPLATE_DIR/System.img
            #echo "Root Image $ROOT_IMG_FILE"
            NEW_DISKS="'file:/OVS/seed_pool/$VM_CFG_TEMPLATE_NAME/System.img,hda,w'"
        else
            cp $IMG_FILE $TEMPLATE_DIR/System$DISK_CNT.img
            #echo "Secondary Image $IMG_FILE"
            FILES=${FILES#*,}
            #echo "FILES = $FILES"
            IMG_FILE_TYPE=${FILES%%\'*}
            #echo "IMG_FILE_TYPE = $IMG_FILE_TYPE"
            NEW_DISKS=$NEW_DISKS", 'file:/OVS/seed_pool/$VM_CFG_TEMPLATE_NAME/System$DISK_CNT.img,$IMG_FILE_TYPE'"
        fi
        # Shuffle line for next disk
        DISKS=${DISKS#*:}
        FILES=${DISKS#*:}
        DISK_CNT=$((DISK_CNT+1))
    done

    # Generate vm.cfg

    # Add Standard name format to allow ModifyJeOS to work
    echo "name = '$VM_CFG_TEMPLATE_NAME'" &gt; $TEMPLATE_DIR/vm.cfg
    echo "disk = [$NEW_DISKS]" &gt;&gt; $TEMPLATE_DIR/vm.cfg
    echo "OVM_simple_name = ''" &gt;&gt; $TEMPLATE_DIR/vm.cfg
    # Copy remaining content of vm.cfg
    while read line
    do
        if ^disk.*|^OVM_simple_name.*|^boot.*|^cpu_weight.*|^cpu_cap.*|^OVM_high_availability.*|^OVM_description.*|^on_poweroff.*|^guest_of_type.*|^vfb.* 
        then
            echo "Ignoring vm.cfg entry : $line"
        else
            echo $line &gt;&gt; $TEMPLATE_DIR/vm.cfg
        fi
    done &lt; $VM_CFG

}

#############################################################
##
## unconfigureVM
## =============
##
## Remove / edit the files that a created / modified when the
## template has been used to created a vServer.
##
#############################################################

function unconfigureVM() {
    echo "Unconfiguring Root Image $ROOT_IMG_FILE"
    cd $WORKING_DIR
    # Make Temp Mount Directory
    mkdir -p $SYSTEMIMGDIR
    # Check if we are using LVM
    if  "$LVM" == "true" 
    then
        kpartx -a $ROOT_IMG_FILE
        vgscan
        vgchange -ay $VOL_GRP

        vgdisplay -s|grep $VOL_GRP
        if  "$?" == "1" 
        then
            echo could not find volume group: $VOL_GRP
            echo please cleanup mapped device
            exit
        else
            echo found volume group: $VOL_GRP
        fi

        lvdisplay -c|grep $LOG_VOL
        if  "$?" == "1" 
        then
            echo could not find logical volume: $LOG_VOL
            echo please cleanup mapped devices and run vgchange -an $VOL_GRP
            exit
        else
            echo found logical volume: $LOG_VOL
        fi

        ls -l /dev/mapper/$VOL_GRP-$LOG_VOL
        read p1
        mount /dev/mapper/$VOL_GRP-$LOG_VOL $SYSTEMIMGDIR
        if  "$?" == "1" 
        then
            echo "Failed to mount image file - exiting"
            exit
        fi
    else
        # Mount the Image file
        export LOOP=`losetup -f`
        # Create Loop for the System Image
        losetup $LOOP $ROOT_IMG_FILE
        kpartx -a $LOOP
        mount /dev/mapper/`basename $LOOP`p2 $SYSTEMIMGDIR
        if  "$?" == "1" 
        then
            echo "Failed to mount image file - exiting"
            exit
        fi
    fi

    echo "Mounted $SYSTEMIMGDIR"
    #Change Dir into mounted Image
    cd $SYSTEMIMGDIR

    # Unconfigure
    cp etc/sysconfig/ovmd etc/sysconfig/ovmd.orig
    sed 's/INITIAL_CONFIG=no/INITIAL_CONFIG=yes/g' etc/sysconfig/ovmd.orig &gt; etc/sysconfig/ovmd
    rm -v etc/sysconfig/ovmd.orig

    cp etc/resolv.conf etc/resolv.conf.$RUN_DATE
    if  "$KEEP_RESOLV" != "true" 
    then
        sed -i '/.*/d' etc/resolv.conf
    else
        echo "Keeping unmodified resolv.conf"
    fi

    # Remove existing ssh information
    rm -v root/.ssh/*
    rm -v etc/ssh/ssh_host*

    # Clean up hosts
    cp etc/hosts etc/hosts.$RUN_DATE
    cp etc/sysconfig/networking/profiles/default/hosts etc/sysconfig/networking/profiles/default/hosts.$RUN_DATE
    if  "$KEEP_HOSTS" != "true" 
    then
        sed -i '/localhost/!d' etc/hosts
        sed -i '/localhost/!d' etc/sysconfig/networking/profiles/default/hosts
    else
        echo "Keeping unmodified hosts"
    fi

    # Clean up networking
    sed -i '/^GATEWAY/d' etc/sysconfig/network

    # Remove Network scripts
    rm -v etc/sysconfig/network-scripts/ifcfg-*eth*
    rm -v etc/sysconfig/network-scripts/ifcfg-ib*
    rm -v etc/sysconfig/network-scripts/ifcfg-bond*

    # Remove log files
    rm -v var/log/messages*
    rm -v var/log/ovm-template-config.log
    rm -v var/log/ovm-network.log
    rm -v var/log/boot.log*
    rm -v var/log/cron*
    rm -v var/log/maillog*
    rm -v var/log/rpmpkgs*
    rm -v var/log/secure*
    rm -v var/log/spooler*
    rm -v var/log/yum.log*

    # Remove Kernel Messages

    rm -v var/log/dmesg

    # Edit modprobe file
    sed -i '/bond/d' etc/modprobe.conf

    # Edit hwconf file
    cp etc/sysconfig/hwconf etc/sysconfig/hwconf.orig
    sed 's/mlx4_en/mlx4_core/' etc/sysconfig/hwconf.orig &gt; etc/sysconfig/hwconf
    rm -v etc/sysconfig/hwconf.orig

    # Remove Exalogic Config file
    rm -v etc/exalogic.conf

    #Remove bash history
    rm -v root/.bash_history

    # Unmount the image file
    cd $WORKING_DIR
    umount $SYSTEMIMGDIR
    echo "Unmounted $SYSTEMIMGDIR"

    # Check if we are using LVM
    if  "$LVM" == "true" 
    then
        vgchange -an $VOL_GRP
        kpartx -d $ROOT_IMG_FILE
    else
	kpartx -d $LOOP
	losetup -d $LOOP
    fi

    rm -rf $SYSTEMIMGDIR
}

function buildTemplateTgz() {
	echo "Creating the Template tgz file"
	mkdir -p $DESTINATION_DIR
	cd $TEMPLATE_DIR
	TEMPLATE_TGZ=$DESTINATION_DIR/el_template_$VSERVER_NAME.tgz
	tar -zcvf $TEMPLATE_TGZ *
	echo "Template $TEMPLATE_TGZ file created"
}

function cleanWorkingDir() {
	echo "Cleaning Working Directory"
	cd $WORKING_DIR
	rm -rfv $VSERVER_NAME
}

#############################################################
##
## createTemplate
## ==============
##
## High level template creation function that will call the 
## required processing function in the necessary sequence.
##
#############################################################

function createTemplate() {
    VSERVER_NAME=$VSERVER
    copyServerFiles
    unconfigureVM
    buildTemplateTgz
    cleanWorkingDir
    echo ""
    echo ""
    echo "****************************************************"
    echo "**"
    echo "** $TEMPLATE_TGZ has been created from"
    echo "** vServer $VSERVER_NAME "
    echo "**"
    echo "****************************************************"
    echo ""
    echo ""
}

#############################################################
##
## executeRemoteCreateTemplate
## ===========================
##
## Execute the CreateTemplateFromVServer.sh on the specified 
## Compute Node. This is required because the Repository is
## not accessible from the EC VM. It's assumed we will not 
## need to enter a password.
##
#############################################################

function executeRemoteCreateTemplate() {
    echo "Executing Remote Functions"
    if  "$CN_IP_ADDRESS" != "" 
    then
        #ssh root@$CN_IP_ADDRESS "bash -s" &lt; CreateTemplateFromVServer.sh -n $VSERVER_NAME -r $REPOSITORY_DIR -w $WORKING_DIR -d $DESTINATION_DIR
        #ssh root@$CN_IP_ADDRESS "bash -s -n $VSERVER_NAME -r $REPOSITORY_DIR -w $WORKING_DIR -d $DESTINATION_DIR" &lt; CreateTemplateFromVServer.sh
        #cat CreateTemplateFromVServer.sh | ssh root@$CN_IP_ADDRESS "bash -s -n $VSERVER_NAME -r $REPOSITORY_DIR -w $WORKING_DIR -d $DESTINATION_DIR"
        ADDITIONAL=""
        if  "$KEEP_RESOLV" == "true" 
        then
            ADDITIONAL=" -keep-resolv"
        fi
        if  "$KEEP_HOSTS" == "true" 
        then
            ADDITIONAL=$ADDITIONAL" -keep-hosts"
        fi
        echo "Additional $ADDITIONAL"
        echo "Copying script $0 to $CN_IP_ADDRESS"
        scp $0 root@$CN_IP_ADDRESS:/tmp
        ssh root@$CN_IP_ADDRESS "chmod a+x /tmp/$0"
        if  "$LVM" == "true" 
        then
            ssh root@$CN_IP_ADDRESS "/tmp/$0 --create-template -v $VSERVER_NAME -r $REPOSITORY_DIR -w $WORKING_DIR -d $DESTINATION_DIR -lvm $VOL_GRP $LOG_VOL $ADDITIONAL"
        else
            ssh root@$CN_IP_ADDRESS "/tmp/$0 --create-template -v $VSERVER_NAME -r $REPOSITORY_DIR -w $WORKING_DIR -d $DESTINATION_DIR $ADDITIONAL"
        fi
        ssh root@$CN_IP_ADDRESS "rm -f /tmp/$0"

        TEMPLATE_TGZ=$DESTINATION_DIR/el_template_$VSERVER_NAME.tgz
    fi
}

#############################################################
##
## generateAssetsFile
## ==================
##
## Generates a Input script that can be used with the 
## --create-assets to recreate the account assets. 
##
#############################################################

function generateAssetsFile() {
    echo "$ACCOUNT:Connect|$ACCOUNT_USER|$ACCOUNT_PASSWORD" &gt;&gt; $ASSET_FILE
    echo "$ACCOUNT:Disconnect" &gt;&gt; $ASSET_FILE
}

#############################################################
##
## generateCaptureAssetFile
## ========================
##
## Generates a Input script that can be used with the 
## --create-assets to create a server based on the new 
## template.
##
#############################################################

function generateCaptureAssetFile() {
    echo "Capturing Asset information to input file $ASSET_FILE"
    if  "$ASSET_FILE" == "" 
    then
        ASSET_FILE=$VSERVER_NAME"Asset.in"
    fi
    echo "$ACCOUNT:Connect|$ACCOUNT_USER|$ACCOUNT_PASSWORD" &gt; $ASSET_FILE
    # Here we are assuming that we have used the recommended mount
    SN_TEMPLATE_FILE=${TEMPLATE_TGZ/u01/export}
    echo "$ACCOUNT:Upload|ServerTemplate|$VSERVER_NAME-Template|http://$SN_IP_ADDRESS/shares$SN_TEMPLATE_FILE" &gt;&gt; $ASSET_FILE
    # Get VServer specific information
    getVServers
    getNetworks
    getVSTypes

    for line in "${vserversArray[@]}"
    do
        VSERVER_ID=${line%%|*}
        line=${line#*|}
        NAME=${line%%|*}
        line=${line#*|}
        if  "$NAME" == "$VSERVER_NAME" 
        then
            DESCRIPTION=${line%%|*}
            line=${line#*|}
            STATE=${line%%|*}
            line=${line#*|}
            NETWORK_IDS=${line%%|*}
            line=${line#*|}
            NETWORK_IPS=${line%%|*}
            line=${line#*|}
            TEMPLATE_ID=${line%%|*}
            line=${line#*|}
            SSH_KEY=${line%%|*}
            line=${line#*|}
            VSTYPE_ID=${line%%|*}
            line=${line#*|}

            NETWORK_NAMES=""
            #NETWORK_IPS=""
            for NETWORK_ID in ${NETWORK_IDS//,/ }
            do
                getNetworkName
                if  "$NETWORK_NAMES" == "" 
                then
                    NETWORK_NAMES=$NETWORK_NAME
                    if  "$BACKUP" != "true" 
                    then
                        NETWORK_IPS="*"
                    fi
                else
                    NETWORK_NAMES=$NETWORK_NAMES","$NETWORK_NAME
                    if  "$BACKUP" != "true" 
                    then
                        NETWORK_IPS=$NETWORK_IPS",*"
                    fi
                fi
            done

            if  "$VSTYPE" == "" 
            then
                # Get VServer Type Name
                getVSTypeName
            else
                VSTYPE_NAME=$VSTYPE
            fi

            echo "$ACCOUNT:Create|vServer|$VSERVER_NAME|$VSTYPE_NAME|$VSERVER_NAME-Template|$NETWORK_NAMES|$NETWORK_IPS|$VSDG|$DESCRIPTION" &gt;&gt; $ASSET_FILE

            break
        fi
    done

    echo "$ACCOUNT:Disconnect" &gt;&gt; $ASSET_FILE

    echo "Generated Asset File $ASSET_FILE"

}

#############################################################
##
## captureVServer
## ==============
##
## High level template creation function that will call the 
## required processing function in the necessary sequence.
##
#############################################################

function captureVServer() {
    VSERVER_NAME=$VSERVER
    stopVServer
    executeRemoteCreateTemplate
    startVServer
    generateCaptureAssetFile
    echo ""
    echo ""
    echo "****************************************************"
    echo "**"
    echo "** $TEMPLATE_TGZ has been created from"
    echo "** vServer $VSERVER_NAME "
    echo "**"
    echo "****************************************************"
    echo ""
    echo ""
}

function simpleCreateVServer() {
    ASSET_FILE=/tmp/simpleCreateAsset.$$.in
    echo "$ACCOUNT:Connect|$ACCOUNT_USER|$ACCOUNT_PASSWORD" &gt; $ASSET_FILE
    echo "$ACCOUNT:Create|vServer|$VSERVER|$VSTYPE|$VSTEMPLATE|$NETWORK_NAMES|$NETWORK_IPS|$VSDG|$VSDESCRIPTION" &gt;&gt; $ASSET_FILE
    echo "$ACCOUNT:Disconnect" &gt;&gt; $ASSET_FILE
    getAccounts
    createAssets
}

function simpleStopVServer() {
    VSERVER_NAME=$VSERVER
    stopVServer
}

function simpleStartVServer() {
    VSERVER_NAME=$VSERVER
    startVServer
}

function simpleRestartVServer() {
    simpleStopVServer
    simpleStartVServer
}

function simpleDeleteVServer() {
    VSERVER_NAME=$VSERVER
    deleteVServer
}

#############################################################
##
## usage
## =====
##
## Show usage.
##
#############################################################

function usage() {
	echo ""
#	echo &gt;&amp;2 "usage: $0 [-a ] [-v ] [-u ] [-p ] [-r ] [-w ] [-d ] [-cip ] [-sip ] [-url ] [-f ] [-remove-ssh] [--verbose] <command></command>"
	echo &gt;&amp;2 "usage: $0 <command></command> "
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "Commands "
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --status-vservers"
	echo &gt;&amp;2 "                List the status all the vServers in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the vServers. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [-v ] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --start-vservers"
	echo &gt;&amp;2 "                Start all or the named -v vServer(s) in the specified Account. If no Account is specified"
	echo &gt;&amp;2 "                then it will loop through all Accounts within the vDC starting the vServers."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [-v ] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --reboot-vservers"
	echo &gt;&amp;2 "                Reboot all or the named -v vServer(s) in the specified Account. If no Account is specified"
	echo &gt;&amp;2 "                then it will loop through all Accounts within the vDC starting the vServers."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [-v ] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --stop-vservers"
	echo &gt;&amp;2 "                Stop all or the named -v vServer(s) in the specified Account. If no Account is specified"
	echo &gt;&amp;2 "                then it will loop through all Accounts within the vDC stoping the vServers."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [-v ] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --list-vservers"
	echo &gt;&amp;2 "                List all the vServers in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the vServers. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 "                If --verbose is also specified the all available vServer information will be listed."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [--verbose] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --list-vnets"
	echo &gt;&amp;2 "                List all the vNets in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the vNets. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 "                If --verbose is also specified the all available vNet information will be listed."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [--verbose] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --list-distgroups"
	echo &gt;&amp;2 "                List all the Distribution Groups in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the Distribution Groups. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 "                If --verbose is also specified the all available Distribution Group information will be listed."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [--verbose] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --list-volumes"
	echo &gt;&amp;2 "                List all the Volumes in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the Volumes. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 "                If --verbose is also specified the all available Volumes information will be listed."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [--verbose] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --list-templates"
	echo &gt;&amp;2 "                List all the Templates in the specified Account. If no Account is specified then it"
	echo &gt;&amp;2 "                will loop through all Accounts within the vDC listing the Templates. To successfully"
	echo &gt;&amp;2 "                achieve this the mandatory Username and Password must have access to all the accounts."
	echo &gt;&amp;2 "                If --verbose is also specified the all available Template information will be listed."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -u  -p "
	echo &gt;&amp;2 "                Optional parameters: [-a ] [--verbose] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --create-vserver"
	echo &gt;&amp;2 "                Creates a single vServer based on the information provided in the parameters. All parameters"
	echo &gt;&amp;2 "                are name based and the ids will be found based on the provided name."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -u  -p  -v  -vs-type  -vs-template  -vs-networks  -vs-ips  "
	echo &gt;&amp;2 "                Optional parameters: [-vs-dg ] [-vs-desc ] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --delete-vserver"
	echo &gt;&amp;2 "                Deletes a single vServer based on the information provided in the parameters. All parameters"
	echo &gt;&amp;2 "                are name based and the ids will be found based on the provided name."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -u  -p  -v  "
	echo &gt;&amp;2 "                Optional parameters: [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --stop-vserver"
	echo &gt;&amp;2 "                Stops a single vServer based on the information provided in the parameters. All parameters"
	echo &gt;&amp;2 "                are name based and the ids will be found based on the provided name."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -u  -p  -v  "
	echo &gt;&amp;2 "                Optional parameters: [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --start-vserver"
	echo &gt;&amp;2 "                Starts a single vServer based on the information provided in the parameters. All parameters"
	echo &gt;&amp;2 "                are name based and the ids will be found based on the provided name."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -u  -p  -v  "
	echo &gt;&amp;2 "                Optional parameters: [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --restart-vserver"
	echo &gt;&amp;2 "                Restarts a single vServer based on the information provided in the parameters. All parameters"
	echo &gt;&amp;2 "                are name based and the ids will be found based on the provided name."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -u  -p  -v  "
	echo &gt;&amp;2 "                Optional parameters: [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --create-assets"
	echo &gt;&amp;2 "                Reads the specified Asset file and creates all the assets defined within it. If multiple"
	echo &gt;&amp;2 "                projects are defined these are worked through. The file is processed sequentially and"
	echo &gt;&amp;2 "                therefore must contain action in an appropriate sequence."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -f "
	echo &gt;&amp;2 "                Optional parameters: [-remove-ssh-key] [-url ]"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --create-template"
	echo &gt;&amp;2 "                Takes the specified vServer name and identifies the associated img files which will then"
	echo &gt;&amp;2 "                be copied to a working directory before being opened and edited thus converting them to a"
	echo &gt;&amp;2 "                template. If multiple images exist (because vServers uses volumes) it will be converted to"
	echo &gt;&amp;2 "                a single template with multiple img files and hence larger size. This command must be executed"
	echo &gt;&amp;2 "                on a physical compute node preferably cn01."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -v "
	echo &gt;&amp;2 "                Optional parameters: [-lvm  ] [-r ] [-w ] [-d ] -keep-hosts -keep-resolv"
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          --capture-vserver"
	echo &gt;&amp;2 "                Access the Exalogic EMOC system and retrieve the information about the specified vServer. This"
	echo &gt;&amp;2 "                information is recorded in an Asset file that can be used with --create-assets. The script also"
	echo &gt;&amp;2 "                takes the existing vServer image files and converts them into a template and the upload is added"
	echo &gt;&amp;2 "                to the Asset file."
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "                Required parameters: -a  -v  -u  -p  -cip  -sip "
	echo &gt;&amp;2 "                Optional parameters: [-lvm  ] [-r ] [-w ] [-d ] [-new-ips] [-url ] -keep-hosts -keep-resolv [-vs-dg ] -vs-type  "
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "Parameters "
	echo &gt;&amp;2 " "
	echo &gt;&amp;2 "          -a  Name of the Account that contains the Specified vServer."
	echo &gt;&amp;2 "          -u  User that is allowed to access the specified account the default is root"
	echo &gt;&amp;2 "          -p  password of the specified user"
	echo &gt;&amp;2 "          -v  vServer to be templatised or cloned."
	echo &gt;&amp;2 "          -r  Location of the repository the default is $REPOSITORY_DIR"
	echo &gt;&amp;2 "          -w  Working directory where intermediate files will be copied default $WORKING_DIR."
	echo &gt;&amp;2 "          -d  Directory where the template tgz will be created. Default is $DESTINATION_DIR"
	echo &gt;&amp;2 "          -f  (Default is CreateAssets.in)"
	echo &gt;&amp;2 "          -vs-type  Name of the vServer Type to be used during the vServer Creation"
	echo &gt;&amp;2 "          -vs-template  Name of the vServer Template to be used during the vServer Creation"
	echo &gt;&amp;2 "          -vs-desc  Description of the vServer to be used during the vServer Creation"
	echo &gt;&amp;2 "          -vs-networks  Comma separated list of Network Names the vServer will be associated with"
	echo &gt;&amp;2 "          -vs-ips  Comma separated list of IP Addresses, or * for automatic, associated with the network name list."
	echo &gt;&amp;2 "          -vs-dg  Name of the Distribution Group that the server will be placed in."
	echo &gt;&amp;2 "          -keep-hosts If set the hosts file will not be re-initialised during template creation."
	echo &gt;&amp;2 "          -keep-resolv If set the resolv.conf file will not be re-initialised during template creation."
	echo &gt;&amp;2 "          -remove-ssh-key Indicates that the ssh keys should be removed"
	echo &gt;&amp;2 "          -new-ips Indicates that the IP Address in a -capture-vserver should be replaced by * within the Asset file"
	echo &gt;&amp;2 "          -cip  This is the IP Address of the Compute Node that will be used to access"
        echo &gt;&amp;2 "               the /OVS/Repository and the actual vserver image files"
	echo &gt;&amp;2 "          -sip  IP Address of the Storage node that will be placed in the generated Asset "
        echo &gt;&amp;2 "               file for the load template entry. This must be accessible from EMOC."
	echo &gt;&amp;2 "          -url  URL to access the EMOC interface the default is https://localhost."
	echo &gt;&amp;2 "          -lvm   If the images file uses LVM then this parameter must be specified."
	echo &gt;&amp;2 "          -verbose Displays more information for list commands."
	echo &gt;&amp;2 "          -to-hrf Converts the verbose output to a Human Readable Form, i.e. replaces Ids with names."
	echo &gt;&amp;2 "          -h This message."
	echo &gt;&amp;2 " "
	echo""
	exit 1
}

###############################################################
##
## Simple start for the script that will extract the parameters
## and call the appropriate start function.
##
###############################################################

export ACCOUNT_USER=""
export ACCOUNT_PASSWORD=""
export SYSTEMIMGDIR=/mnt/elsystem
export REMOVE_SSH_KEYS=false
export WORKING_DIR="/u01/common/images/vServerTemplatesWIP"
export DESTINATION_DIR="/u01/common/images/vServerTemplates"
export REPOSITORY_DIR="/OVS/Repositories/*"
export CN_IP_ADDRESS=""
export SN_IP_ADDRESS=""
export BACKUP=true
export VSDESCRIPTION=""

while [ $# -gt 0 ]
do
	case "$1" in	
# Parameters
		-a) ACCOUNT="$2"; shift;;
		-d) DESTINATION_DIR="$2"; shift;;
		-f) ASSET_FILE="$2"; shift;;
		-p) ACCOUNT_PASSWORD="$2"; shift;;
		-r) REPOSITORY_DIR="$2"; shift;;
		-u) ACCOUNT_USER="$2"; shift;;
		-v) VSERVER="$2"; shift;;
		-w) WORKING_DIR="$2"; shift;;
		-cip) CN_IP_ADDRESS="$2"; shift;;
		-sip) SN_IP_ADDRESS="$2"; shift;;
		-url) IAAS_BASE_URL="$2"; shift;;
                -new-ips) BACKUP=false;;
                -keep-resolv) KEEP_RESOLV=true;;
                -keep-hosts) KEEP_HOSTS=true;;
		-remove-ssh-key) REMOVE_SSH_KEYS=true;;
                -lvm) LVM=true; VOL_GRP="$2"; LOG_VOL="$3"; shift; shift;;
                -vs-type) VSTYPE="$2"; shift;;
                -vs-template) VSTEMPLATE="$2"; shift;;
                -vs-desc) VSDESCRIPTION="$2"; shift;;
                -vs-networks) NETWORK_NAMES="$2"; shift;;
                -vs-ips) NETWORK_IPS="$2"; shift;;
                -vs-dg) VSDG="$2"; shift;;
		-to-hrf) HRF=true;;
		-verbose) VERBOSE=true;;
		--verbose) VERBOSE=true;;
# Commands
		--create-vserver) CREATE_VSERVER=true;;		
		--delete-vserver) DELETE_VSERVER=true;;		
		--stop-vserver) STOP_VSERVER=true;;		
		--start-vserver) START_VSERVER=true;;		
		--restart-vserver) RESTART_VSERVER=true;;		
		--stop-vservers) STOP_VSERVERS=true;;		
		--start-vservers) START_VSERVERS=true;;		
		--reboot-vservers) REBOOT_VSERVERS=true;;		
		--status-vservers) STATUS_VSERVERS=true;;		
		--list-vservers) LIST_VSERVERS=true;;               
		--list-vnets) LIST_VNETS=true;;		
		--list-distgroups) LIST_DISTGRPS=true;;		
		--list-templates) LIST_TEMPLATES=true;;		
		--list-volumes) LIST_VOLUMES=true;;	
                --create-assets) CREATE_ASSETS=true;;
                --create-template) CREATE_TEMPLATE=true;;
                --capture-vserver) CAPTURE_VSERVER=true;;
                --generate-assets) GENERATE_ASSETS=true;;

                --test-cli) TEST_CLI=true;;

		*) usage;;
		*) break;;
	esac
	shift
done

IAAS_USER=$ACCOUNT_USER
echo "$ACCOUNT_PASSWORD" &gt; $IAAS_PASSWORD_FILE

# Check if the JAVA_HOME is set
if  "$JAVA_HOME" == "" 
then
	export JAVA_HOME=/usr/java/latest
	echo "JAVA_HOME is not defined using $JAVA_HOME"
fi

if  "$CREATE_ASSETS" == "true" &amp;&amp; "$ASSET_FILE" != "" 
then
    createAssets
elif  "$CREATE_TEMPLATE" == "true" &amp;&amp; "$VSERVER" != "" 
then
    if  "$LVM" == "true" 
    then
        if | "$LOG_VOL" == "" 
        then
            usage
        else
            grep "^ *filter.*a/\.*" /etc/lvm/lvm.conf &gt;/dev/null
            if  "$?" == "1" 
            then
               echo please change filter entry in /etc/lvm/lvm.conf from:
               grep "^ *filter.*r/\.*" /etc/lvm/lvm.conf
               echo to:
               echo '    filter = [ "a/.*/" ]'
               exit
            fi   
        fi
    fi
    createTemplate
elif  "$TEST_CLI" == "true" &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" 
then
    testCli
elif  "$CAPTURE_VSERVER" == "true" &amp;&amp; \
        "$ACCOUNT" != "" &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" &amp;&amp; \
        "$VSERVER" != "" &amp;&amp; \
        "$CN_IP_ADDRESS" != "" &amp;&amp; \
        "$SN_IP_ADDRESS" != "" 
then
    getAccounts
    for account in "${accountsArray[@]}"
    do
        ACCOUNT_ID=${account%%|*}
        account=${account#*|}
        ACCOUNT_NAME=${account%%|*}
        if  "$ACCOUNT" == "$ACCOUNT_NAME" &amp;&amp; "$ACCOUNT_ID" == ACC-* 
        then
            connectToAccount
            captureVServer
            disconnectFromAccount
        fi
    done
elif  "$GENERATE_ASSETS" == "true" &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" 
then
    getAccounts
    ASSET_FILE=CreateAssets.$$.in
    for account in "${accountsArray[@]}"
    do
        ACCOUNT_ID=${account%%|*}
        account=${account#*|}
        ACCOUNT_NAME=${account%%|*}
        if | "$ACCOUNT" == "$ACCOUNT_NAME") &amp;&amp; "$ACCOUNT_ID" == ACC-* 
        then
            connectToAccount
            generateAssetsFile
            disconnectFromAccount
        fi
    done
elif  "$CREATE_VSERVER" == "true" &amp;&amp; \
        "$ACCOUNT" != "" &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" &amp;&amp; \
        "$VSERVER" != "" &amp;&amp; \
        "$VSTYPE" != "" &amp;&amp; \
        "$VSTEMPLATE" != "" &amp;&amp; \
        "$NETWORK_NAMES" != "" &amp;&amp; \
        "$NETWORK_IPS" != "" 
then
    simpleCreateVServer
elif | \
        "$STOP_VSERVER" == "true" || \
        "$START_VSERVER" == "true" || \
        "$RESTART_VSERVER" == "true") &amp;&amp; \
        "$ACCOUNT" != "" &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" &amp;&amp; \
        "$VSERVER" != "" 
then
    getAccounts

    for account in "${accountsArray[@]}"
    do
        ACCOUNT_ID=${account%%|*}
        account=${account#*|}
        ACCOUNT_NAME=${account%%|*}
        if | "$ACCOUNT" == "$ACCOUNT_NAME") &amp;&amp; "$ACCOUNT_ID" == ACC-* 
        then
            connectToAccount
            if  "$DELETE_VSERVER" == "true" 
            then
                simpleDeleteVServer
            elif  "$STOP_VSERVER" == "true" 
            then
                simpleStopVServer
            elif  "$START_VSERVER" == "true" 
            then
                simpleStartVServer
            elif  "$RESTART_VSERVER" == "true" 
            then
                simpleRestartVServer
            fi
            disconnectFromAccount
        fi
    done
elif | \
        "$START_VSERVERS" == "true" || \
        "$REBOOT_VSERVERS" == "true" || \
        "$LIST_VSERVERS" == "true" || \
        "$STATUS_VSERVERS" == "true" || \
        "$LIST_VNETS" == "true" || \
        "$LIST_DISTGRPS" == "true" || \
        "$LIST_TEMPLATES" == "true" || \
        "$LIST_VOLUMES" == "true") &amp;&amp; \
        "$ACCOUNT_USER" != "" &amp;&amp; \
        "$ACCOUNT_PASSWORD" != "" 
then
    getAccounts

    for account in "${accountsArray[@]}"
    do
        ACCOUNT_ID=${account%%|*}
        account=${account#*|}
        ACCOUNT_NAME=${account%%|*}
        if | "$ACCOUNT" == "$ACCOUNT_NAME") &amp;&amp; "$ACCOUNT_ID" == ACC-* 
        then
                connectToAccount
                if  "$STOP_VSERVERS" == "true" 
                then
                        stopVServers
                elif  "$START_VSERVERS" == "true" 
                then
                        startVServers
                elif  "$REBOOT_VSERVERS" == "true" 
                then
                        rebootVServers
                elif  "$LIST_VSERVERS" == "true" 
                then
                        listVServers
                elif  "$STATUS_VSERVERS" == "true" 
                then
                        listVServerStatus
                elif  "$LIST_VNETS" == "true" 
                then
                        listVNets
                elif  "$LIST_DISTGRPS" == "true" 
                then
                        listDistributionGroups
                elif  "$LIST_TEMPLATES" == "true" 
                then
                        listTemplates
                elif  "$LIST_VOLUMES" == "true" 
                then
                        listVolumes
                fi
                disconnectFromAccount
        fi
    done
else
    usage
fi

rm -f $IAAS_PASSWORD_FILE

Add Your Comment