#!/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/' /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 " 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 ] [-r]" echo >&2 "" echo >&2 " -f (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 "**************************************"