#!/bin/bash

# Copyright (C) Metaswitch Networks 2016
# If license terms are provided to you in a COPYING file in the root directory
# of the source code repository by which you are accessing this code, then
# the license outlined in that COPYING file applies to your use.
# Otherwise no rights are granted except for those provided to you by
# Metaswitch Networks in a separate written agreement.

set -ue

local_site_name=site1
etcd_key=clearwater
. /etc/clearwater/config

. /usr/share/clearwater/utils/check-root-permissions 1

if [ $# -ne 3 ] && [ $# -ne 4 ]
then
  echo "Usage: mark_node_failed <node_type> <datastore> <failed_node_ip> [<etcd_ip>]"
  exit 1
fi

node_type=$1
datastore=$2
dead_node_ip=$3
# If etcd_ip is not provided, first default to management_local_ip, and then
# default to local_ip.
local_ip=${management_local_ip:-$local_ip}
etcd_ip=${4:-$local_ip}

/usr/share/clearwater/clearwater-cluster-manager/env/bin/python /usr/share/clearwater/clearwater-cluster-manager/scripts/mark_node_failed.py $etcd_ip $local_site_name $node_type $datastore $dead_node_ip $etcd_key
