From a2ab1424a0d5dad43b05dfd64c79b4b2aaeedefd Mon Sep 17 00:00:00 2001
From: Dimitris Aragiorgis <dimara@grnet.gr>
Date: Thu, 27 Mar 2014 10:55:53 +0200
Subject: [PATCH] Use hostname -f to get node FQDN

Ganeti exports node names with their FQDN. Use hostname -f
to compare the exported variables and decide whether to execute
the hook or not.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
---
 snf-network-dnshook | 6 ++----
 snf-network-hook    | 7 +++----
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/snf-network-dnshook b/snf-network-dnshook
index 4adcc41..a83e8c0 100755
--- a/snf-network-dnshook
+++ b/snf-network-dnshook
@@ -77,10 +77,8 @@ update_dns () {
 
 # Main starts here
 
-host=$(hostname)
-domain=$(hostname -d)
-
 INSTANCE=$GANETI_INSTANCE_NAME
+hostname=$(hostname -f)
 
 # Exit if we do not have instance name.
 # It should be exported to hooks for instance related opcodes.
@@ -89,7 +87,7 @@ if [ -z "$INSTANCE" ]; then
 fi
 
 # Run only in primary node of instance
-if [ "$GANETI_INSTANCE_PRIMARY" != "$host.$domain" ]; then
+if [ "$GANETI_INSTANCE_PRIMARY" != "$hostname" ]; then
   exit 0
 fi
 
diff --git a/snf-network-hook b/snf-network-hook
index c583acc..fd96ac1 100755
--- a/snf-network-hook
+++ b/snf-network-hook
@@ -36,8 +36,7 @@
 source /etc/default/snf-network
 source /usr/lib/snf-network/common.sh
 
-host=$(hostname)
-domain=$(hostname -d)
+hostname=$(hostname -f)
 
 INSTANCE=$GANETI_INSTANCE_NAME
 
@@ -62,13 +61,13 @@ for idx in $(seq $FIRST $LAST); do
   for tag in $NETWORK_TAGS; do
     case $tag in
     $IP_LESS_ROUTED_TAG)
-      if [ "$GANETI_OLD_PRIMARY" == "$host.$domain" ]; then
+      if [ "$GANETI_OLD_PRIMARY" == "$hostname" ]; then
         # This runs on the source node
         # We invoke get_info here in order not to log
         # and calculate things that are not needed eventually
         get_info
         delete_neighbor_proxy
-      elif [ "$GANETI_NEW_PRIMARY" == "$host.$domain" ]; then
+      elif [ "$GANETI_NEW_PRIMARY" == "$hostname" ]; then
         $SNF_NETWORK_LOG $0 "Do nothing in new primary. All done by if-up script"
       fi
     ;;
-- 
GitLab