Update config version number when downgrading
[ganeti-local] / tools / vcluster-setup.in
index cba73ba..ad918bd 100644 (file)
@@ -23,12 +23,14 @@ shopt -s extglob
 
 readonly self=$(readlink -f $0)
 readonly ensure_dirs=@PKGLIBDIR@/ensure-dirs
-readonly action_shortcuts=( start stop restart status )
+readonly action_shortcuts=( start stop restart status watcher )
 readonly default_nodecount=5
 readonly default_instcount=10
 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
@@ -41,8 +43,8 @@ readonly max_node_count=$((first_inst_ipaddr_octet - first_node_ipaddr_octet))
 readonly max_instance_count=$((255 - first_inst_ipaddr_octet))
 
 usage() {
-  echo "Usage: $0 [-c <number>] [-i <number>] [-p <prefix>] [-n <netdev>]"\
-       '<directory>'
+  echo "Usage: $0 [-E] [-N] [-c <number>] [-i <number>] [-p <prefix>]"\
+       '[-n <netdev>] [-I <path>] <directory>'
   echo
   echo 'Options:'
   echo "  -c  Number of virtual nodes (defaults to $default_nodecount)"
@@ -50,6 +52,9 @@ usage() {
   echo "  -p  IPv4 network prefix (defaults to $default_netprefix)"
   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_filename"
+  echo '  -N  Do not configure networking'
 }
 
 # Variables for options
@@ -57,9 +62,12 @@ nodecount=$default_nodecount
 instcount=$default_instcount
 netprefix=$default_netprefix
 netdev=$default_netdev
+initscript=$default_initscript
+etchosts=1
+networking=1
 
 # Parse options
-while getopts :hc:p:n:i: opt; do
+while getopts :hENc:p:n:i:I: opt; do
   case "$opt" in
     h)
       usage
@@ -99,6 +107,19 @@ while getopts :hc:p:n:i: opt; do
         exit 1
       fi
     ;;
+    I)
+      initscript="$OPTARG"
+      if [[ ! -x $initscript ]]; then
+        echo "Init script '$initscript' is not executable" >&2
+        exit 1
+      fi
+      ;;
+    E)
+      etchosts=
+      ;;
+    N)
+      networking=
+      ;;
     \?)
       echo "Invalid option: -$OPTARG" >&2
       usage >&2
@@ -166,9 +187,9 @@ setup_node() {
   fi
 
   mkdir -p \
-    $nodedir/etc/default \
-    $nodedir/var/lock\
-    $nodedir/var/{lib,log,run}/ganeti
+    $nodedir@SYSCONFDIR@/{default,ganeti} \
+    $nodedir@LOCALSTATEDIR@/lock\
+    $nodedir@LOCALSTATEDIR@/{lib,log,run}/ganeti
 
   GANETI_HOSTNAME=$(node_hostname $number) \
   GANETI_ROOTDIR=$nodedir \
@@ -205,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)"
@@ -221,7 +242,7 @@ setup_etc_hosts() {
       done
     } > $tmpfile && \
     chmod 0644 $tmpfile && \
-    mv $tmpfile /etc/hosts && \
+    mv $tmpfile $etc_hosts_filename && \
     trap - EXIT
   )
 }
@@ -242,8 +263,13 @@ setup_scripts() {
       echo '#!/bin/bash'
       for ((i=0; i < nodecount; ++i)); do
         local name=$(node_hostname $i)
-        echo "echo 'Action \"$action\" for virtual node \"$name\" ...'"
-        echo "$name/cmd /etc/init.d/ganeti $action"
+        if [[ $action = watcher ]]; then
+          echo "echo 'Running watcher for virtual node \"$name\" ..."
+          echo "$name/cmd ganeti-watcher \"\$@\""
+        else
+          echo "echo 'Action \"$action\" for virtual node \"$name\" ...'"
+          echo "$name/cmd $initscript $action \"\$@\""
+        fi
       done
     } > $rootdir/$action-all
     chmod +x $rootdir/$action-all
@@ -263,11 +289,12 @@ EOF
   cat <<EOF
 
 Initialize cluster:
-  cd $rootdir && node1/cmd gnt-cluster init --no-etc-hosts $cluster_name
+  cd $rootdir && node1/cmd gnt-cluster init --no-etc-hosts \\
+    --no-ssh-init --no-lvm-storage --no-drbd-storage $cluster_name
 
 Change cluster settings:
   cd $rootdir && node1/cmd gnt-cluster modify \\
-    --enabled-hypervisors=fake \\
+    --enabled-hypervisors=fake --specs-nic-count=min=0 \\
     --specs-disk-size=min=0 --specs-disk-count=min=0
 
 Add node:
@@ -276,8 +303,12 @@ EOF
 }
 
 setup_all_nodes
-setup_etc_hosts
-setup_network_interfaces
+if [[ -n "$etchosts" ]]; then
+  setup_etc_hosts
+fi
+if [[ -n "$networking" ]]; then
+  setup_network_interfaces
+fi
 setup_scripts
 show_info