Exalogic Virtual Tea Break Snippets - Wrapping the Exalogic iaas cli

Having worked with the Exalogic Command Line for a while I decided to wrap some of the common functions in a simplified bash script. This saves me creating the keys, connecting and identifying the appropriate Ids. Instead I can simply specify the Name and the script will do the rest of the work. This initial version has just a few commands in it but as I add more the blog entry will expand, as will the script, and document the new functionality.

Commands

All the Command below will work against the whole vDC unless they are restricted to an Account by using the -a option or a vServer by using the -v option. For all actions the script requires a User and password to be passed.

--list-vservers

This command will work through all the Accounts on a given vDC and display the vServers that are available within that Account. Issuing the command in it's simplest form, below, will display the following:

[root@ec1-vm ~]# ./SimplifiedCli.sh -u root -p password --list-vservers
JAVA_HOME is not defined using /usr/java/latest
GlobalResources|LB-2
GlobalResources|nis-vserver-s
GlobalResources|JOI28GB
GlobalResources|nis-vserver-m
GlobalResources|dns
GlobalResources|LB-1

Andrew|VS002
Andrew|VS003

UliAccount|test-vm
UliAccount|sc-tvm
UliAccount|uliAdmin
UliAccount|otd-tvm
UliAccount|nis-tvm
UliAccount|wcdb-vm
UliAccount|lvm-tvm
UliAccount|sc-vm1
UliAccount|wc-vm1
UliAccount|sc-vm3
UliAccount|sc-vm2
UliAccount|wc-vm2

FAPoc|FA-DB
FAPoc|FA-01
FAPoc|OTD01
FAPoc|FA-02
FAPoc|FA-IDM
FAPoc|FA-03

Users can also specify that a Verbose format be used (--verbose) which will print the full set of information available for the given vServers as below.

[root@ec1-vm ~]# ./SimplifiedCli.sh -u root -p password --list-vservers --verbose -a Andrew
JAVA_HOME is not defined using /usr/java/latest
Andrew|VS002|VSRV-616bdf32-2a92-44e4-a9ea-862d0b97c0bb|VS002|Created By CreateAsset.sh|RUNNING|VNET-52a60524-d7e6-4e3f-8204-8cf8bb798ddb,VNET-1b2402d7-9010-45db-a887-4b955377584d|10.242.96.72,172.17.0.40|TMPL-a06a1406-cf5a-479d-a3ea-7c8657bb4013|ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrGYXTkLFoahLbmc4AfCCGqjfwERUubU+TyBk5jyMq46L0eqILhQuRKBRwGp1YbvlEbeFFgQkoR11wJCw7L5wZCNXE99dY1Iya7cst68TgajMlRAunlyD7owGC2ICvTsR3aqzdOtZ6xdXPB6OEYkTI+HLBAKAdZsPdQdb6oI3eKiNzX0FcJHFT68WNuOiaD0aALV1Ct81tkAkDpLNRlag9Pt|2006|true
Andrew|VS003|VSRV-5ab971c4-1bad-4cee-8575-7e80a68ef0b3|VS003|Created By CreateAsset.sh|RUNNING|VNET-1b2402d7-9010-45db-a887-4b955377584d,VNET-52a60524-d7e6-4e3f-8204-8cf8bb798ddb|172.17.0.36,10.242.96.75|TMPL-a06a1406-cf5a-479d-a3ea-7c8657bb4013|ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrGYXTkLFoahLbmc4AfCCGqjfwERUubU+TyBk5jyMq46L0eqILhQuRKBRwGp1YbvlEbeFFgQkoR11wJCw7L5wZCNXE99dY1Iya7cst68TgajMlRAunlyD7owGC2ICvTsR3aqzdOtZ6xdXPB6OEYkTI+HLBAKAdZsPdQdb6oI3eKiNzX0FcJHFT68WNuOiaD0aALV1Ct81tkAkDpLNRlag9Pt|2006|true

--status-vservers

Issuing the status command will cause the script to loop through the vServers within the vDC Accounts and simply display the current status of the vServer.

