1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-28 17:57:22 +03:00

F #4809: Fully working vip hooks

This commit is contained in:
Jaime Melis 2017-05-29 17:49:30 +02:00
parent 1e54e36ff0
commit 9d763ef628
5 changed files with 57 additions and 34 deletions

View File

@ -1281,8 +1281,7 @@ HOOK_FT_FILES="share/hooks/ft/host_error.rb \
# HOOK RAFT scripts, to be installed under $VAR_LOCATION/remotes/hooks/raft
#-------------------------------------------------------------------------------
HOOK_RAFT_FILES="share/hooks/raft/leader.sh \
share/hooks/raft/follower.sh"
HOOK_RAFT_FILES="share/hooks/raft/vip.sh"
#-------------------------------------------------------------------------------
# Installation scripts, to be installed under $SHARE_LOCATION

View File

@ -127,6 +127,18 @@ VNC_PORTS = [
# BROADCAST_TIMEOUT_MS: How often heartbeats are sent to followers.
# XMLRPC_TIMEOUT_MS: To timeout raft related API calls
#
# RAFT_LEADER_HOOK: Executed when a server transits from follower->leader
# The purpose of this hook is to configure the Virtual IP.
# COMMAND: raft/vip.sh is a fully working script, this should not be changed
# ARGUMENTS: <interface> and <ip_cidr> must be replaced. For example
# ARGUMENTS = "leader ens1 10.0.0.2/24"
#
# RAFT_FOLLOWER_HOOK: Executed when a server transits from leader->follower
# The purpose of this hook is to configure the Virtual IP.
# COMMAND: raft/vip.sh is a fully working script, this should not be changed
# ARGUMENTS: <interface> and <ip_cidr> must be replaced. For example
# ARGUMENTS = "follower ens1 10.0.0.2/24"
#
# NOTE: Timeout tunning depends on the latency of the servers (network and load)
# as well as the max downtime tolerated by the system. Timeouts needs to be
# greater than 10ms
@ -148,6 +160,18 @@ RAFT = [
XMLRPC_TIMEOUT_MS = 100
]
# Executed when a server transits from follower->leader
# RAFT_LEADER_HOOK = [
# COMMAND = "raft/vip.sh",
# ARGUMENTS = "leader <interface> <ip_cidr>"
# ]
# Executed when a server transits from leader->follower
# RAFT_FOLLOWER_HOOK = [
# COMMAND = "raft/follower.sh",
# ARGUMENTS = "follower <interface> <ip_cidr>"
# ]
#*******************************************************************************
# Default showback cost
#-------------------------------------------------------------------------------
@ -743,16 +767,6 @@ IPAM_MAD = [
# the master OpenNebula.
#-------------------------------------------------------------------------------
# Executed when a server transit from follower->leader
RAFT_LEADER_HOOK = [
COMMAND = "raft/leader.sh"
]
# Executed when a server transit from leader->follower
RAFT_FOLLOWER_HOOK = [
COMMAND = "raft/follower.sh"
]
HM_MAD = [
EXECUTABLE = "one_hm" ]

View File

@ -1,11 +0,0 @@
#!/bin/bash -e
DIR=`dirname $0`
cd $DIR
cd ../../../../
SERVER=$(basename `pwd`)
echo "`date +'%F %H:%M:%S'` [$SERVER] FOLLOWER HOOK" >> /tmp/raft_hooks.log
exit 0

View File

@ -1,11 +0,0 @@
#!/bin/bash -e
DIR=`dirname $0`
cd $DIR
cd ../../../../
SERVER=$(basename `pwd`)
echo "`date +'%F %H:%M:%S'` [$SERVER] LEADER HOOK" >> /tmp/raft_hooks.log
exit 0

32
share/hooks/raft/vip.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash -e
ACTION="$1"
INTERFACE="$2"
IP="$3"
if [ -z "$INTERFACE" ]; then
echo "Missing interface." >&2
exit 1
fi
if [ -z "$IP" ]; then
echo "Missing IP." >&2
exit 1
fi
case $ACTION in
leader)
sudo ip address add $IP dev $INTERFACE
;;
follower)
sudo ip address del $IP dev $INTERFACE
;;
*)
echo "Unknown action '$ACTION'" >&2
exit 1
;;
esac
exit 0