Make cluster name optional for "create cluster"
authorMartin Schwenke <martin@meltin.net>
Fri, 20 Jun 2014 04:58:37 +0000 (14:58 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 25 Jun 2014 10:46:16 +0000 (20:46 +1000)
It can either be specified in the configuration file via the CLUSTER
variable.  If it isn't set there then if the configuration file name
is of the form "foo.autocluster" then the cluster name is "foo".

Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster

index 655f04992c6f7a4788b705ed82550adb75086d15..7afb74bc56bb93ad16fc9725da0eb70859aff016 100755 (executable)
@@ -55,7 +55,7 @@ EOF
      create base
            create a base image
 
-     create cluster CLUSTERNAME
+     create cluster [ CLUSTERNAME ]
            create a full cluster
 
      create node CLUSTERNAME IP_OFFSET
@@ -468,7 +468,9 @@ cluster_created_hooks=
 
 create_cluster ()
 {
-    CLUSTER="$1"
+    # Use $1.  If not set then use value from configuration file.
+    CLUSTER="${1:-${CLUSTER}}"
+    [ -n "$CLUSTER" ] || die "\$CLUSTER not set"
 
     sanity_check_cluster_name
 
@@ -1191,8 +1193,20 @@ eval set -- "$getopt_output"
 
 while true ; do
     case "$1" in
-       # force at least ./local_file to avoid accidental file from $PATH
-       -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
+       -c)
+           b=$(basename $2)
+           # force at least ./local_file to avoid accidental file
+           # from $PATH
+           . "$(dirname $2)/${b}"
+           # If $CLUSTER is unset then try to base it on the filename
+           if [ ! -n "$CLUSTER" ] ; then
+               case "$b" in
+                   *.autocluster)
+                       CLUSTER="${b%.autocluster}"
+               esac
+           fi
+           shift 2
+           ;;
        -e) no_sanity=1 ; run_hooks post_config_hooks ; eval "$2" ; exit ;;
        -E) eval "$2" ; shift 2 ;;
        -x) set -x; shift ;;