summaryrefslogtreecommitdiffstats
path: root/fuel/prototypes/auto-deploy/deploy/functions/common.sh
blob: 6947d796f6dfbd1235355901468580c1738c7ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Common functions

error_exit () {
  echo "Error: $@" >&2
  exit 1
}

ssh() {
  SSHPASS="r00tme" sshpass -e ssh -o UserKnownHostsFile=${tmpdir}/known_hosts \
    -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
}

scp() {
  SSHPASS="r00tme" sshpass -e scp  -o UserKnownHostsFile=${tmpdir}/known_hosts \
    -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
}


fuel () {
  ssh root@`dea getFuelIp` "fuel $@"
}


# TODO: Move numberOfNodes into the DEA API
numberOfNodes() {
  fuel node | tail -n +3 | grep -v "^$" | wc -l
}

# TODO: Move numberOfNodesUp into the DEA API
numberOfNodesUp() {
  fuel node | tail -n +3  | grep -v "^$" | grep True | wc -l
}

# Currently not used!
# Wait for node count to increase
waitForNode() {
  local cnt
  local initCnt
  local expectCnt

  initCnt=`numberOfNodesUp`
  expectCnt=$[initCnt+1]
  while true
  do
    cnt=`numberOfNodesUp`
    if [ $cnt -eq $expectCnt ]; then
      break
    elif [ $cnt -lt $initCnt ]; then
      error_exit "Node count decreased while waiting, $initCnt -> $cnt"
    elif [ $cnt -gt $expectCnt ]; then
      error_exit "Node count exceeded expect count, $cnt > $expectCnt"
    fi
    sleep 10
    echo -n "[${cnt}]"
  done
  echo "[${cnt}]"
}