Updates docs for SR1 with final revision
[genesis.git] / fuel / prototypes / auto-deploy / deploy / functions / dea-api.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
13
14 ########################################################################
15 # Internal functions BEGIN
16
17
18
19 dea_f_err()
20 {
21     local rc
22     local cmd
23
24     rc=$1
25     shift
26
27     if [ -n "$rc" ]; then
28         echo "Error ($rc): $@" >&2
29     else
30         echo "Error: $@" >&2
31     fi
32 }
33
34 dea_f_run()
35 {
36   $@
37   rc=$?
38   if [ $rc -ne 0 ]; then
39      dea_f_err $rc "Error running $@"
40      return $rc
41   fi
42 }
43
44 # Internal functions END
45 ########################################################################
46
47 true=0
48 false=1
49
50 # API: Get the DEA API version supported by this adapter
51 dea_getApiVersion ()
52 {
53     echo "1.0"
54 }
55
56
57 # API: Node numbering is sequential.
58
59
60 # API: Get the role for this node
61 # API: Argument 1: node id
62 dea_getNodeRole()
63 {
64     $DEAPARSE $DEAFILE getNodeRole $@
65
66 }
67
68 # API: Get IP address of Fuel master
69 dea_getFuelIp()
70 {
71     $DEAPARSE $DEAFILE getProperty fuel ADMIN_NETWORK ipaddress
72 }
73
74 # API: Get netmask Fuel master
75 dea_getFuelNetmask()
76 {
77     $DEAPARSE $DEAFILE getProperty fuel ADMIN_NETWORK netmask
78 }
79
80 # API: Get gateway address of Fuel master
81 # FIXME: This is currently not in the DEA, so make the gatway the ..1
82 # FiXME: of the IP
83 dea_getFuelGateway()
84 {
85     $DEAPARSE $DEAFILE getProperty fuel ADMIN_NETWORK ipaddress | \
86          sed 's/.[0-9]*$/.1/'
87 }
88
89 # API: Get gateway address of Fuel master
90 dea_getFuelHostname()
91 {
92     $DEAPARSE $DEAFILE getProperty fuel HOSTNAME
93 }
94
95 # API: Get DNS address of Fuel master
96 dea_getFuelDns()
97 {
98     $DEAPARSE $DEAFILE getProperty fuel DNS_UPSTREAM
99 }
100
101 # API: Convert a normal MAC to a Fuel short mac for --node-id
102 dea_convertMacToShortMac()
103 {
104     echo $1 | sed 's/.*..:..:..:..:\(..:..\).*/\1/' | tr [A-Z] [a-z]
105 }
106
107
108 # API: Get property from DEA file
109 # API: Argument 1: search path, as e.g. "fuel ADMIN_NETWORK ipaddress"
110 dea_getProperty()
111 {
112     $DEAPARSE $DEAFILE getProperty $@
113 }
114
115 # API: Convert DHA node id to Fuel cluster node id
116 # API: Look for lowest Fuel node number, this will be DHA node 1
117 # API: Argument: node id
118 dea_getClusterNodeId()
119 {
120     local baseId
121     local inId
122     local fuelIp
123
124     inId=$1
125     fuelIp=`dea_getFuelIp`
126
127     baseId=`ssh root@${fuelIp} fuel node | tail -n +3 | awk '{ print $1 }'| sed 's/ //g' | sort -n | head -1`
128     echo "$[inId + baseId - 1]"
129 }
130
131 # API: Entry point for dea functions
132 # API: Typically do not call "dea_node_zeroMBR" but "dea node_ZeroMBR"
133 # API:
134 # API: Before calling dea, the adapter file must gave been sourced with
135 # API: the DEA file name as argument
136 dea()
137 {
138     if [ -z "$DEAFILE" ]; then
139         error_exit "dea_setup has not been run"
140     fi
141
142
143     if type dea_$1 &>/dev/null; then
144         cmd=$1
145         shift
146         dea_$cmd $@
147         return $?
148     else
149         error_exit "No such function dea_$1 defined"
150     fi
151 }
152
153 if [ "$1" == "api" ]; then
154   egrep "^# API: |dea.*\(\)" $0 | sed 's/^# API: /# /' | grep -v dea_f_ | sed 's/)$/)\n/'
155 else
156     deatopdir=$(dirname $(readlink -f $BASH_SOURCE))
157     DEAPARSE="$deatopdir/deaParse.py"
158     DEAFILE=$1
159
160     if [ ! -f $DEAFILE ]; then
161         error_exit "No such DEA file: $DEAFILE"
162     else
163         echo "Adapter init"
164         echo "$@"
165         echo "DEAPARSE: $DEAPARSE"
166         echo "DEAFILE: $DEAFILE"
167     fi
168 fi
169
170
171