I fixed a bug in the patch.

regards
Klaus

Am 10.03.2011 19:25, schrieb Klaus Darilion:
> Am 08.03.2011 13:32, schrieb Klaus Darilion:
>> Hi!
>>
>> Instead of adding a virtual IP address to an interface
>> (ocf:heartbeat:IPaddr2), how do I manage a physical interface? Are there
>> any special resource scripts?
> 
> Hi!
> 
> I tried to reuse ocf:heartbeat:IPaddr2 to manage and IP address as
> primary IP address on a certain interface. Basically
> ocf:heartbeat:IPaddr2 works, but there are problems if the interface is
> down but the IP address is configured.
>  1. the failure won't be detected
>  2. adding the IP will fail if the IP is already added
> 
> Thus this patch:
> 1. also checks if the interface is up, not only if the IP address is
> configured
> 2. before adding the IP address, it will delete the IP address if the
> address is already configured (on any interface, with any netmask). Thus
> the "add" will always work.
> 
> You might want to add it.
> 
> regards
> Klaus
> 
> 
> 
> _______________________________________________
> Pacemaker mailing list: Pacemaker@oss.clusterlabs.org
> http://oss.clusterlabs.org/mailman/listinfo/pacemaker
> 
> Project Home: http://www.clusterlabs.org
> Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
> Bugs: 
> http://developerbugs.linux-foundation.org/enter_bug.cgi?product=Pacemaker
--- IPaddr2     2011-03-10 17:03:25.000000000 +0100
+++ IPaddr2Interface    2011-03-10 19:56:37.000000000 +0100
@@ -12,6 +12,7 @@
 #
 # Copyright (c) 2003 Tuomo Soini
 # Copyright (c) 2004-2006 SUSE LINUX AG, Lars Marowsky-Brée
+# Copyright (c) 2004-2011 IPCom GmbH, www.ipcom.at, Klaus Darilion
 #                    All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -356,16 +357,33 @@
 #      is an interface name (e.g., "eth0").
 #
 find_interface() {
+       ipaddr="$1"
        #
        # List interfaces but exclude FreeS/WAN ipsecN virtual interfaces
        #
-       local iface=`$IP2UTIL -o -f inet addr show | grep "\ $BASEIP/$NETMASK" \
+       local iface=`$IP2UTIL -o -f inet addr show | grep "\ $ipaddr/" \
                | cut -d ' ' -f2 | grep -v '^ipsec[0-9][0-9]*$'`
        echo $iface
        return 0
 }
 
 #
+#      Find out if the interface is up, return "up" or "down"
+#
+interface_status() {
+       iface="$1"
+       local status="`$IP2UTIL -o link show "$iface" up`"
+
+       if [ -z "$status" ]; then
+               echo "down"
+               return 0
+       fi
+
+       echo "up"
+       return 0
+}
+
+#
 #        Delete an interface
 #
 delete_interface () {
@@ -391,6 +409,17 @@
        iface="$4"
        label="$5"
 
+       # If the address is already configured, the adding will fail
+       # (eg. interface is configured, but DOWN). Therefore always
+       # delete the IP address first.
+        cur_nic="`find_interface $ipaddr`"
+       if [ -n "$cur_nic" ]; then
+               CMD="$IP2UTIL -f inet addr del $ipaddr dev $cur_nic"
+
+               ocf_log info "$CMD"
+               $CMD
+       fi
+
        CMD="$IP2UTIL -f inet addr add $ipaddr/$netmask brd $broadcast dev 
$iface"
 
        if [ ! -z "$label" ]; then
@@ -557,6 +586,12 @@
                        ;;
                esac
 
+               int_status="`interface_status $cur_nic`"
+               if [ "$int_status" = "down" ]; then
+                       echo "no"
+                       return 0
+               fi
+
                echo "ok"
                return 0
        fi
_______________________________________________
Pacemaker mailing list: Pacemaker@oss.clusterlabs.org
http://oss.clusterlabs.org/mailman/listinfo/pacemaker

Project Home: http://www.clusterlabs.org
Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
Bugs: http://developerbugs.linux-foundation.org/enter_bug.cgi?product=Pacemaker

Reply via email to