From 36683bada012413a8451b39f96fdae5f9ff28767 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 10 Oct 2012 10:53:00 +0200
Subject: [PATCH] vcluster-setup: Stop hardcoding /etc/hosts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

… use a constant instead.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 tools/vcluster-setup.in | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/vcluster-setup.in b/tools/vcluster-setup.in
index edaeb2d10..ab8affacc 100644
--- a/tools/vcluster-setup.in
+++ b/tools/vcluster-setup.in
@@ -30,6 +30,7 @@ readonly default_netprefix=192.0.2
 readonly default_netdev=eth0
 readonly default_initscript=@SYSCONFDIR@/init.d/ganeti
 readonly cluster_name=cluster
+readonly etc_hosts_filename=/etc/hosts
 
 # IP address space:
 # Cluster: .1
@@ -52,7 +53,7 @@ usage() {
   echo '  -n  Network device for virtual IP addresses (defaults to'\
        "$default_netdev)"
   echo "  -I  Path to init script (defaults to $default_initscript)"
-  echo '  -E  Do not modify /etc/hosts'
+  echo "  -E  Do not modify $etc_hosts_filename"
   echo '  -N  Do not configure networking'
 }
 
@@ -225,13 +226,13 @@ setup_all_nodes() {
 }
 
 setup_etc_hosts() {
-  echo 'Configuring /etc/hosts ...' >&2
+  echo "Configuring $etc_hosts_filename ..." >&2
   (
     set -e -u
-    local -r tmpfile=$(mktemp /etc/hosts.vcluster.XXXXX)
+    local -r tmpfile=$(mktemp $etc_hosts_filename.vcluster.XXXXX)
     trap "rm -f $tmpfile" EXIT
     {
-      egrep -v "^$netprefix.[[:digit:]]+[[:space:]]" /etc/hosts
+      egrep -v "^$netprefix.[[:digit:]]+[[:space:]]" $etc_hosts_filename
       echo "$netprefix.1 $cluster_name"
       for ((i=0; i < nodecount; ++i)); do
         echo "$(node_ipaddr $i) $(node_hostname $i)"
@@ -241,7 +242,7 @@ setup_etc_hosts() {
       done
     } > $tmpfile && \
     chmod 0644 $tmpfile && \
-    mv $tmpfile /etc/hosts && \
+    mv $tmpfile $etc_hosts_filename && \
     trap - EXIT
   )
 }
-- 
GitLab