Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / functions / common.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 # Common functions
12
13 error_exit () {
14   echo "Error: $@" >&2
15   exit 1
16 }
17
18 ssh() {
19   SSHPASS="r00tme" sshpass -e ssh -o UserKnownHostsFile=${tmpdir}/known_hosts \
20     -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
21 }
22
23 scp() {
24   SSHPASS="r00tme" sshpass -e scp  -o UserKnownHostsFile=${tmpdir}/known_hosts \
25     -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
26 }
27
28
29 fuel () {
30   ssh root@`dea getFuelIp` "fuel $@"
31 }
32
33
34 # TODO: Move numberOfNodes into the DEA API
35 numberOfNodes() {
36   fuel node | tail -n +3 | grep -v "^$" | wc -l
37 }
38
39 # TODO: Move numberOfNodesUp into the DEA API
40 numberOfNodesUp() {
41   fuel node | tail -n +3  | grep -v "^$" | grep True | wc -l
42 }
43
44 # Currently not used!
45 # Wait for node count to increase
46 waitForNode() {
47   local cnt
48   local initCnt
49   local expectCnt
50
51   initCnt=`numberOfNodesUp`
52   expectCnt=$[initCnt+1]
53   while true
54   do
55     cnt=`numberOfNodesUp`
56     if [ $cnt -eq $expectCnt ]; then
57       break
58     elif [ $cnt -lt $initCnt ]; then
59       error_exit "Node count decreased while waiting, $initCnt -> $cnt"
60     elif [ $cnt -gt $expectCnt ]; then
61       error_exit "Node count exceeded expect count, $cnt > $expectCnt"
62     fi
63     sleep 10
64     echo -n "[${cnt}]"
65   done
66   echo "[${cnt}]"
67 }