[root@ec1-vm ~]# ./SimplifiedCli.sh -u root -p password --status-vservers
JAVA_HOME is not defined using /usr/java/latest
GlobalResources|LB-2|RUNNING
GlobalResources|nis-vserver-s|RUNNING
GlobalResources|JOI28GB|SHUTDOWN
GlobalResources|nis-vserver-m|RUNNING
GlobalResources|dns|RUNNING
GlobalResources|LB-1|RUNNING

Andrew|VS002|RUNNING
Andrew|VS003|RUNNING

UliAccount|test-vm|RUNNING
UliAccount|sc-tvm|SHUTDOWNDETACHED
UliAccount|uliAdmin|RUNNING
UliAccount|otd-tvm|RUNNING
UliAccount|nis-tvm|RUNNING
UliAccount|wcdb-vm|RUNNING
UliAccount|lvm-tvm|RUNNING
UliAccount|sc-vm1|RUNNING
UliAccount|wc-vm1|RUNNING
UliAccount|sc-vm3|RUNNING
UliAccount|sc-vm2|RUNNING
UliAccount|wc-vm2|RUNNING

FAPoc|FA-DB|RUNNING
FAPoc|FA-01|SHUTDOWNDETACHED
FAPoc|OTD01|SHUTDOWNDETACHED
FAPoc|FA-02|SHUTDOWNDETACHED
FAPoc|FA-IDM|RUNNING
FAPoc|FA-03|SHUTDOWNDETACHED

--stop-vservers

The stop-vservers will use the cli to force a shutdown of the vservers. By default this will loop through all vServers in the vDC an stop them on an Account by Account basis.

--start-vservers

The start-vservers will use the cli to force a shutdown of the vservers. By default this will loop through all vServers in the vDC an start them on an Account by Account basis.

Script

Usage

usage: ./SimplifiedCli.sh [-a <Account Name>] [-v <vServer Name>] -u <Account User> -p <Account Password> [--verbose] <Command>
 -a <Account Name> Name of the Account that contains the Specified vServer.
 -u <Account User> User that is allowed to access the specified account the default is root
 -p <Account Password> password of the specified user
 -v <vServer Name> vServer to be templatised or cloned.
 -h This message.

Commands

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

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

 --start-vservers
 Start all or the named -v vServer(s) in the specified Account. If no Account is specified
 then it will loop through all Accounts within the vDC starting the vServers.

 --stop-vservers
 Stop all or the named -v vServer(s) in the specified Account. If no Account is specified
 then it will loop through all Accounts within the vDC stoping the vServers.

Download

 1 #!/bin/bash
