blob: 091643f174de309d22f0320203294757aff8381d [file] [log] [blame]
Jakub Latuseke0e8ca72020-10-21 13:36:29 +02001{{/*
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04002#/bin/sh
3
4# Copyright © 2018 Amdocs
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
Jakub Latuseke0e8ca72020-10-21 13:36:29 +020017*/}}
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040018
19set -e
20primary=${SDNC_IS_PRIMARY_CLUSTER:-true}
21
22url=http://sdnc:8282/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards
23username="${ODL_USERNAME:-{{.Values.odl.restconf.username}}}"
24password="${ODL_PASSWORD:-{{.Values.odl.restconf.password}}}"
25LOGFILE="/app/geo.log"
26enableDebugLogging=true
27
28debugLog(){
29 if [ "$enableDebugLogging" == true ]; then
30 if [ $# -eq 0 ]; then
31 echo "" >> $LOGFILE
32 else
33 echo $( date ) $@ >> $LOGFILE
34 fi
35 fi
36}
37
38
39if [ "$primary" = "true" ]; then
40 votingState='
41{
42 "input": {
43 "member-voting-state": [
44 {
45 "member-name": "member-1",
46 "voting": true
47 },
48 {
49 "member-name": "member-2",
50 "voting": true
51 },
52 {
53 "member-name": "member-3",
54 "voting": true
55 },
56 {
57 "member-name": "member-4",
58 "voting": false
59 },
60 {
61 "member-name": "member-5",
62 "voting": false
63 },
64 {
65 "member-name": "member-6",
66 "voting": false
67 }
68 ]
69 }
70}'
71else
72 votingState='
73{
74 "input": {
75 "member-voting-state": [
76 {
77 "member-name": "member-1",
78 "voting": false
79 },
80 {
81 "member-name": "member-2",
82 "voting": false
83 },
84 {
85 "member-name": "member-3",
86 "voting": false
87 },
88 {
89 "member-name": "member-4",
90 "voting": true
91 },
92 {
93 "member-name": "member-5",
94 "voting": true
95 },
96 {
97 "member-name": "member-6",
98 "voting": true
99 }
100 ]
101 }
102}'
103fi
104
105status=$(curl -s -u $username:$password -o /dev/null -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d "$votingState" -w "%{http_code}\n" $url 2> /dev/null)
106if [ $status -ne 200 ];then
107 debugLog "Switch voting failed. status: $status ,username: $username ,password: $password ,votingState: $votingState ,url:$url "
108 echo "failure"
109else
110 echo "success"
111fi
112