Merge lp:~thomir-deactivatedaccount/core-image-tester/trunk-local-ssh-setup into lp:core-image-tester
- trunk-local-ssh-setup
- Merge into trunk
Proposed by
Thomi Richards
Status: | Merged |
---|---|
Approved by: | Thomi Richards |
Approved revision: | 32 |
Merged at revision: | 32 |
Proposed branch: | lp:~thomir-deactivatedaccount/core-image-tester/trunk-local-ssh-setup |
Merge into: | lp:core-image-tester |
Diff against target: |
464 lines (+405/-8) 3 files modified
README.rst (+16/-7) core_image_tester/worker.py (+13/-1) uci-nova (+376/-0) |
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/core-image-tester/trunk-local-ssh-setup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Francis Ginther | Approve | ||
Review via email: mp+257582@code.launchpad.net |
Commit message
Make uci-nova inline.
Description of the change
This branch copies uci-nova from revno 6 of the uci-nova branch. I'll follow this with another branch that removes some of the options that aren't applicable to the core-image-tester.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'README.rst' | |||
2 | --- README.rst 2015-04-01 00:32:13 +0000 | |||
3 | +++ README.rst 2015-04-27 21:05:47 +0000 | |||
4 | @@ -28,17 +28,10 @@ | |||
5 | 28 | $ sudo apt-get update | 28 | $ sudo apt-get update |
6 | 29 | $ sudo apt-get install autopkgtest | 29 | $ sudo apt-get install autopkgtest |
7 | 30 | 30 | ||
8 | 31 | .. note:: | ||
9 | 32 | Thomi: At the time of writing (16/3/2015), the autopkgtest from the PPA is not | ||
10 | 33 | enough to make this work. You also need to manually branch | ||
11 | 34 | lp:~canonical-ci-engineering/adt-cloud-worker/uci-nova and follow the instructions | ||
12 | 35 | there. | ||
13 | 36 | |||
14 | 37 | ...and install bzr, which is needed to get the test branch:: | 31 | ...and install bzr, which is needed to get the test branch:: |
15 | 38 | 32 | ||
16 | 39 | $ sudo apt-get install bzr | 33 | $ sudo apt-get install bzr |
17 | 40 | 34 | ||
18 | 41 | |||
19 | 42 | Install the service itself:: | 35 | Install the service itself:: |
20 | 43 | 36 | ||
21 | 44 | $ python setup.py install | 37 | $ python setup.py install |
22 | @@ -49,6 +42,22 @@ | |||
23 | 49 | 42 | ||
24 | 50 | $ python setup.py develop | 43 | $ python setup.py develop |
25 | 51 | 44 | ||
26 | 45 | uci-nova | ||
27 | 46 | ++++++++ | ||
28 | 47 | |||
29 | 48 | This service includes a custom adt-run ssh setup script called 'uci-nova'. This | ||
30 | 49 | is a shell script that exists in the root of the branch, and is called by the | ||
31 | 50 | core-image-tester service. | ||
32 | 51 | |||
33 | 52 | You can run adt-run manually yourself, in order to replicate what the service | ||
34 | 53 | does. For example:: | ||
35 | 54 | |||
36 | 55 | $ adt-run --built-tree <test_dir> \ | ||
37 | 56 | --output-dir <result_dir> \ | ||
38 | 57 | --- ssh -s ./uci-nova -- \ | ||
39 | 58 | --flavor <nova_flavour> \ | ||
40 | 59 | --image <nova_image> | ||
41 | 60 | |||
42 | 52 | Run the tests! | 61 | Run the tests! |
43 | 53 | ============== | 62 | ============== |
44 | 54 | 63 | ||
45 | 55 | 64 | ||
46 | === modified file 'core_image_tester/worker.py' | |||
47 | --- core_image_tester/worker.py 2015-04-17 16:02:30 +0000 | |||
48 | +++ core_image_tester/worker.py 2015-04-27 21:05:47 +0000 | |||
49 | @@ -18,6 +18,7 @@ | |||
50 | 18 | """ADT Cloud worker functional code.""" | 18 | """ADT Cloud worker functional code.""" |
51 | 19 | import logging | 19 | import logging |
52 | 20 | import os | 20 | import os |
53 | 21 | import os.path | ||
54 | 21 | import shutil | 22 | import shutil |
55 | 22 | import subprocess | 23 | import subprocess |
56 | 23 | import tarfile | 24 | import tarfile |
57 | @@ -204,7 +205,7 @@ | |||
58 | 204 | '--built-tree', test_dir, | 205 | '--built-tree', test_dir, |
59 | 205 | '--output-dir', result_dir, | 206 | '--output-dir', result_dir, |
60 | 206 | # Specify the ssh backend, and the uci-nova setup script: | 207 | # Specify the ssh backend, and the uci-nova setup script: |
62 | 207 | '---', 'ssh', '-s', 'uci-nova', '--', | 208 | '---', 'ssh', '-s', get_uci_nova_path(), '--', |
63 | 208 | '--flavor', config['adt']['image_flavor'], | 209 | '--flavor', config['adt']['image_flavor'], |
64 | 209 | '--image', nova_image, | 210 | '--image', nova_image, |
65 | 210 | '--console', os.path.join(result_dir, 'nova-console.log'), | 211 | '--console', os.path.join(result_dir, 'nova-console.log'), |
66 | @@ -219,6 +220,17 @@ | |||
67 | 219 | return 0 | 220 | return 0 |
68 | 220 | 221 | ||
69 | 221 | 222 | ||
70 | 223 | def get_uci_nova_path(): | ||
71 | 224 | return os.path.abspath( | ||
72 | 225 | os.path.join( | ||
73 | 226 | __file__, | ||
74 | 227 | '..', | ||
75 | 228 | '..', | ||
76 | 229 | 'uci-nova' | ||
77 | 230 | ) | ||
78 | 231 | ) | ||
79 | 232 | |||
80 | 233 | |||
81 | 222 | def sanitize_results(results_dir, config): | 234 | def sanitize_results(results_dir, config): |
82 | 223 | """Filter out any secrets exposed in select log files. | 235 | """Filter out any secrets exposed in select log files. |
83 | 224 | 236 | ||
84 | 225 | 237 | ||
85 | === added file 'uci-nova' | |||
86 | --- uci-nova 1970-01-01 00:00:00 +0000 | |||
87 | +++ uci-nova 2015-04-27 21:05:47 +0000 | |||
88 | @@ -0,0 +1,376 @@ | |||
89 | 1 | #!/bin/sh | ||
90 | 2 | # | ||
91 | 3 | # This script is part of autopkgtest | ||
92 | 4 | # autopkgtest is a tool for testing Debian binary packages | ||
93 | 5 | # | ||
94 | 6 | # This script sets up a nova instance to use as an autopkgtest testbed. It | ||
95 | 7 | # assumes that the host system is already prepared to run nova commands. | ||
96 | 8 | # WARNING: This is mostly a proof of concept and not very robust. | ||
97 | 9 | |||
98 | 10 | # Options: | ||
99 | 11 | # | ||
100 | 12 | # -f flavor | --flavor=flavor | ||
101 | 13 | # Name or ID of flavor (see 'nova flavor-list'), mandatory | ||
102 | 14 | # -i image | --image=image | ||
103 | 15 | # Name or ID of image (see 'nova image-list'), mandatory | ||
104 | 16 | # -N net-id | --net-id=net-id | ||
105 | 17 | # UUID of the network that should be used for the instance | ||
106 | 18 | # -n name | --name=name | ||
107 | 19 | # Name for the new server. A name will be generated if not specified. | ||
108 | 20 | # -c console-log | --console=file-name | ||
109 | 21 | # Save the nova console-log of the server to the specified file. | ||
110 | 22 | # | ||
111 | 23 | # | ||
112 | 24 | # Authors: | ||
113 | 25 | # Celso Providelo <celso.providelo@canonical.com> | ||
114 | 26 | # | ||
115 | 27 | # | ||
116 | 28 | # autopkgtest is Copyright (C) 2006-2015 Canonical Ltd. | ||
117 | 29 | # | ||
118 | 30 | # This program is free software; you can redistribute it and/or modify | ||
119 | 31 | # it under the terms of the GNU General Public License as published by | ||
120 | 32 | # the Free Software Foundation; either version 2 of the License, or | ||
121 | 33 | # (at your option) any later version. | ||
122 | 34 | # | ||
123 | 35 | # This program is distributed in the hope that it will be useful, | ||
124 | 36 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
125 | 37 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
126 | 38 | # GNU General Public License for more details. | ||
127 | 39 | # | ||
128 | 40 | # You should have received a copy of the GNU General Public License | ||
129 | 41 | # along with this program; if not, write to the Free Software | ||
130 | 42 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
131 | 43 | # | ||
132 | 44 | # See the file CREDITS for a full list of credits information (often | ||
133 | 45 | # installed as /usr/share/doc/autopkgtest/CREDITS). | ||
134 | 46 | set -eu | ||
135 | 47 | |||
136 | 48 | CAPABILITIES='isolation-machine,reboot,revert,revert-full-system' | ||
137 | 49 | |||
138 | 50 | SUDO_PASSWORD='' | ||
139 | 51 | SSH_USER=ubuntu | ||
140 | 52 | |||
141 | 53 | FLAVOR="" | ||
142 | 54 | IMAGE="" | ||
143 | 55 | |||
144 | 56 | SRVNAME="" | ||
145 | 57 | NET_ID="" | ||
146 | 58 | CONSOLE="" | ||
147 | 59 | DEBUG="" | ||
148 | 60 | |||
149 | 61 | |||
150 | 62 | debug() { | ||
151 | 63 | [ -z "$DEBUG" ] && return | ||
152 | 64 | echo "$@">&2 | ||
153 | 65 | } | ||
154 | 66 | |||
155 | 67 | warning() { | ||
156 | 68 | echo "$@">&2 | ||
157 | 69 | } | ||
158 | 70 | |||
159 | 71 | error() { | ||
160 | 72 | echo "$@">&2 | ||
161 | 73 | } | ||
162 | 74 | |||
163 | 75 | parse_args() { | ||
164 | 76 | # Parse command line argument and populate environment | ||
165 | 77 | |||
166 | 78 | SHORTOPTS="f:,i:,N:,n:,c:,d" | ||
167 | 79 | LONGOPTS="flavor:,image:,net-id:,name:,console:,debug" | ||
168 | 80 | |||
169 | 81 | TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@") | ||
170 | 82 | eval set -- "$TEMP" | ||
171 | 83 | |||
172 | 84 | while true; do | ||
173 | 85 | case "$1" in | ||
174 | 86 | -f|--flavor) | ||
175 | 87 | FLAVOR=$2 | ||
176 | 88 | shift 2;; | ||
177 | 89 | -i|--image) | ||
178 | 90 | IMAGE=$2 | ||
179 | 91 | shift 2;; | ||
180 | 92 | -N|--net-id) | ||
181 | 93 | NET_ID="$2" | ||
182 | 94 | shift 2;; | ||
183 | 95 | -n|--name) | ||
184 | 96 | SRVNAME=$2 | ||
185 | 97 | shift 2;; | ||
186 | 98 | -c|--console) | ||
187 | 99 | CONSOLE=$2 | ||
188 | 100 | shift 2;; | ||
189 | 101 | -d|--debug) | ||
190 | 102 | DEBUG=1; shift;; | ||
191 | 103 | --) | ||
192 | 104 | shift; | ||
193 | 105 | break;; | ||
194 | 106 | *) | ||
195 | 107 | error "E: $(basename $0): Unsupported option $1" | ||
196 | 108 | exit 1;; | ||
197 | 109 | esac | ||
198 | 110 | done | ||
199 | 111 | |||
200 | 112 | if [ -z "$FLAVOR" ]; then | ||
201 | 113 | error "Argument 'flavor' is mandatory. Run 'nova flavor-list' to "\ | ||
202 | 114 | "print a list of available flavors." | ||
203 | 115 | exit 1 | ||
204 | 116 | fi | ||
205 | 117 | if [ -z "$IMAGE" ]; then | ||
206 | 118 | error "Argument 'image' is mandatory. Run 'nova image-list' to "\ | ||
207 | 119 | "print a list of available images to boot from." | ||
208 | 120 | exit 1 | ||
209 | 121 | fi | ||
210 | 122 | } | ||
211 | 123 | |||
212 | 124 | security_setup_nova() { | ||
213 | 125 | debug "Creating specific nova security-group: $SRVNAME" | ||
214 | 126 | nova secgroup-create $SRVNAME "$SRVNAME testbed" | ||
215 | 127 | |||
216 | 128 | debug "Allowing ingress SSH ..." | ||
217 | 129 | nova secgroup-add-rule $SRVNAME tcp 22 22 0.0.0.0/0 | ||
218 | 130 | |||
219 | 131 | debug "Egress traffic will respect external Firewall rules ..." | ||
220 | 132 | } | ||
221 | 133 | |||
222 | 134 | security_setup_neutron() { | ||
223 | 135 | debug "Creating specific neutron security-group: $SRVNAME" | ||
224 | 136 | neutron security-group-create $SRVNAME \ | ||
225 | 137 | --description "$SRVNAME testbed" | ||
226 | 138 | |||
227 | 139 | debug "Cleaning up default egress rules ..." | ||
228 | 140 | DEFAULT_RULES=$(neutron security-group-rule-list \ | ||
229 | 141 | --format csv -c id -c security_group --quote none \ | ||
230 | 142 | | grep $SRVNAME | cut -d',' -f1) | ||
231 | 143 | for rule_id in $DEFAULT_RULES; do | ||
232 | 144 | neutron security-group-rule-delete $rule_id | ||
233 | 145 | done | ||
234 | 146 | |||
235 | 147 | debug "Allowing ingress SSH ..." | ||
236 | 148 | neutron security-group-rule-create \ | ||
237 | 149 | --direction ingress \ | ||
238 | 150 | --ethertype ipv4 \ | ||
239 | 151 | --protocol tcp \ | ||
240 | 152 | --port-range-min 22 \ | ||
241 | 153 | --port-range-max 22 \ | ||
242 | 154 | --remote-ip-prefix 0.0.0.0/0 \ | ||
243 | 155 | $SRVNAME | ||
244 | 156 | |||
245 | 157 | debug "Allowing DNS egress traffic ..." | ||
246 | 158 | neutron security-group-rule-create \ | ||
247 | 159 | --direction egress \ | ||
248 | 160 | --remote-ip-prefix 8.8.8.8 \ | ||
249 | 161 | $SRVNAME | ||
250 | 162 | |||
251 | 163 | debug "Allowing APT and NTP egress traffic ..." | ||
252 | 164 | neutron security-group-rule-create \ | ||
253 | 165 | --direction egress \ | ||
254 | 166 | --remote-ip-prefix 91.189.88.0/21 \ | ||
255 | 167 | $SRVNAME | ||
256 | 168 | } | ||
257 | 169 | |||
258 | 170 | # create a testbed (if necessary), configure ssh, copy ssh key into it, | ||
259 | 171 | # configure sudo, etc.; print a list of "key=value" parameters to stdout on | ||
260 | 172 | # success | ||
261 | 173 | open() { | ||
262 | 174 | # Boot a nova instance and returns its connection parameters | ||
263 | 175 | [ -n "$SRVNAME" ] || SRVNAME=`mktemp -u adt-nova-XXXXXX` | ||
264 | 176 | |||
265 | 177 | mkdir /tmp/$SRVNAME | ||
266 | 178 | |||
267 | 179 | debug "Creating new SSH key on /tmp/$SRVNAME" | ||
268 | 180 | SSH_IDENTITY=/tmp/$SRVNAME/id_rsa | ||
269 | 181 | ssh-keygen -f $SSH_IDENTITY -q -N "" | ||
270 | 182 | |||
271 | 183 | debug "Creating specific nova keypair: $SRVNAME" | ||
272 | 184 | nova keypair-add --pub-key $SSH_IDENTITY.pub $SRVNAME | ||
273 | 185 | |||
274 | 186 | # Setup testbed security with nova or neutron according to their | ||
275 | 187 | # availability in the target cloud. | ||
276 | 188 | if ! neutron security-group-list; then | ||
277 | 189 | security_setup_nova | ||
278 | 190 | else | ||
279 | 191 | security_setup_neutron | ||
280 | 192 | fi | ||
281 | 193 | |||
282 | 194 | # generate cloud-init user data; mostly for manage_etc_hosts, but also get | ||
283 | 195 | # rid of some unnecessary stuff in the VM | ||
284 | 196 | local userdata=`mktemp` | ||
285 | 197 | cat <<EOF > $userdata | ||
286 | 198 | #cloud-config | ||
287 | 199 | manage_etc_hosts: true | ||
288 | 200 | apt_update: true | ||
289 | 201 | apt_upgrade: false | ||
290 | 202 | snappy: | ||
291 | 203 | ssh_enabled: True | ||
292 | 204 | |||
293 | 205 | runcmd: | ||
294 | 206 | - echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/90nolanguages | ||
295 | 207 | - echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/autopkgtest | ||
296 | 208 | EOF | ||
297 | 209 | |||
298 | 210 | EXTRA_OPTS='' | ||
299 | 211 | if [ -n "$NET_ID" ]; then | ||
300 | 212 | EXTRA_OPTS="$EXTRA_OPTS --nic net-id=$NET_ID" | ||
301 | 213 | fi | ||
302 | 214 | |||
303 | 215 | # Boot the instance | ||
304 | 216 | debug "Creating nova instance $SRVNAME ..." | ||
305 | 217 | OUT=$(nova boot --config-drive=1 \ | ||
306 | 218 | --flavor $FLAVOR --image $IMAGE --user-data $userdata \ | ||
307 | 219 | --key_name $SRVNAME --security-groups $SRVNAME \ | ||
308 | 220 | $EXTRA_OPTS $SRVNAME 2>&1) || { | ||
309 | 221 | error "nova boot failed:" | ||
310 | 222 | error "$OUT" | ||
311 | 223 | exit 1 | ||
312 | 224 | } | ||
313 | 225 | debug "Nova boot succeeded" | ||
314 | 226 | rm $userdata | ||
315 | 227 | |||
316 | 228 | # Find IP address | ||
317 | 229 | ipaddr="" | ||
318 | 230 | retry=60 | ||
319 | 231 | while [ -z "$ipaddr" ]; do | ||
320 | 232 | OUT=$(nova show --minimal $SRVNAME) | ||
321 | 233 | ipaddr=$(echo "$OUT" | awk 'BEGIN {FS="|"} /network/ {n=split($3,i,/,\s*/); gsub(" ", "", i[n]); print i[n]}') | ||
322 | 234 | retry=$(( retry - 1 )) | ||
323 | 235 | if [ $retry -le 0 ]; then | ||
324 | 236 | error "Failed to acquire an IP address. Aborting!" | ||
325 | 237 | error "$OUT" | ||
326 | 238 | cleanup | ||
327 | 239 | exit 1 | ||
328 | 240 | fi | ||
329 | 241 | sleep 3 | ||
330 | 242 | done | ||
331 | 243 | debug "Finding IP address succeeded: $ipaddr" | ||
332 | 244 | |||
333 | 245 | # purge the device host key so that SSH doesn't print a scary warning | ||
334 | 246 | ssh-keygen -f ~/.ssh/known_hosts -R $ipaddr >/dev/null 2>&1 || true | ||
335 | 247 | |||
336 | 248 | ADT_EXTRA_OPTS="-n $SRVNAME" | ||
337 | 249 | if [ -n "$CONSOLE" ]; then | ||
338 | 250 | ADT_EXTRA_OPTS="$ADT_EXTRA_OPTS -c $CONSOLE" | ||
339 | 251 | fi | ||
340 | 252 | |||
341 | 253 | # Return access information to adt-virt-ssh. | ||
342 | 254 | cat<<EOF | ||
343 | 255 | identity=$SSH_IDENTITY | ||
344 | 256 | login=$SSH_USER | ||
345 | 257 | hostname=$ipaddr | ||
346 | 258 | capabilities=$CAPABILITIES | ||
347 | 259 | extraopts=$ADT_EXTRA_OPTS | ||
348 | 260 | EOF | ||
349 | 261 | if [ -n "$SUDO_PASSWORD" ]; then | ||
350 | 262 | echo "password=$SUDO_PASSWORD" | ||
351 | 263 | fi | ||
352 | 264 | |||
353 | 265 | # wait until ssh is available and cloud-config is done | ||
354 | 266 | debug "Waiting until ssh becomes available" | ||
355 | 267 | SSH="ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/$SRVNAME/id_rsa -l $SSH_USER $ipaddr" | ||
356 | 268 | retry=60 | ||
357 | 269 | while ! $SSH true; do | ||
358 | 270 | retry=$(( retry - 1 )) | ||
359 | 271 | if [ $retry -le 0 ]; then | ||
360 | 272 | error "Timed out waiting for ssh. Aborting!" | ||
361 | 273 | cleanup | ||
362 | 274 | exit 1 | ||
363 | 275 | fi | ||
364 | 276 | sleep 5 | ||
365 | 277 | done | ||
366 | 278 | |||
367 | 279 | debug "Waiting for cloud-init to finish" | ||
368 | 280 | if ! timeout 30m $SSH 'while [ ! -e /var/lib/cloud/instance/boot-finished ]; do sleep 1; done'; then | ||
369 | 281 | error "Timed out waiting for cloud-init to finish. Aborting!" | ||
370 | 282 | cleanup | ||
371 | 283 | exit 1 | ||
372 | 284 | fi | ||
373 | 285 | |||
374 | 286 | } | ||
375 | 287 | |||
376 | 288 | cleanup() { | ||
377 | 289 | if [ -z "$SRVNAME" ]; then | ||
378 | 290 | error "Cannot determine server name. Instance won't be deleted!" | ||
379 | 291 | exit 0 | ||
380 | 292 | fi | ||
381 | 293 | |||
382 | 294 | if [ -n "$CONSOLE" ]; then | ||
383 | 295 | debug "Saving console-log for $SRVNAME" | ||
384 | 296 | nova console-log $SRVNAME > $CONSOLE | ||
385 | 297 | fi | ||
386 | 298 | |||
387 | 299 | debug "Deleting $SRVNAME instance" | ||
388 | 300 | nova delete $SRVNAME || true | ||
389 | 301 | |||
390 | 302 | debug "Deleting $SRVNAME keypair" | ||
391 | 303 | nova keypair-delete $SRVNAME || true | ||
392 | 304 | |||
393 | 305 | debug "Deleting /tmp/$SRVNAME SSH keys" | ||
394 | 306 | rm -rf /tmp/$SRVNAME || true | ||
395 | 307 | |||
396 | 308 | DELETE_CMD="neutron security-group-delete $SRVNAME" | ||
397 | 309 | if ! neutron security-group-list; then | ||
398 | 310 | DELETE_CMD="nova secgroup-delete $SRVNAME" | ||
399 | 311 | fi | ||
400 | 312 | |||
401 | 313 | debug "Deleting $SRVNAME security-group" | ||
402 | 314 | retry=3 | ||
403 | 315 | while ! eval "$DELETE_CMD"; do | ||
404 | 316 | retry=$(( retry - 1 )) | ||
405 | 317 | if [ $retry -le 0 ]; then | ||
406 | 318 | error "Timed out deleting secgroup. Aborting!" | ||
407 | 319 | cleanup | ||
408 | 320 | exit 1 | ||
409 | 321 | fi | ||
410 | 322 | sleep 5 | ||
411 | 323 | done | ||
412 | 324 | |||
413 | 325 | SRVNAME="" | ||
414 | 326 | } | ||
415 | 327 | |||
416 | 328 | revert() { | ||
417 | 329 | if [ -z "$SRVNAME" ]; then | ||
418 | 330 | echo "Needs to be called with -n <server name>" >&2 | ||
419 | 331 | exit 1 | ||
420 | 332 | fi | ||
421 | 333 | cleanup | ||
422 | 334 | open | ||
423 | 335 | } | ||
424 | 336 | |||
425 | 337 | reboot() { | ||
426 | 338 | if [ -z "$SRVNAME" ]; then | ||
427 | 339 | error "Cannot determine server name. Instance won't be rebooted!" | ||
428 | 340 | exit 1 | ||
429 | 341 | fi | ||
430 | 342 | |||
431 | 343 | nova reboot --poll $SRVNAME >/dev/null 2>&1||true | ||
432 | 344 | } | ||
433 | 345 | |||
434 | 346 | # ######################################## | ||
435 | 347 | # Main procedure | ||
436 | 348 | # | ||
437 | 349 | if [ $# -eq 0 ]; then | ||
438 | 350 | error "Invalid number of arguments, command is missing" | ||
439 | 351 | exit 1 | ||
440 | 352 | fi | ||
441 | 353 | cmd=$(echo $1|tr [[:upper:]] [[:lower:]]) | ||
442 | 354 | shift | ||
443 | 355 | parse_args "$@" | ||
444 | 356 | |||
445 | 357 | # Don't leave stuff behind ... | ||
446 | 358 | trap "cleanup" 1 2 6 15 | ||
447 | 359 | |||
448 | 360 | case $cmd in | ||
449 | 361 | open) | ||
450 | 362 | open;; | ||
451 | 363 | cleanup) | ||
452 | 364 | cleanup;; | ||
453 | 365 | revert) | ||
454 | 366 | revert;; | ||
455 | 367 | reboot) | ||
456 | 368 | reboot;; | ||
457 | 369 | '') | ||
458 | 370 | echo "Needs to be called with command as first argument" >&2 | ||
459 | 371 | exit 1 | ||
460 | 372 | ;; | ||
461 | 373 | *) | ||
462 | 374 | echo "invalid command $cmd" >&2 | ||
463 | 375 | exit 1 | ||
464 | 376 | esac |
Approve