Category Archives: Exa Family

Exalogic Installation Series -12- Scripted Template Generation from an existing vServer

As part of your Exalogic Virtual environment you may want to build vServer that will be used, going forwards, as a template for future vServers. Currently the “Exalogic Elastic Cloud Administrator’s Guide” has an appendix describing how this can be achieved using the OVMM interface. Based on internal A-Team work it is now possible to achieve this directly from a compute nodes command-line without accessing OVMM.

As a result of this I have built the script below that will take the files associated with a “Stopped” vServer and converts them to a template.

For this templating process to work the script will need to be executed on a machine with access to the /OVS/Repositories/* directories and this means running directly on one of the Compute Nodes (I generally run it on Compute Node 1).

Because of the space and resource limitations of the Compute Node (minimal OS) we will need to create a and mount a Share from the internal ZFS to save the working files and ultimately the Template. To this end the script will take a number of parameters that will specification of these directories. If these are not specified the script assumes we have the ZFS /export/common/images mounted on /u01/common/images.

As can been seen from the Usage section below the script only mandates the Name of the vServer to be copied but assumes that the user has stopped the vServer previously. Once the template has been created, or post copy, the vServer can be restarted.

CreateTemplateFromVServer.sh

Usage

usage: ./CreateTemplateFromVServer.sh -n <vServer Name> [-r <Repository Directory>] [-w <Working Directory>] [-d <Destination Directory>]

 -n <vServer Name> vServer to be templatised or cloned.
 -r <Repository Directory> Location of the repository the default is /OVS/Repositories/*
 -w <Working Directory> Working directory where intermediate files will be copied default /u01/common/images/vServerTemplateWIP.
 -d <Destination Directory> Directory where the template tgz will be created. Default is /u01/common/images/vServerTemplates
 -h This information.

Script

Download

#!/bin/bash

################################################################################
#
#  Exalogic EL X2-2 2.0.0.4 (Linux x86-64) Configuration Script.
#
#  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 2011 Andrew Hopkinson, Oracle Corporation UK Ltd.
#
################################################################################

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#*:}
 while [[ "$DISKS" != "$FILES" ]]
 do
  #echo "FILES = $FILES"
  #echo "DISKS = $DISKS"
  IMG_FILE=${FILES%%,*}
  echo "Copying $IMG_FILE"
  cp $IMG_FILE $TEMPLATE_DIR
  # Set root imag we assume the first
  if [[ "$ROOT_IMG_FILE" == "" ]]
  then
   SYSTEM_IMG=${IMG_FILE#*VirtualDisks/}
   ROOT_IMG_FILE=$TEMPLATE_DIR/$SYSTEM_IMG
   echo "Root Image $ROOT_IMG_FILE"
  fi
  # Shuffle line for next disk
  DISKS=${DISKS#*:}
  FILES=${DISKS#*:}
 done
}

#############################################################
##
## 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
 # Mount the Image file
 export LOOP=`losetup -f`
 # Make Temp Mount Directory
 mkdir -p $SYSTEMIMGDIR
 # Create Loop for the System Image
 losetup $LOOP $ROOT_IMG_FILE
 kpartx -a $LOOP
 mount /dev/mapper/`basename $LOOP`p2 $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 > etc/sysconfig/ovmd
 rm -v etc/sysconfig/ovmd.orig
 
 sed -i '/.*/d' etc/resolv.conf
 
 # Remove existing ssh information
 rm -v root/.ssh/*
 rm -v etc/ssh/ssh_host*
 
 # Clean up networking
 sed -i '/^GATEWAY/d' etc/sysconfig/network
 
 # Clean up hosts
 sed -i '/localhost/!d' etc/hosts
 sed -i '/localhost/!d' etc/sysconfig/networking/profiles/default/hosts
 
 # 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 > 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
 kpartx -d $LOOP
 losetup -d $LOOP
 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() {
 copyServerFiles
 unconfigureVM
 buildTemplateTgz
 cleanWorkingDir
 echo ""
 echo ""
 echo "****************************************************"
 echo "**"
 echo "** $TEMPLATE_TGZ has been created from"
 echo "** vServer $VSERVER_NAME "
 echo "**"
 echo "****************************************************"
 echo ""
 echo ""
}


function usage() {
 echo ""
 echo >&2 "usage: $0 -n <vServer Name> [-r <Repository Directory>] [-w <Working Directory>] 
 [-d <Destination Directory>] "
 echo >&2 ""
 echo >&2 "          -n <vServer Name> vServer to be templatised or cloned."
 echo >&2 "          -r <Repository Directory> Location of the repository the default is $REPOSITORY_DIR"
 echo >&2 "          -w <Working Directory> Working directory where intermediate files will be copied default 
 $WORKING_DIR."
 echo >&2 "          -d <Destination Directory> Directory where the template tgz will be created. Default is 
 $DESTINATION_DIR"
 echo ""
 exit 1
}

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

export WORKING_DIR="/u01/common/images/vServerTemplateWIP"
export DESTINATION_DIR="/u01/common/images/vServerTemplates"
export REPOSITORY_DIR="/OVS/Repositories/*"
export SYSTEMIMGDIR=/mnt/elsystem

while [ $# -gt 0 ]
do
 case "$1" in 
  -n) VSERVER_NAME="$2"; shift;;
  -r) REPOSITORY_DIR="$2"; shift;;
  -d) DESTINATION_DIR="$2"; shift;;
  -w) WORKING_DIR="$2"; shift;;
  *) usage;;
  *) break;;
 esac
 shift
done


# Processing function call
if [[ "$VSERVER_NAME" == "" || "$REPOSITORY_DIR" == "" ]]
then
 usage
else
 createTemplate
fi



echo "****************************************"
echo "*****  Finished Creating Template  *****"
echo "****************************************"

Exalogic Installation Series -11- Some Simple ZFS Scripts

Whilst working on an Exalogic Upgrade I was working with the ZFS storage and having executed the same commands a number of times I decided to script them. This short blog entry, although it will grow over time, contains the scripts I find useful. For each of the scripts I will simply provide a brief description and the source of the script and occasionally add the output assuming it is not too long. Where I need to pass the Hostname / IP Address of the storage heads the scripts will use the flags:

  • -p <Primary – first storage head>
  • -s <Secondary – Second storage head>

I will be using a combinations of simple bash scripts and the more function ZFS scripting language.

Show Config

Executing this script against one of the storage heads will read and show all the properties that are current set on the specified storage head. Simply redirecting the output to a file provides me with a backup before I execute any modifications.

To run the script you will need to execute the following:

ssh root@<Storage IP> < showConfig.aksh > storageConfig.log

showConfig.aksh

script
function processNode(node) {
    run('cd /');
    run(node);
    printf("*****************************************************\n");
    printf("%s\n", node);
    printf("*****************************************************\n\n");

    printf("%s", run('list'));

    printf("\n\n*****************************************************\n\n");

    var nodeChildren = children();
    for (var i = 0; i < nodeChildren.length; i++) {
        processNode(node + " " + nodeChildren[i]);
        run('cd ..');
    }
}

processNode('');

Show Shares

This script, modified from the ZFS Admin Guide, will display a list of all Projects/Shares on the storage along with the amount of spece used and available.

To run the script you will need to execute the following:

ssh root@<Storage IP> < showShares.aksh

showShares.aksh

script
    run('shares');
    projects = list();
    printf("%-50s %-10s %-10s\n", "Project/Share", "Used", "Available");
    printf("%-50s %-10s %-10s\n", "=============", "====", "=========");
    for (i = 0; i < projects.length; i++) {
        run('select ' + projects[i]);
        shares = list();
        for (j = 0; j < shares.length; j++) {
            run('select ' + shares[j]);
            share = projects[i] + '/' + shares[j];
            used = run('get space_data').split(/\s+/)[3];
            available = run('get space_available').split(/\s+/)[3];
            printf("%-50s %-10s %-10s\n", share, used, available);
            run('cd ..');
        }
        run('cd ..');
    }

showShares.aksh

[root@slce50cn01 ~]# ssh root@slce50sn01 < showShares.aksh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Project/Share Used Available
============= ==== =========
ExalogicControl/ExalogicControl 312G 21.9T
ExalogicControl/ExalogicPool1 1.28G 21.9T
ExalogicControl/ExalogicPool2 31.5K 21.9T
ExalogicControl/ExalogicPool3 31.5K 21.9T
ExalogicControl/ExalogicPool4 31.5K 21.9T
ExalogicControl/ExalogicRepo 1.01T 21.9T
ExalogicControl/Exalogic_EnterpriseController 37.5K 21.9T
ExalogicControl/Exalogic_OVAB 31.5K 21.9T
ExalogicControl/Exalogic_ProxyController 31.5K 21.9T
ExalogicControl/Exalogic_RDBMS 31.5K 21.9T

Set NFSv4 Delegation

The following script will set the NFSv4 Delegation flag to false (recommended) and also the appropriate IPMP values. If you know the location of the value to set then the following should be easy to modify.

To run the script you will need to execute the following:

./setIPMPAndNFSV4Delegation.sh [-s <Secondary Storage Node hostname/IP>] [-p <Primary Storage Node hostname/IP>]

setIPMPAndNFSV4Delegation.sh

#!/bin/bash

PRIMARY=
SECONDARY=

while [ $# -gt 0 ]
do
 case "$1" in 
   -p) PRIMARY="$2"; shift;;
   -s) SECONDARY="$2"; shift;;
   *) echo ""; echo >&2 \
      "usage: $0 [-s <Secondary Storage Node hostname/IP>] [-p <Primary Storage Node hostname/IP>] "
      echo""; exit 1;;
    *) break;;
 esac
 shift
done

function updateStorage {
ssh root@$1 << EOF
cd /
configuration services ipmp
show
set interval=5000
set failback=false
commit
cd /
configuration services nfs
show
set enable_delegation=false
commit
quit
EOF
}

if [ "$PRIMARY" != "" ]
then
 updateStorage $PRIMARY
fi

if [ "$SECONDARY" != "" ]
then
 updateStorage $SECONDARY
fi

Snapshot ZFS Project or Share

This script will allow you to create a snapshot of a ZFS Project or Share on the internal storage. You have the option of specifying the Snapshot name but if this is not supplied it will default to a date stamped name.

To run the script you will need to execute the following:

snapshotZFS.sh -ip <Storage Node hostname/IP> -p <Project Name> [-s <Share Name>] [-n <Snapshot Name>]

snapshotZFS.sh

#!/bin/bash

BAK_EXT=`date +"%Y%m%d-%H%M%S"`
PROJECT=""
SHARE=""
IPADDRESS=""
SNAPSHOTNAME="SnapShot-$BAK_EXT"

while [ $# -gt 0 ]
do
    case "$1" in 
        -ip) IPADDRESS="$2"; shift;;
        -p) PROJECT="$2"; shift;;
        -s) SHARE="$2"; shift;;
        -n) SNAPSHOTNAME="$2"; shift;;
        *) echo ""; echo >&2 \
            "usage: $0 -ip <Storage Node hostname/IP> -p <Project Name> [-s <Share Name>] [-n <Snapshot Name>] "
            echo""; exit 1;;
        *) break;;
    esac
    shift
done

if [ "$IPADDRESS" == "" ]
then
    echo "IP Address or Hostname of the Storage must be provided"
    exit 1
fi

if [ "$PROJECT" == "" ]
then
    echo "Project name must be provided"
    exit 1
fi

echo $SNAPSHOTNAME

ssh root@$IPADDRESS <<EOF
script
    try {
        run('cd /');
        run('shares');
        run('select $PROJECT');
        printf('%s\n', run('list'));
        try {
            run('select $SHARE');
        } catch (e) {
        }
        run('snapshots');
        run('snapshot $SNAPSHOTNAME');

    } catch (err) {
        if (err.code == EAKSH_ENTITY_BADSELECT) {
            printf('ERROR: "$SHARE" is not a share in the "$PROJECT" project\n');
        } else {
            printf('ERROR: (%s)\n', err.message);
        }
    }
EOF

Exalogic Installation Series -10- Scripting Asset Creation

So far in this series we have looked at creating asset within the EMOC BUI but the Exalogic 2.0.1 installation also provide the Iaas cli as an alternative to most of the common functionality available within EMOC. The IaaS cli interface provides access to the functions that are available to a user logged into the BUI with the CloudUser Role.

As such not all functionality is available from the command line interface however having said that the IaaS cli provides all the functionality required to create the Assets within a specific Account (Tenure). Because these action are common and repeatable I decided to wrap the functionality within a simple script that takes a simple input file and creates the Asset.

Following the Script through will show us the required steps needed to create the various Assets within an Account and hence I will work through the various functions within the script below describing the steps.

You will note from the various steps within the script that it is designed to pause between actions allowing the proceeding action to complete. The reason for this is because we could swamp EMOC with a series of actions and may end up with a situation where we are trying to action a Volume attached before the creation of the vServer and Volume have completed.

processAssets()

This function simply reads through the passed input file identifying what assets need to be created. An example of the input file can be found below. It can be seen that the input file can be used to create Assets in multiple Accounts during a single run. The order of the entries define the functions that need to be actioned as follows:

Input Command Iaas Actions Parameters
Production:Connect
  1. akm-describe-accounts
  2. akm-create-access-key
  3. iaas-create-key-pair
  4. iaas-describe-vnets
  5. iaas-describe-vserver-types
  6. iaas-describe-server-templates
  1. Username
  2. Password
Production:Upload|ServerTemplate
  1. iaas-create-server-template-from-url
  1. Template Name
  2. URL to the template (best if placed on the internal ZFS)
Production:Create|VirtualNetwork
  1. iaas-create-vnet
  1. Network Name
  2. Size (Number of IPs)
Production:Create|DistributionGroup
  1. iaas-create-distribution-group
  1. Distribution Group Name

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

Production:Create|vServer
  1. iaas-run-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 automaticallty the a “*” should be entered.
  6. Distribution Group [Optional]
Production:Create|Volume
  1. iaas-create-volume
  1. Volume Name
  2. Volume Size
Production:Attach|Volume
  1. iaas-attach-volumes-to-vserver
  1. vServer Name
  2. Comma separated list of volume names
Production:Disconnect
  1. iaas-delete-key-pair
  2. akm-delete-access-key
None

 

connectToAccount()

It can be seen from the connectToAccount function that before we can execute any Asset creation we must first connect to the appropriate account. To do this we will need the ID associated with the Account. This can be found by executing the akm-describe-accounts cli command which will return a list of all Accounts and there IDs. Once we have the Account ID we generate and Access key using the akm-create-access-key command and then a keypair with the iaas-create-key-pair command.

At this point we now have all the information we need to access the specific named account.

createDistributionGroup()

Here we simply retrive the name of the Distribution Group from the input line and create a group. The size of the group is not specified and will always be 50000.

createVServer()

This function simply retrieved the information from the input line and then will create the vServer using the iaas-run-vserver cli command. Reading the function you will notice that it takes the various input names for vServer Type, Template and Networks and converts them into the appropriate IDs. The IaaS cli will not work directly with component names and hence all IDs need to be found.

createVolume()

Function that simply takes the Volume name and Size then executes the iaas-create-volume command to create the volume.

attachVolume()

Takes the name of the Volume, which we may have just created, and a Volume then identifies the appropriate IDs before assigning the Volume to the vServer with the iaas-attach-volumes-to-vserver.

disconnectFromAccount()

Once we have finished connecting to the Account we simply remove the key pair with iaas-delete-key-pair and the access key with akm-delete-access-key although it may be useful to keep this if ssh is required and you do not subsequently modify the sshd information to allow unsecured access. By default the key is required for ssh access when a vServer is created from the command-line.

CreateAssets.sh

Usage

usage: ./CreateAssets.sh [-f <Asset Definition File>] [-r]

 -f <Asset Definition File> (Default is CreateAssets.in)
 -r Indicates that the ssh keys should be removed
 -h This message

Script

Download

#!/bin/bash

################################################################################
#
#  Exalogic EL X2-2 2.0.0.4 (Linux x86-64) Configuration Script.
#
#  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 2011 Andrew Hopkinson, Oracle Corporation UK Ltd.
#
################################################################################

export OCCLI=/opt/sun/occli/bin
export IAAS_HOME=/opt/oracle/iaas/cli
export IAAS_BASE_URL=https://127.0.0.1
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"`
#CloudUser used to create vServers & Volumes
export IAAS_USER=exaprod
export IAAS_PASSWORD_FILE=root.pwd
export INPUT_FILE=CreateAssets.in

export ACCOUNTS_FILE=accounts.out
export VOLUMES_FILE=volumes.out
export DISTGRPS_FILE=distgrp.out
export VNETS_FILE=vnets.out
export VSERVER_TYPES_FILE=vstype.out
export VSERVER_FILE=vserver.out
export VSERVER_TEMPLATES=template.out
export NETWORK_STATIC_IPS=staticips.out
export KEY_PAIRS=keypairs.out


PROCESSING_ACCOUNT=""

function cleanTempFiles() {
 rm -f $ACCOUNTS_FILE $VOLUMES_FILE $DISTGRPS_FILE $VNETS_FILE $VSERVER_TYPES_FILE $VSERVER_FILE 
$VSERVER_TEMPLATES $KEY_PAIRS $IAAS_PASSWORD_FILE $IAAS_ACCESS_KEY_FILE
 #$KEY_FILE
}

function connectToAccount() {
 if [[ "$ACCOUNT" != "$PROCESSING_ACCOUNT" ]]
 then
  if [[ "" != "$PROCESSING_ACCOUNT" ]]
  then
   $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
  fi
  # Set run specific key information
  export IAAS_ACCESS_KEY_FILE=$ACCOUNT"."$RUN_DATE"."$BASE_IAAS_ACCESS_KEY_FILE
  export KEY_NAME=$ACCOUNT"."$RUN_DATE"."$BASE_KEY_NAME
  export KEY_FILE=$ACCOUNT"."$RUN_DATE"."$BASE_KEY_FILE
  #echo "IAAS_ACCESS_KEY_FILE=$IAAS_ACCESS_KEY_FILE"
  #echo "KEY_NAME=$KEY_NAME"
  echo "KEY_FILE=$KEY_FILE"
  # Save current processing account
  PROCESSING_ACCOUNT=$ACCOUNT
  IAAS_USER=$ACCOUNT_USER
  echo "$ACCOUNT_PASSWORD" > $IAAS_PASSWORD_FILE
  $IAAS_HOME/bin/akm-describe-accounts --sep "|" > $ACCOUNTS_FILE
  while read line
  do
   ACCOUNT_ID=${line%%|*}
   line=${line#*|}
   ACCOUNT_NAME=${line%%|*}
 #  echo "Id = $ACCOUNT_ID"
 #  echo "Name = $ACCOUNT_NAME"
   if [[ "$ACCOUNT_NAME" == "$ACCOUNT" ]]
   then
    #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"
    
    #cp $IAAS_ACCESS_KEY_FILE $ACCOUNT_NAME$IAAS_ACCESS_KEY_FILE
    #cp $KEY_FILE $ACCOUNT_NAME$KEY_FILE
    break
   fi    
  done < $ACCOUNTS_FILE 
 fi
}

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
  PROCESSING_ACCOUNT=""
  # Clean Up
  cleanTempFiles
}

function getDistributionGroups() {
 $IAAS_HOME/bin/iaas-describe-distribution-groups --sep "|" > $DISTGRPS_FILE
}

function getNetworks() {
 $IAAS_HOME/bin/iaas-describe-vnets --sep "|" > $VNETS_FILE
}

function getVSTypes() {
 $IAAS_HOME/bin/iaas-describe-vserver-types --sep "|" > $VSERVER_TYPES_FILE
}

function getTemplates() {
 $IAAS_HOME/bin/iaas-describe-server-templates --sep "|" > $VSERVER_TEMPLATES
}

function getVolumes() {
 $IAAS_HOME/bin/iaas-describe-volumes --sep "|" > $VOLUMES_FILE
}

function getVServers() {
 $IAAS_HOME/bin/iaas-describe-vservers --sep "|" > $VSERVER_FILE
}

function getNetworkStaticIPs() {
 $IAAS_HOME/bin/iaas-describe-ip-addresses --filters vnet=$NETWORK_ID --sep "|" > $NETWORK_STATIC_IPS
}

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

function getDistributionGroupId() {
 while read line
 do
  DISTGROUP_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$NAME" == "$DISTGROUP_NAME" ]]
  then
   break
  fi
  DISTGROUP_ID=""
 done < $DISTGRPS_FILE
}

#############################################################
##
## getNetworkId
## ============
##
## Get the Network id based on the supplied name.
##
#############################################################

function getNetworkId() {
 while read line
 do
  NETWORK_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$NAME" == "$NETWORK_NAME" ]]
  then
   break
  fi
  NETWORK_ID=""
 done < $VNETS_FILE
}

#############################################################
##
## 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
#  getFirstAllocatedIPAddress
 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`
}

function allocateIPAddresses() {
 $IAAS_HOME/bin/iaas-allocate-ip-addresses --vnet $NETWORK_ID --num $IP_COUNT
}

#############################################################
##
## getFirstAllocatedIPAddress
## ==========================
##
## Get the first static IP Address for a given Network Id.
##
#############################################################

function getFirstAllocatedIPAddress() {
 getNetworkStaticIPs
 while read line
 do
  IP_ADDRESS=${line%%|*}
  break
 done < $NETWORK_STATIC_IPS
}

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

function getVSTypeId() {
 while read line
 do
  VSTYPE_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$VSTYPE_NAME" == "$NAME" ]]
  then
   break
  fi
  VSTYPE_ID=""
 done < $VSERVER_TYPES_FILE
}

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

function getTemplateId() {
 while read line
 do
  TEMPLATE_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$TEMPLATE_NAME" == "$NAME" ]]
  then
   break
  fi
  TEMPLATE_ID=""
 done < $VSERVER_TEMPLATES
}

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

function getVolumeId() {
 while read line
 do
  VOLUME_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$NAME" == "$VOLUME_NAME" ]]
  then
   break;
  fi
  VOLUME_ID=""
 done < $VOLUMES_FILE
}

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

function getVServerId() {
 while read line
 do
  VSERVER_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  if [[ "$VSERVER_NAME" == "$NAME" ]]
  then
   break;
  fi
  VSERVER_ID=""
 done < $VSERVER_FILE
}

function getVServerState() {
 getVServers
 while read line
 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 < $VSERVER_FILE
}

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....."
    #echo "Will Delete $NAME in 5 Minutes....."
    #sleep 300
    #deleteVServer
    #echo "Deleted $NAME waiting 5 Minutes....."
    #sleep 300
    break
   fi
   getVServerState
   #echo "Description: [$DESCRIPTION]"
  done
  echo "$NAME $VSERVER_STATE"
  # Lets pause for a minute or two
  echo "Just Chilling......"
  sleep 30
  echo "Ahhhhh we're getting there......."
  sleep 30
  echo "I'm almost at one with the universe......."
  sleep 30
  echo "Bong Reality Check !"
}

function deleteVServer() {
 $IAAS_HOME/bin/iaas-terminate-vservers --force --vserver-ids $VSERVER_ID
}

function createVServer() {
 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%%|*}
 
 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 addres 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
 
 # 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 "Created By CreateAsset.sh"
 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 "Created By CreateAsset.sh"
 fi
 pauseUntilVServerRunning
 if [[ "$REMOVE_SSH_KEYS" == "true" ]]
 then
  removeSshKeyRequirement
 fi
 
 echo "vServer $VSERVER_NAME has been created"
}

function removeSshKeyRequirement() {
 SSH_FLAGS="-i $KEY_FILE -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
 SSH_FLAGS="-i $KEY_FILE -o StrictHostKeyChecking=no"
 # Create Variables as environment variables
 #export NETWORK_IPS=$NETWORK_IPS
 #export VSERVER_NAME=$VSERVER_NAME

 SSH_IP_ADDRESS=""
 for IP in ${NETWORK_IPS//,/ }
 do
  SSH_RESULT=$(ssh $SSH_FLAGS root@$IP "hostname")
  echo "SSH Result $SSH_RESULT"
  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 "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 > /etc/ssh/sshd_config"
  ssh $SSH_FLAGS root@$SSH_IP_ADDRESS "service sshd restart"

  echo "Removed ssh key requirement for $VSERVER_NAME"
 else
  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 <IP Address>"
  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 > 
  /etc/ssh/sshd_config"
  echo "service sshd restart"
  echo ""
 fi
}

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

function createDistributionGroup() {
 DISTGROUP_NAME=${ASSET_DETAILS%%|*}
 ASSET_DETAILS=${ASSET_DETAILS#*|}
 # Size is never specified
 # DISTGROUP_SIZE=${ASSET_DETAILS%%|*}
 # Create Volume
 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
}

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

}

function createVolume() {
 VOLUME_NAME=${ASSET_DETAILS%%|*}
 ASSET_DETAILS=${ASSET_DETAILS#*|}
 VOLUME_SIZE=${ASSET_DETAILS%%|*}
 # 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
}

function attachVolume() {
 VSERVER_NAME=${ASSET_DETAILS%%|*}
 ASSET_DETAILS=${ASSET_DETAILS#*|}
 VOLUME_NAMES=${ASSET_DETAILS%%|*}
 # 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
}

#############################################################
##
## 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
 while read line
 do
  TEMPLATE_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  line=${line#*|}
  line=${line#*|}
  TEMPLATE_STATE=${line%%|*}
  if [[ "$TEMPLATE_NAME" == "$NAME" ]]
  then
   break;
  fi
 done < $VSERVER_TEMPLATES
}

#############################################################
##
## 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
}

#############################################################
##
## 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() {
 TEMPLATE_NAME=${ASSET_DETAILS%%|*}
 ASSET_DETAILS=${ASSET_DETAILS#*|}
 TEMPLATE_URL=${ASSET_DETAILS%%|*}
 # 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
}

#############################################################
##
## 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
 while read line
 do
  NETWORK_ID=${line%%|*}
  line=${line#*|}
  NAME=${line%%|*}
  line=${line#*|}
  line=${line#*|}
  NETWORK_STATE=${line%%|*}
  if [[ "$NETWORK_NAME" == "$NAME" ]]
  then
   break;
  fi
 done < $VNETS_FILE
}

#############################################################
##
## 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
}

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

function createVirtualNetwork() {
 NETWORK_NAME=${ASSET_DETAILS%%|*}
 ASSET_DETAILS=${ASSET_DETAILS#*|}
 NETWORK_IPS=${ASSET_DETAILS%%|*}
 # 
 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
}

#############################################################
##
## processAssets
## =============
##
## 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 processAssets() {
 # Read Entries into an Array
 assetArray=( $(grep ":" $INPUT_FILE) )
 # Process Array
 for line in "${assetArray[@]}"
 #while read line
 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%%|*}
   connectToAccount
   
   ## Account Info
   getNetworks
   getVSTypes
   getTemplates
  elif [[ "$ACTION" == "Create" ]]
  then
   ASSET=${line%%|*}
   line=${line#*|}
   ASSET_DETAILS=$line
   if [[ "$ASSET" == "vServer" ]]
   then
    getDistributionGroups
    createVServer
   elif [[ "$ASSET" == "vServers" ]]
   then
    getDistributionGroups
    createVServers
   elif [[ "$ASSET" == "Volume" ]]
   then
    createVolume
   elif [[ "$ASSET" == "DistributionGroup" ]]
   then
    createDistributionGroup
   elif [[ "$ASSET" == "VirtualNetwork" ]]
   then
    createVirtualNetwork
   fi
#   continue
  elif [[ "$ACTION" == "Upload" ]]
  then
   ASSET=${line%%|*}
   line=${line#*|}
   ASSET_DETAILS=$line
   if [[ "$ASSET" == "ServerTemplate" ]]
   then
    uploadServerTemplate
   fi
#   continue
  elif [[ "$ACTION" == "Attach" ]]
  then
   ASSET=${line%%|*}
   line=${line#*|}
   ASSET_DETAILS=$line
   if [[ "$ASSET" == "Volume" ]]
   then
    getVolumes
    getVServers
    attachVolume
   fi
#   continue
  elif [[ "$ACTION" == "Disconnect" ]]
  then
   disconnectFromAccount
#   continue
  fi
 #done < $INPUT_FILE
 done
}

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

function usage() {
 echo ""
 echo >&2 "usage: $0 [-f <Asset Definition File>] [-r]"
 echo >&2 ""
 echo >&2 "          -f <Asset Definition File> (Default is CreateAssets.in)"
 echo >&2 "          -r Indicates that the ssh keys should be removed"
 echo ""
 exit 1
}

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

REMOVE_SSH_KEYS=false
while [ $# -gt 0 ]
do
 case "$1" in 
  -f) INPUT_FILE="$2"; shift;;
  -r) REMOVE_SSH_KEYS=true;;
  *) usage;;
  *) break;;
 esac
 shift
done

# 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
# Processing function call
processAssets

echo "**************************************"
echo "*****  Finished Creating Assets  *****"
echo "**************************************"

CreateAssetsProd.in

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|VS007|VSTProduction|Navstar40GBRootTemplate|EoIB1-client-access,IPoIB-vserver
-shared-storage,VN001|10.242.96.68,172.17.0.35,*|DG001
Production:Create|vServer|VS002|VSTProduction|Navstar40GBRootTemplate|EoIB1-client-access,IPoIB-vserver
-shared-storage|10.242.96.72,*
Production:Create|vServer|VS003|VSTProduction|Navstar40GBRootTemplate|EoIB1-client-access,IPoIB-vserver
-shared-storage|10.242.96.75,*

Production:Create|Volume|VS006|5
Production:Create|Volume|VS007|5
Production:Create|Volume|VS002|5
Production:Create|Volume|VS003|5

Production:Attach|Volume|VS006|VS006
Production:Attach|Volume|VS007|VS007
Production:Attach|Volume|VS002|VS002
Production:Attach|Volume|VS003|VS003

Production:Disconnect

Post Creation

By default the vServers are created, for security, with Public key Authentication enabled. If you want to turn this functionality off you will need to use the “-r” flag. If this fails because the script can not access the vServer from the location where it has been executed then you will need to do this manually as follows. Open a console started from EMOC to modify the sshd_config paramters; as follows:

  1. Open EMOC.
  2. Right-click on your new vServer and select “Launch Virtual Console” and wait until it opens.
  3. Edit the /etc/ssh/sshd_config file and set the following values:
    1. PasswordAuthentication yes
  4. Restart the sshd using:

    /etc/init.d/sshd reload

Exalogic Installation Series -9- Creating a ModifyJeOS VirtualBox

Exalogic Virtual Tea Break Snippets – Creating a ModifyJeOS VirtualBox

Following on from my previous blog entry “Modifying the Base Template” I decided to put together a quick blog to show how to create a small VirtualBox, guest, that can be used to execute the ModifyJeOS and hence edit you templates. One of the main advantages of this is that Templates can be created away from the Exalogic Environment. For the Guest OS I chose Oracle Linux 6u3 and decided to create it as a basic server because I did not require a graphical interface but it’s a simple change to create it with a GUI.

Required Software

Creating the VM

I’ll assume that the reader is experienced with Virtual Box and installing Oracle Linux and hence will make this section brief.

Create VirtualBox Guest

Create a new VirtualBox Guest and select oracle Linux 64 bit. Follow through the create process and select Dynamic Disk Size and the default 12GB disk size. The actual image will be a lot smaller than this but the Oracle Linux install will fail with insufficient disk space if you attempt a smaller size.

VBox

Once the guest has been created attach the previously downloaded Oracle Linux  u3 iso to the cd drive and start the guest.

Install Oracle Linux

On starting the guest the system will boot off the associated Oracle Linux  u3 iso and take you through the standard installation process. Select all the appropriate information but when you reach the installation type select Basic Server because we do not need that additional packages and only need to access through the command line interface.

OEL

Complete the installation and reboot the Guest. At this point we now have a basic Oracle Linux server running.

Installing Guest Add-ons

Before we can easily access the Guest we will need to add the VirtualBox guest add-ons. These will provide better keyboard and mouse integration and allow access the shared folders on the host machine. Before we can do this we will need to do the following:

  1. Enable Networking.
  2. Install additional rpms.

To enable the networking (eth0), that appears to be disabled by default, we can execute:

ifup eth0
Network

This will start the eth0 connection but once the Guest is rebooted the network will be down again. To resolve this you will need to edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file and change the ONBOOT parameter to “yes”.

Now we have enabled the network we will need to install a number of addition rpm. First we will need to configure the yum repository (/etc/yum.repos.d) as follows:

[ol6_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=1

[ol6_ga_base]
name=Oracle Linux $releasever GA installation media copy ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/0/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=0

[ol6_u1_base]
name=Oracle Linux $releasever Update 1 installation media copy ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/1/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=0

[ol6_u2_base]
name=Oracle Linux $releasever Update 2 installation media copy ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/2/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=0

[ol6_u3_base]
name=Oracle Linux $releasever Update 3 installation media copy ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/3/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=0

[ol6_UEK_latest]
name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/UEK/latest/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=1

[ol6_UEK_base]
name=Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)
baseurl=http://public-yum.oracle.com/repo/OracleLinux/OL6/UEK/base/$basearch/
gpgkey=http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6
gpgcheck=1
enabled=0

Once the repository has been edited we will need to execute the following yum commands:

yum update
yum install gcc
yum install kernel-uek-devel
yum install kernel-devel
yum install createrepo

At this point we now have all the additional packages required to install the VirtualBox Guest Add-ons.

So select Devices->InstallGuest Additions on you running guest:

Add-ons

This will simply place the VirtualBoxGuestAdditions.iso in the virtual cd and we will need to execute the following before we can run them.

mkdir /media/cdrom
mount -t iso9660 -o ro /dev/cdrom /media/cdrom
cd /media/cdrom/
ls
./VBoxLinuxAdditions.run
add-ons

This will initiate the install and kernel rebuild. What you will notice is that during the installation a Failed will be displayed but this is simply because we have no graphical components.

Failed

At this point we the installation will also have added the vboxsf group to the system and to access any shared folders we will create our user will need to be a member of this group an so the next stage is to add the root user to this group as follows:

usermod -G vboxsf root

cat /etc/group
cat /etc/passwd
init 0

Now simply shutdown the guest and add the Shared folder within your guests settings.

Install ModifyJeOS

Once the shared folder has been added restart the guest and change directory into the shared folder (/media/sf_<folder name>). For the next step I am assuming the ModifyJeOS rpms are located in the shared folder. We can simply execute:

rpm -ivh ovm-modify-jeos-1.1.0-17.el5.noarch.rpm

# Test with

modifyjeos
modifyjeos

Using ModifyJeOS

I have a modified MountSystemImg.sh script that should be copied into the /root/bin directory (you may need to create this) and from here it can be executed from any location:

MountSystemImg.sh
#!/bin/sh

# The script assumes it's being run from the directory containing the System.img

# Export for later i.e. during unmount
export LOOP=`losetup -f`
export SYSTEMIMGDIR=/mnt/elsystem
export SYSTEMIMG=System.img
export TEMPLATEDIR=`pwd`

# Read Parameters
while [ $# -gt 0 ]
do
 case "$1" in
  -i) SYSTEMIMG="$2"; shift;;
  *) echo ""; echo >&2 \
      "usage: $0 [-i <System Image Name (Default System.img)> "
      echo""; exit 1;;
  *) break;;
 esac
 shift
done

# Make Temp Mount Directory
mkdir -p $SYSTEMIMGDIR
# Create Loop for the System Image
losetup $LOOP $SYSTEMIMG
kpartx -a $LOOP
mount /dev/mapper/`basename $LOOP`p2 $SYSTEMIMGDIR
#Change Dir into mounted Image
cd $SYSTEMIMGDIR
echo "######################################################################"
echo "###                                                                ###"
echo "### Starting Bash shell for editing. When completed log out to     ###"
echo "### Unmount the System.img file.                                   ###"
echo "###                                                                ###"
echo "######################################################################"
echo
bash
cd ~
cd $TEMPLATEDIR
umount $SYSTEMIMGDIR
kpartx -d $LOOP
losetup -d $LOOP
rm -rf $SYSTEMIMGDIR

This script will simple create a mount directory, mount the System.img and then start a new shell in the mounted directory. On exiting the shell it will unmount the System.img. It only requires that you execute the script in the directory containing the System.img. These can be created under the mounted shared directory.

In the example below I have extracted the Base template within the shared folder and then renamed it OEL_40GB_ROOT before changing into that directory and executing the script.

mount

Modifying Files in the System.img

Once you have mounted the System.img script, above, you will be placed in a bash shell and located in the /mnt/elsystem directory. This directory represents the root of the System.img file and from here we can access the various files within, what will be, the vServers file system.

ls

One thing that we need to remember is to remove the / when editing files or creating links and so :

vi /etc/hosts becomes vi etc/hosts
vi /etc/fstab becomes vi etc/fstab

When creating links these must all be done as relative link so to set the System Time Zone we would normally execute:

ln -sf /usr/share/zoneinfo/GMT /etc/localtime

But this is replaced with:

cd etc
ln -sf ../usr/share/zoneinfo/GMT localtime

Exalogic Installation Series -8- Allocating Static IP Addresses

By default once a Network has been created within the Enterprise Manager Ops Centre (EMOC) it can be allocated to vServers during their creation. At this point an IP Address will be allocated automatically from the pool of Allocated IPs associated with the Network and Account combination.

In many customer solutions the vServers will need to be allocated a specific IP address so that they can be accessed externally at a know location. To achieve this we must Allocate a number of vIPs within the range allocated to the Account. This is done on an Account by Account basis as follows.

Select Account Network Tab

As the appropriate CloudUser select the Account you have access to and then within the Centre Pane select the Networks Tab. You will see all the Public and Private Networks that are available to this Account. Select one of your networks, in the case below the EoIB-PROD-APPS, and the then press the “Allocate vIPs” button hilighted below.

Static IP

Allocate vIP Address

Selecting the Allocated vIP Addresses button will start the wizard and allow you to specify the number of IP Addresses to be reserved for Static assignment to vServers. The Wizard will allow you to reserve a specified number of IPs up to the number not allocated to vServers within this account.

Static IPs

Once a value is selected the Allocate vIP button will display the IPs available for static allocation before the user accepts them.

Static IP

If you need all the IPs for static allocation then this step should be done before any vServers have been created that use this Network. As you can see from the images above because I did not select all available, and a number of vServers have already been created for this Account, the reserved IP addresses are not contiguous.

Allocating to a vServer

Once the Static IPs have been reserved then they will be available for Allocation during the creation of vServer. If the users is creating a single vServer then the vServer Creation Wizard will allow the user to select the IP addresses. By default “automatic” will be selected in the Method Allocation drop-down but changing this to “Static IP” will cause the reserved IPs to be displayed in a drop-down under “IP Address” and the user can select a specific IP address for this vServer. Once an IP address is allocated to a vServer it will no-longer appear in the drop-down.

Static IP

Deallocating IPs

If it is decided that IPs should no-longer be allocated from a static list then the user can release the unallocated to back to the pool of available IPs for auto allocation. This is achieved in a similar manner to allocating those IPs by first selecting the appropriate  account and then the Network tab. Once on the Network tab the appropriate network can be selected followed by the “Deallocate IPs” button. This will initiate the deallocation wizard that will first show all available, i.e. unallocated, IPs and the user must select all those to be returned to the pool.

Deallocatedeallocate

Once the Ips have been selected for deallocation then pressing the Deallocate button will present them to the user for confirmation before returning them to the pool.