Prototype of automated libvirt installation
[genesis.git] / fuel / prototypes / libvirt / deploy / tools / transplant2.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 cleanup () {
13   if [ -n "$tmpDir" ]; then
14     rm -Rf $tmpDir
15   fi
16 }
17
18 trap cleanup exit
19
20 error_exit () {
21   echo "Error: $@" >&2
22   exit 1
23 }
24
25 tmpDir=`mktemp -d /tmp/deaXXXX`
26
27 export PATH=`dirname $0`:$PATH
28
29 if [ $# -ne 1 ]; then
30   error_exit "Argument error"
31 fi
32 deaFile=$1
33
34 if [ ! -f "$deaFile" ]; then
35   error_exit "Can't find $deaFile"
36 fi
37
38
39 if [ `fuel env | tail -n +3 | grep -v '^$' | wc -l` -ne 1 ]; then
40   error_exit "Not exactly one environment"
41 fi
42 envId=`fuel env | tail -n +3 | grep -v '^$' | awk '{ print $1 }'`
43
44 # Phase 1: Graft deployment information
45 if [ "a" == "b" ]; then
46 fuel deployment --env $envId --default --dir $tmpDir || \
47   error_exit "Could not dump environment"
48
49 for controller in `find $tmpDir -type f | grep -v compute`
50 do
51   transplant_network_scheme.py $controller $deaFile controller || \
52     error_exit "Failed to graft `basename $controller`"
53 done
54
55 for compute in `find $tmpDir -type f | grep compute`
56 do
57   transplant_network_scheme.py $compute $deaFile compute || \
58     error_exit "Failed to graft `basename $compute`"
59 done
60
61 fuel deployment --env $envId --upload --dir $tmpDir || \
62   error_exit "Could not upload environment"
63 fi
64 # Phase 2: Graft interface information
65
66 for nodeId in `fuel node | grep True | awk '{ print $1}'`
67 do
68   echo "Node $nodeId"
69   fuel node --node-id $nodeId --network --download --dir $tmpDir || \
70      error_exit "Could not download node $nodeId"
71
72   transplant_interfaces.py ${tmpDir}/node_${nodeId}/interfaces.yaml $deaFile || \
73      error_exit "Failed to graft interfaces"
74
75   fuel node --node-id $nodeId --network --upload --dir $tmpDir || \
76      error_exit "Could not upload node $nodeId"
77 done
78
79
80