87587a5aaaea0471072cf148903cd9a33e9103ea
[genesis.git] / fuel / prototypes / libvirt / create_dea / create_dea.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 [ $# -lt 1 ]; then
30   error_exit "Argument error"
31 fi
32 deafile=$1
33 shift
34
35 if [ $# -ne 0 ]; then
36   comment="$@"
37 fi
38
39 if [ -f "$deafile" ]; then
40   error_exit "$deafile already exists"
41 fi
42
43 if [ `fuel env | tail -n +3 | grep -v '^$' | wc -l` -ne 1 ]; then
44   error_exit "Not exactly one environment"
45 fi
46 envId=`fuel env | tail -n +3 | grep -v '^$' | awk '{ print $1 }'`
47
48 computeId=`fuel node | grep compute | grep True | head -1 | awk '{ print $1}'`
49 controllerId=`fuel node | grep controller | grep True | head -1 | awk '{ print $1}'`
50
51 if [ -z "$computeId" ]; then
52   error_exit "Could not find any compute node"
53 elif [ -z "$controllerId" ]; then
54   error_exit "Could not find any controller node"
55 fi
56
57 fuel deployment --env $envId --download --dir $tmpDir > /dev/null || \
58   error_exit "Could not get deployment info"
59 fuel settings --env $envId --download --dir $tmpDir > /dev/null || \
60   error_exit "Could not get settings"
61 fuel network --env $envId --download --dir $tmpDir > /dev/null || \
62   error_exit "Could not get network settings"
63
64 echo "version: 1.0" > $deafile
65 echo "created: `date`" >> $deafile
66 if [ -n "$comment" ]; then
67   echo "comment: $comment" >> $deafile
68 fi
69
70 reap_network_scheme.py $tmpDir/deployment_${envId}/*controller_${controllerId}.yaml $deafile controller || \
71   error_exit "Could not extract network scheme for controller"
72 reap_network_scheme.py $tmpDir/deployment_${envId}/compute_${computeId}.yaml $deafile compute || \
73   error_exit "Could not extract network scheme for controller"
74 reap_network_settings.py $tmpDir/network_${envId}.yaml $deafile network || \
75   error_exit "Could not extract network settings"
76 reap_settings.py $tmpDir/settings_${envId}.yaml $deafile settings || \
77   error_exit "Could not extract settings"
78
79 fuel node --node-id $controllerId --network --download --dir $tmpDir || \
80   error_exit "Could not get network info for node $controllerId"
81 reap_interfaces.py $tmpDir/node_${controllerId}/interfaces.yaml $deafile || \
82   error_exit "Could not extract interfaces"
83
84
85 echo "DEA file is available at $deafile"
86