6fb26c4754a9e11dfa15ab3f7bcaae3ddd2e62ea
[genesis.git] / fuel / prototypes / libvirt / deploy / functions / deploy_env.sh
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Deploy!
12
13 scp -q $deafile root@10.20.0.2:. || error_exit "Could not copy DEA file to Fuel"
14 echo "Uploading build tools to Fuel server"
15 ssh root@10.20.0.2 rm -rf tools || error_exit "Error cleaning old tools structure"
16 scp -qrp $topdir/tools root@10.20.0.2:. || error_exit "Error copying tools"
17
18 # Refuse to run if environment already present
19 envcnt=`fuel env | tail -n +3 | grep -v '^$' | wc -l`
20 if [ $envcnt -ne 0 ]; then
21   error_exit "Environment count is $envcnt"
22 fi
23
24 # Refuse to run if any nodes are up
25 nodeCnt=`noNodesUp`
26 if [ $nodeCnt -ne 0 ]; then
27   error_exit "Nodes are up (node count: $nodeCnt)"
28 fi
29
30 # Extract release ID for Ubuntu environment
31 ubuntucnt=`fuel release | grep Ubuntu | wc -l`
32 if [ $ubuntucnt -ne 1 ]; then
33   error_exit "Not exacly one Ubuntu release found"
34 fi
35
36 ubuntuid=`fuel release | grep Ubuntu | awk '{ print $1 }'`
37
38 # Create environment
39 fuel env create --name Foobar --rel $ubuntuid --mode ha --network-mode neutron  --net-segment-type vlan || error_exit "Error creating environment"
40 envId=`ssh root@10.20.0.2 fuel env | tail -n +3 | awk '{ print $1 }'` || error_exit "Could not get environment id"
41
42
43 echo "Running transplant #1"
44 ssh root@10.20.0.2 "cd tools; ./transplant1.sh ../`basename $deafile`" || error_exit "Error running transplant sequence #1"
45
46 # Spin up VMs
47 for node in controller1 controller2 controller3 compute4 compute5
48 do
49   echo "Starting VM $node"
50   virsh start $node >/dev/null 2>&1 || error_exit "Could not virsh start $node"
51   sleep 10
52 done
53
54 for node in controller1 controller2 controller3
55 do
56   echo -n "Waiting for Fuel to detect $node"
57   waitForHost $node
58   echo "Setting role for $node"
59   fuel node set --node-id `getNodeId $node` --role controller,mongo --env $envId || error_exit "Could not set role for $node"
60 done
61
62 for node in compute4 compute5
63 do
64   echo -n "Waiting for Fuel to detect $node"
65   waitForHost $node
66   echo "Setting role for $node"
67   fuel node set --node-id `getNodeId $node` --role compute --env $envId || error_exit "Could not set role for $node"
68 done
69
70 # Inject node network config
71 echo "Running transplant #2"
72 ssh root@10.20.0.2 "cd tools; ./transplant2.sh ../`basename $deafile`" || error_exit "Error running transplant sequence #2"
73
74 # Run pre-deploy with default input
75 # Need to set terminal as script does "clear"
76 ssh root@10.20.0.2 "TERM=vt100 /opt/opnfv/pre-deploy.sh < /dev/null" || error_exit "Pre-deploy failed"
77
78 # Deploy
79 echo "Deploying!"
80 ssh root@10.20.0.2 "fuel deploy-changes --env $envId" >/dev/null 2>&1 || error_exit "Deploy failed"
81 echo "Deployment completed"