Guillaume Lambert | 824f996 | 2021-03-09 16:56:08 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 2 | |
Guillaume Lambert | 824f996 | 2021-03-09 16:56:08 +0100 | [diff] [blame] | 3 | {{/* |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 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 Latusek | e0e8ca7 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 17 | */}} |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 18 | |
| 19 | set -e |
| 20 | primary=${SDNC_IS_PRIMARY_CLUSTER:-true} |
| 21 | |
| 22 | url=http://sdnc:8282/restconf/operations/cluster-admin:change-member-voting-states-for-all-shards |
| 23 | username="${ODL_USERNAME:-{{.Values.odl.restconf.username}}}" |
| 24 | password="${ODL_PASSWORD:-{{.Values.odl.restconf.password}}}" |
| 25 | LOGFILE="/app/geo.log" |
| 26 | enableDebugLogging=true |
| 27 | |
| 28 | debugLog(){ |
Guillaume Lambert | 5f4af05 | 2021-03-09 21:52:32 +0100 | [diff] [blame^] | 29 | if [ "$enableDebugLogging" = true ]; then |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 30 | if [ $# -eq 0 ]; then |
| 31 | echo "" >> $LOGFILE |
| 32 | else |
| 33 | echo $( date ) $@ >> $LOGFILE |
| 34 | fi |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | |
| 39 | if [ "$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 | }' |
| 71 | else |
| 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 | }' |
| 103 | fi |
| 104 | |
| 105 | status=$(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) |
| 106 | if [ $status -ne 200 ];then |
| 107 | debugLog "Switch voting failed. status: $status ,username: $username ,password: $password ,votingState: $votingState ,url:$url " |
| 108 | echo "failure" |
| 109 | else |
| 110 | echo "success" |
| 111 | fi |
| 112 | |