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