Skip to content
Snippets Groups Projects
Commit 36683bad authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

vcluster-setup: Stop hardcoding /etc/hosts


… use a constant instead.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 48967eb0
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ readonly default_netprefix=192.0.2 ...@@ -30,6 +30,7 @@ readonly default_netprefix=192.0.2
readonly default_netdev=eth0 readonly default_netdev=eth0
readonly default_initscript=@SYSCONFDIR@/init.d/ganeti readonly default_initscript=@SYSCONFDIR@/init.d/ganeti
readonly cluster_name=cluster readonly cluster_name=cluster
readonly etc_hosts_filename=/etc/hosts
# IP address space: # IP address space:
# Cluster: .1 # Cluster: .1
...@@ -52,7 +53,7 @@ usage() { ...@@ -52,7 +53,7 @@ usage() {
echo ' -n Network device for virtual IP addresses (defaults to'\ echo ' -n Network device for virtual IP addresses (defaults to'\
"$default_netdev)" "$default_netdev)"
echo " -I Path to init script (defaults to $default_initscript)" 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' echo ' -N Do not configure networking'
} }
...@@ -225,13 +226,13 @@ setup_all_nodes() { ...@@ -225,13 +226,13 @@ setup_all_nodes() {
} }
setup_etc_hosts() { setup_etc_hosts() {
echo 'Configuring /etc/hosts ...' >&2 echo "Configuring $etc_hosts_filename ..." >&2
( (
set -e -u 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 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" echo "$netprefix.1 $cluster_name"
for ((i=0; i < nodecount; ++i)); do for ((i=0; i < nodecount; ++i)); do
echo "$(node_ipaddr $i) $(node_hostname $i)" echo "$(node_ipaddr $i) $(node_hostname $i)"
...@@ -241,7 +242,7 @@ setup_etc_hosts() { ...@@ -241,7 +242,7 @@ setup_etc_hosts() {
done done
} > $tmpfile && \ } > $tmpfile && \
chmod 0644 $tmpfile && \ chmod 0644 $tmpfile && \
mv $tmpfile /etc/hosts && \ mv $tmpfile $etc_hosts_filename && \
trap - EXIT trap - EXIT
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment