#!/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://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"` #CloudUser used to create vServers & Volumes export IAAS_USER=root 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 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 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 rm -f $KEY_FILE $IAAS_ACCESS_KEY_FILE } ############################################################# ## ## 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" == "$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]" $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" == "$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]" $IAAS_HOME/bin/iaas-start-vservers --vserver-ids $VSERVER_IDS else echo "No vServers to start" 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%%|*} if [[ "$VSERVER" == "" || "$VSERVER" == "$VSERVER_NAME" ]] then if [[ "$VERBOSE" == "true" ]] then echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_ID|"$(echo $vserver | sed 's/_/ /g') 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" == "$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 } ############################################################# ## ## usage ## ===== ## ## Show usage. ## ############################################################# function usage() { echo "" echo >&2 "usage: $0 [-a ] [-v ] -u -p [--verbose] " echo >&2 " -a Name of the Account that contains the Specified vServer." echo >&2 " -u User that is allowed to access the specified account the default is root" echo >&2 " -p password of the specified user" echo >&2 " -v vServer to be templatised or cloned." echo >&2 " -url URL to access the EMOC interface the default is https://localhost." echo >&2 " -h This message." echo >&2 " " echo >&2 "Commands " echo >&2 " " echo >&2 " --list-vservers" echo >&2 " List all the vServers in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the vServers. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " If --verbose is also specified the all available vServer information will be listed." echo >&2 " " echo >&2 " --status-vservers" echo >&2 " List the status all the vServers in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the vServers. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " " echo >&2 " --start-vservers" echo >&2 " Start all or the named -v vServer(s) in the specified Account. If no Account is specified" echo >&2 " then it will loop through all Accounts within the vDC starting the vServers." echo >&2 " " echo >&2 " --stop-vservers" echo >&2 " Stop all or the named -v vServer(s) in the specified Account. If no Account is specified" echo >&2 " then it will loop through all Accounts within the vDC stoping the vServers." echo >&2 " " echo >&2 " --list-vnets" echo >&2 " List all the vNets in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the vNets. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " If --verbose is also specified the all available vNet information will be listed." echo >&2 " " echo >&2 " --list-distgroups" echo >&2 " List all the Distribution Groups in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the Distribution Groups. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " If --verbose is also specified the all available Distribution Group information will be listed." echo >&2 " " echo >&2 " --list-volumes" echo >&2 " List all the Volumes in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the Volumes. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " If --verbose is also specified the all available Volumes information will be listed." echo >&2 " " echo >&2 " --list-templates" echo >&2 " List all the Templates in the specified Account. If no Account is specified then it" echo >&2 " will loop through all Accounts within the vDC listing the Templates. To successfully" echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts." echo >&2 " If --verbose is also specified the all available Template information will be listed." echo"" exit 1 } ############################################################### ## ## Simple start for the script that will extract the parameters ## and call the appriate start function. ## ############################################################### export ACCOUNT_USER="root" export ACCOUNT_PASSWORD="welcome1" export SYSTEMIMGDIR=/mnt/elsystem while [ $# -gt 0 ] do case "$1" in -a) ACCOUNT="$2"; shift;; -v) VSERVER="$2"; shift;; -u) ACCOUNT_USER="$2"; shift;; -p) ACCOUNT_PASSWORD="$2"; shift;; -url) IAAS_BASE_URL="$2"; shift;; --verbose) VERBOSE=true;; --list-vservers) LIST_VSERVERS=true;; --stop-vservers) STOP_VSERVERS=true;; --start-vservers) START_VSERVERS=true;; --status-vservers) STATUS_VSERVERS=true;; --list-vnets) LIST_VNETS=true;; --list-distgroups) LIST_DISTGRPS=true;; --list-templates) LIST_TEMPLATES=true;; --list-volumes) LIST_VOLUMES=true;; *) usage;; *) break;; esac shift done IAAS_USER=$ACCOUNT_USER echo "$ACCOUNT_PASSWORD" > $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 getAccounts for account in "${accountsArray[@]}" do ACCOUNT_ID=${account%%|*} account=${account#*|} ACCOUNT_NAME=${account%%|*} if [[ "$ACCOUNT" == "" || "$ACCOUNT" == "$ACCOUNT_NAME" ]] then connectToAccount if [[ "$STOP_VSERVERS" == "true" ]] then stopVServers elif [[ "$START_VSERVERS" == "true" ]] then startVServers 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