2
3 ################################################################################
4 #
5 # Exalogic EL X2-2 2.0.0.4 (Linux x86-64) Configuration Script.
6 #
7 # HEADER START
8 # 
9 # THIS SCRIPT IS PROVIDED ON AN ?AS IS? BASIS, WITHOUT WARRANTY OF ANY KIND, 
10 # EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT 
11 # THE COVERED SCRIPT IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR 
12 # PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE 
13 # OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE 
14 # DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER 
15 # CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION.
16 # NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS 
17 # DISCLAIMER.
18 #
19 # When distributing this Code, include this HEADER in each file.
20 # If applicable, add the following below this this HEADER, with the fields
21 # enclosed by brackets "[]" replaced with your own identifying information:
22 # Portions Copyright [yyyy] [name of copyright owner]
23 # 
24 # HEADER END
25 # 
26 # 
27 # Copyright 2011 Andrew Hopkinson, Oracle Corporation UK Ltd.
28 #
29 ################################################################################
30
31 export OCCLI=/opt/sun/occli/bin
32 export IAAS_HOME=/opt/oracle/iaas/cli
33 export IAAS_BASE_URL=https://localhost
34 export BASE_IAAS_ACCESS_KEY_FILE=iaas_access.key
35 export BASE_KEY_NAME=cli.asset.create
36 export BASE_KEY_FILE=iaas_access.pub
37 export RUN_DATE=`date +"%Y%m%d-%H%M"`
38 #CloudUser used to create vServers & Volumes
39 export IAAS_USER=root
40 export IAAS_PASSWORD_FILE=root.pwd
41 export INPUT_FILE=CreateAssets.in
42
43 export ACCOUNTS_FILE=accounts.out
44 export VOLUMES_FILE=volumes.out
45 export DISTGRPS_FILE=distgrp.out
46 export VNETS_FILE=vnets.out
47 export VSERVER_TYPES_FILE=vstype.out
48 export VSERVER_FILE=vserver.out
49 export VSERVER_TEMPLATES=template.out
50 export NETWORK_STATIC_IPS=staticips.out
51 export KEY_PAIRS=keypairs.out
52
53
54
55 function getAccounts() {
56 accountsArray=( $($IAAS_HOME/bin/akm-describe-accounts --sep "|" | sed 's/ /_/g') )
57 }
58
59 function getVServers() {
60 vserversArray=( $($IAAS_HOME/bin/iaas-describe-vservers --sep "|" | sed 's/ /_/g') )
61 }
62
63
64
65 function connectToAccount() {
66 # Set run specific key information
67 export IAAS_ACCESS_KEY_FILE=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_IAAS_ACCESS_KEY_FILE
68 export KEY_NAME=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_KEY_NAME
69 export KEY_FILE=$ACCOUNT_NAME"."$RUN_DATE"."$BASE_KEY_FILE
70 #echo "IAAS_ACCESS_KEY_FILE=$IAAS_ACCESS_KEY_FILE"
71 #echo "KEY_NAME=$KEY_NAME"
72 #echo "KEY_FILE=$KEY_FILE"
73 #echo "Found Account $line"
74 AK=`$IAAS_HOME/bin/akm-create-access-key --account $ACCOUNT_ID --access-key-file $IAAS_ACCESS_KEY_FILE`
75 KEYPAIR=`$IAAS_HOME/bin/iaas-create-key-pair --key-name $KEY_NAME --key-file $KEY_FILE`
76 #echo "Connected to $ACCOUNT_NAME"
77 }
78
79 function disconnectFromAccount() {
80 $IAAS_HOME/bin/iaas-delete-key-pair --key-name $KEY_NAME --access-key-file $IAAS_ACCESS_KEY_FILE
81 $IAAS_HOME/bin/akm-delete-access-key $AK
82 }
83
84 #############################################################
85 ##
86 ## stopVServers
87 ## ============
88 ##
89 ## Stop one or more vServers running within the currently
90 ## connected Account. If a specific vServer Name is passed in
91 ## $VSERVER as specified on the command line using -v then 
92 ## this will be the one stopped. If no VSERVER is specified
93 ## then all vServers in the Account will be stopped.
94 ##
95 #############################################################
96
97 function stopVServers() {
98 getVServers
99 VSERVER_IDS=""
100 VSERVER_NAMES=""
101 for vserver in "${vserversArray[@]}"
102 do
103 VSERVER_ID=${vserver%%|*}
104 vserver=${vserver#*|}
105 VSERVER_NAME=${vserver%%|*}
106 if [[ "$VSERVER" == "" || "$VSERVER" == "$VSERVER_NAME" ]]
107 then
108 if [[ "$VSERVER_IDS" == "" ]]
109 then
110 VSERVER_IDS=$VSERVER_ID
111 VSERVER_NAMES=$VSERVER_NAME
112 else
113 VSERVER_IDS=$VSERVER_IDS","$VSERVER_ID
114 VSERVER_NAMES=$VSERVER_NAMES","$VSERVER_NAME
115 fi
116 fi
117 done
118 if [[ "$VSERVER_IDS" != "" ]]
119 then
120 echo "Stopping vServer(s) [$VSERVER_NAMES]"
121 $IAAS_HOME/bin/iaas-stop-vservers --vserver-ids $VSERVER_IDS --force
122 else
123 echo "No vServers to stop"
124 fi
125 }
126
127 #############################################################
128 ##
129 ## startVServers
130 ## =============
131 ##
132 ## Start one or more vServers stopped within the currently
133 ## connected Account. If a specific vServer Name is passed in
134 ## $VSERVER as specified on the command line using -v then 
135 ## this will be the one started. If no VSERVER is specified
136 ## then all vServers in the Account will be started.
137 ##
138 #############################################################
139
140 function startVServers() {
141 getVServers
142 VSERVER_IDS=""
143 VSERVER_NAMES=""
144 for vserver in "${vserversArray[@]}"
145 do
146 VSERVER_ID=${vserver%%|*}
147 vserver=${vserver#*|}
148 VSERVER_NAME=${vserver%%|*}
149 if [[ "$VSERVER" == "" || "$VSERVER" == "$VSERVER_NAME" ]]
150 then
151 if [[ "$VSERVER_IDS" == "" ]]
152 then
153 VSERVER_IDS=$VSERVER_ID
154 VSERVER_NAMES=$VSERVER_NAME
155 else
156 VSERVER_IDS=$VSERVER_IDS","$VSERVER_ID
157 VSERVER_NAMES=$VSERVER_NAMES","$VSERVER_NAME
158 fi
159 fi
160 done
161 if [[ "$VSERVER_IDS" != "" ]]
162 then
163 echo "Starting vServer(s) [$VSERVER_NAMES]"
164 $IAAS_HOME/bin/iaas-start-vservers --vserver-ids $VSERVER_IDS
165 else
166 echo "No vServers to start"
167 fi
168 }
169
170 #############################################################
171 ##
172 ## listVServers
173 ## ============
174 ##
175 ## List the vServers running on the specified Account is 
176 ## the verbose flag is set then all vServer details will be 
177 ## displayed otherwise simple the Acc and Name.
178 ##
179 #############################################################
180
181 function listVServers() {
182 getVServers
183 for vserver in "${vserversArray[@]}"
184 do
185 VSERVER_ID=${vserver%%|*}
186 vserver=${vserver#*|}
187 VSERVER_NAME=${vserver%%|*}
188 if [[ "$VSERVER" == "" || "$VSERVER" == "$VSERVER_NAME" ]]
189 then
190 if [[ "$VERBOSE" == "true" ]]
191 then
192 echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_ID|"$(echo $vserver | sed 's/_/ /g')
193 else
194 echo "$ACCOUNT_NAME|$VSERVER_NAME"
195 fi
196 fi
197 done
198 }
199
200 #############################################################
201 ##
202 ## listVServerStatus
203 ## =================
204 ##
205 ## List the Status of the vServers within an Account.
206 ##
207 #############################################################
208
209 function listVServerStatus() {
210 getVServers
211 for vserver in "${vserversArray[@]}"
212 do
213 VSERVER_ID=${vserver%%|*}
214 vserver=${vserver#*|}
215 VSERVER_NAME=${vserver%%|*}
216 vserver=${vserver#*|}
217 VSERVER_DESC=${vserver%%|*}
218 vserver=${vserver#*|}
219 VSERVER_STATUS=${vserver%%|*}
220 if [[ "$VSERVER" == "" || "$VSERVER" == "$VSERVER_NAME" ]]
221 then
222 echo "$ACCOUNT_NAME|$VSERVER_NAME|$VSERVER_STATUS"
223 fi
224 done
225 }
226
227
228
229 #############################################################
230 ##
231 ## usage
232 ## =====
233 ##
234 ## Show usage.
235 ##
236 #############################################################
237
238 function usage() {
239 echo ""
240 echo >&2 "usage: $0 [-a <Account Name>] [-v <vServer Name>] -u <Account User> -p <Account Password> [--verbose] <Command>"
241 echo >&2 " -a <Account Name> Name of the Account that contains the Specified vServer."
242 echo >&2 " -u <Account User> User that is allowed to access the specified account the default is root"
243 echo >&2 " -p <Account Password> password of the specified user"
244 echo >&2 " -v <vServer Name> vServer to be templatised or cloned."
245 echo >&2 " -h This message."
246 echo >&2 " "
247 echo >&2 "Commands "
248 echo >&2 " "
249 echo >&2 " --list-vservers"
250 echo >&2 " List all the vServers in the specified Account. If no Account is specified then it"
251 echo >&2 " will loop through all Accounts within the vDC listing the vServers. To successfully"
252 echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts."
253 echo >&2 " If --verbose is also specified the all available vServer information will be listed."
254 echo >&2 " "
255 echo >&2 " --status-vservers"
256 echo >&2 " List the status all the vServers in the specified Account. If no Account is specified then it"
257 echo >&2 " will loop through all Accounts within the vDC listing the vServers. To successfully"
258 echo >&2 " achieve this the mandatory Username and Password must have access to all the accounts."
259 echo >&2 " "
260 echo >&2 " --start-vservers"
261 echo >&2 " Start all or the named -v vServer(s) in the specified Account. If no Account is specified"
262 echo >&2 " then it will loop through all Accounts within the vDC starting the vServers."
263 echo >&2 " "
264 echo >&2 " --stop-vservers"
265 echo >&2 " Stop all or the named -v vServer(s) in the specified Account. If no Account is specified"
266 echo >&2 " then it will loop through all Accounts within the vDC stoping the vServers."
267 echo""
268 exit 1
269 }
270
271 ###############################################################
272 ##
273 ## Simple start for the script that will extract the parameters
274 ## and call the appriate start function.
275 ##
276 ###############################################################
277
278 export ACCOUNT_USER="root"
279 export ACCOUNT_PASSWORD="welcome1"
280 export SYSTEMIMGDIR=/mnt/elsystem
281
282 while [ $# -gt 0 ]
283 do
284 case "$1" in
285 -a) ACCOUNT="$2"; shift;;
286 -v) VSERVER="$2"; shift;;
287 -u) ACCOUNT_USER="$2"; shift;;
288 -p) ACCOUNT_PASSWORD="$2"; shift;;
289 --verbose) VERBOSE=true;;
290 --list-vservers) LIST_VSERVERS=true;;
291 --stop-vservers) STOP_VSERVERS=true;;
292 --start-vservers) START_VSERVERS=true;;
293 --status-vservers) STATUS_VSERVERS=true;;
294 *) usage;;
295 *) break;;
296 esac
297 shift
298 done
299
300 IAAS_USER=$ACCOUNT_USER
301 echo "$ACCOUNT_PASSWORD" > $IAAS_PASSWORD_FILE
302
303
304
305 # Check if the JAVA_HOME is set
306 if [[ "$JAVA_HOME" == "" ]]
307 then
308 export JAVA_HOME=/usr/java/latest
309 echo "JAVA_HOME is not defined using $JAVA_HOME"
310 fi
311
312 getAccounts
313
314 for account in "${accountsArray[@]}"
315 do
316 ACCOUNT_ID=${account%%|*}
317 account=${account#*|}
318 ACCOUNT_NAME=${account%%|*}
319 if [[ "$ACCOUNT" == "" || "$ACCOUNT" == "$ACCOUNT_NAME" ]]
320 then
321 connectToAccount
322 if [[ "$STOP_VSERVERS" == "true" ]]
323 then
324 stopVServers
325 elif [[ "$START_VSERVERS" == "true" ]]
326 then
327 startVServers
328 elif [[ "$LIST_VSERVERS" == "true" ]]
329 then
330 listVServers
331 elif [[ "$STATUS_VSERVERS" == "true" ]]
332 then
333 listVServerStatus
334 fi
335 disconnectFromAccount
336 fi
337 done
338

Originally posted on the The Old Toxophilist blog.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

The primary contributors to this blog are comprised of the Exalogic and Cloud Application Foundation contingent of Oracle's Fusion Middleware Architecture Team, fondly known as the A-Team. As part of the Oracle development organization, The A-Team supports some of Oracle's largest and most strategic customers worldwide. Our mission is to provide deep technical expertise to support various Oracle field organizations and customers deploying Oracle Fusion Middleware related products. And to collect real world feedback to continuously improve the products we support. In this blog, our experts and guest experts will focus on Exalogic, WebLogic, Coherence, Tuxedo/mainframe migration, Enterprise Manager and JDK/JRockIT performance tuning. It is our way to share some of our experiences with Oracle community. We hope our followers took away something of value from our experiences. Thank you for visiting and please come back soon.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today