Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / 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 # Return offset between DEA node id and cluster node id
26 getDeaNodeOffset()
27 {
28     local baseId
29
30     baseId=`fuel node | tail -n +3 | awk '{ print $1 }' | sed 's/ //g' | sort -n | head -1`
31     echo "$[baseId - 1]"
32 }
33
34 tmpDir=`mktemp -d /tmp/deaXXXX`
35
36 export PATH=`dirname $0`:$PATH
37
38 if [ $# -ne 1 ]; then
39   error_exit "Argument error"
40 fi
41 deaFile=$1
42
43 if [ ! -f "$deaFile" ]; then
44   error_exit "Can't find $deaFile"
45 fi
46
47
48 if [ `fuel env | tail -n +3 | grep -v '^$' | wc -l` -ne 1 ]; then
49   error_exit "Not exactly one environment"
50 fi
51 envId=`fuel env | tail -n +3 | grep -v '^$' | awk '{ print $1 }'`
52
53 # Phase 1: Graft deployment information
54 fuel deployment --env $envId --default --dir $tmpDir || \
55   error_exit "Could not dump environment"
56
57 for controller in `find $tmpDir -type f | grep -v compute`
58 do
59   transplant_network_scheme.py $controller $deaFile controller || \
60     error_exit "Failed to graft `basename $controller`"
61
62   transplant_opnfv_settings.py $controller $deaFile controller || \
63     error_exit "Failed to graft `basename $controller`"
64 done
65
66 for compute in `find $tmpDir -type f | grep compute`
67 do
68   transplant_network_scheme.py $compute $deaFile compute || \
69     error_exit "Failed to graft `basename $compute`"
70
71   transplant_opnfv_settings.py $compute $deaFile compute || \
72     error_exit "Failed to graft `basename $controller`"
73 done
74
75 fuel deployment --env $envId --upload --dir $tmpDir || \
76   error_exit "Could not upload environment"
77
78 # Phase 2: Graft interface information
79 deaOffset=`getDeaNodeOffset`
80 echo "DEA offset: $deaOffset"
81
82 for clusterNodeId in `fuel node | grep True | awk '{ print $1}'`
83 do
84     deaNodeId=$[clusterNodeId - deaOffset]
85     echo "Node $clusterNodeId is $deaNodeId"
86     fuel node --node-id $clusterNodeId --network --download --dir $tmpDir || \
87         error_exit "Could not download node $clusterNodeId"
88
89     transplant_interfaces.py ${tmpDir}/node_${clusterNodeId}/interfaces.yaml \
90         $deaFile $deaNodeId || \
91         error_exit "Failed to graft interfaces"
92
93     fuel node --node-id $clusterNodeId --network --upload --dir $tmpDir || \
94         error_exit "Could not upload node $clusterNodeId"
95 done
96
97
98