Add a shell script that will be the default replacement for the body of backend.ActivateMasterIp and backend.DeactivateMasterIp.
Signed-off-by: Andrea Spadaccini <spadac...@google.com> --- Makefile.am | 2 + tools/master-ip-setup | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 0 deletions(-) create mode 100755 tools/master-ip-setup diff --git a/Makefile.am b/Makefile.am index f9ebfeb..9feabe2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -549,6 +549,7 @@ nodist_pkglib_python_scripts = \ pkglib_SCRIPTS = \ daemons/daemon-util \ tools/kvm-ifup \ + tools/master-ip-setup \ $(pkglib_python_scripts) nodist_pkglib_SCRIPTS = \ @@ -578,6 +579,7 @@ EXTRA_DIST = \ $(pkglib_python_scripts) \ devel/upload.in \ tools/kvm-ifup.in \ + tools/master-ip-setup \ $(docdot) \ $(docpng) \ $(docrst) \ diff --git a/tools/master-ip-setup b/tools/master-ip-setup new file mode 100755 index 0000000..4c4e893 --- /dev/null +++ b/tools/master-ip-setup @@ -0,0 +1,114 @@ +#!/bin/bash +# + +# Copyright (C) 2011 Google Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +USAGE_MSG="Usage: $0 {start|stop}" +PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin + +# Check the environment variables common to both the actions +check_common_env() { + if [[ -z $MASTER_IP ]]; then + echo "No master IP address specified." + exit 1 + fi + + if [[ -z $MASTER_NETMASK ]]; then + echo "No master netmask specified." + exit 1 + fi + + if [[ -z $MASTER_NETDEV ]]; then + echo "No master network device specified." + exit 1 + fi +} + +# Start the master IP +start() { + if [[ -z $CLUSTER_IP_VERSION ]]; then + echo "No cluster IP version specified." + exit 1 + fi + + if [[ $CLUSTER_IP_VERSION == 4 ]]; then + ARP_COMMAND="arping -q -U -c 3 -I $MASTER_NETDEV -s $MASTER_IP $MASTER_IP" + elif [[ $CLUSTER_IP_VERSION == 6 ]]; then + ARP_COMMAND="ndisc6 -q r 3 $MASTER_IP $MASTER_NETDEV" + else + echo "Invalid cluster IP version specified: $CLUSTER_IP_VERSION" + exit 1 + fi + + # Check if the master IP is already configured on this machine + ip addr show | grep $MASTER_IP/$MASTER_NETMASK + + if [[ $? == 0 ]]; then + echo "Master IP already configured on this machine. Doing nothing." + exit 0 + fi + + # Check if the master IP is already configured on another machine + ping $MASTER_IP -w 2 + if [[ $? == 0 ]]; then + echo "Error: master IP configured on another machine." + exit 1 + fi + + ip address add $MASTER_IP/$MASTER_NETMASK dev $MASTER_NETDEV label $MASTER_NETDEV:0 + + if [[ $? != 0 ]]; then + echo "Error during the activation of the master IP address" + exit 1 + fi + + # Send gratuituous ARP to update neighbours' ARP cache + $ARP_COMMAND +} + +# Stop the master IP +stop() { + ip address del $MASTER_IP/$MASTER_NETMASK dev $MASTER_NETDEV + + if [[ $? != 0 ]]; then + echo "Error during the deactivation of the master IP address" + exit 1 + fi +} + +if (( $# < 1 )); then + echo $USAGE_MSG + exit 1 +fi + +check_common_env + +case "$1" in + start) + start + ;; + stop) + stop + ;; + *) + echo $USAGE_MSG + exit 1 + ;; +esac + +exit 0 -- 1.7.3.1