Support os variants
authorGuido Trotter <ultrotter@google.com>
Fri, 7 Aug 2009 13:01:16 +0000 (14:01 +0100)
committerGuido Trotter <ultrotter@google.com>
Sat, 8 Aug 2009 09:26:48 +0000 (10:26 +0100)
This is a Ganeti 2.1 design feature. It's not implemented yet in 2.1,
but its implementation in the debootstrap OS is totally backwards
compatible. If no OS_VARIANT environment variable is passed in,
everything proceeds as before, otherwise a instance-deboostrap tries
to load a config file from a specially configured directory, which can
be used to override any variable in the defaults file (which is sourced
at the beginning as it was before.

By default only the "default" variant is exported, which is shipped as
an empty config file.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

Makefile.am
common.sh.in
variants.list [new file with mode: 0644]

index de9dcf9..7df7151 100644 (file)
@@ -1,9 +1,10 @@
 osname=$(subst ganeti-instance-,,$(PACKAGE))
 
 osdir=$(OS_DIR)/$(osname)
+variantsdir="$(DESTDIR)${sysconfdir}/ganeti/instance-debootstrap/variants"
 
 dist_os_SCRIPTS = create import export rename
-dist_os_DATA = ganeti_api_version
+dist_os_DATA = ganeti_api_version variants
 os_DATA = common.sh
 
 dist_doc_DATA = COPYING NEWS README
@@ -18,4 +19,8 @@ common.sh: common.sh.in Makefile
        $(do_subst) < $< > $@
        chmod +x $@
 
+install-exec-local:
+       @mkdir_p@ "$(variantsdir)"
+       touch "$(variantsdir)/default.conf"
+
 CLEANFILES = common.sh
index 167bb00..130201f 100644 (file)
@@ -143,6 +143,7 @@ fi
 : ${ARCH:=""}
 : ${EXTRA_PKGS:=""}
 : ${CUSTOMIZE_DIR:="@sysconfdir@/ganeti/instance-debootstrap.d"}
+: ${VARIANTS_DIR:="@sysconfdir@/ganeti/instance-debootstrap/variants"}
 : ${GENERATE_CACHE:="yes"}
 : ${CLEAN_CACHE:="14"} # number of days to keep a cache file
 if [ -z "$OS_API_VERSION" -o "$OS_API_VERSION" = "5" ]; then
@@ -178,3 +179,27 @@ else
   log_error "Unknown OS API VERSION $OS_API_VERSION"
   exit 1
 fi
+
+if [ -n "$OS_VARIANT" ]; then
+  if [ ! -d "$VARIANTS_DIR" ]; then
+    log_error "OS Variants directory $VARIANTS_DIR doesn't exist"
+    exit 1
+  fi
+  VARIANT_CONFIG="$VARIANTS_DIR/$OS_VARIANT.conf"
+  if [ -f "$VARIANTS_CONFIG" ]; then
+    . "$VARIANTS_CONFIG"
+  else
+    if grep -qxF "$OS_VARIANT" variants.list; then
+      log_error "ERROR: instance-debootstrap configuration error"
+      log_error "  Published variant $OS_VARIANT is missing its config file"
+      log_error "  Please create $VARIANT_CONFIG or unpublish the variant"
+      log_error "  (by removing $OS_VARIANT from variants.list)"
+    else
+      log_error "Unofficial variant $OS_VARIANT is unsupported"
+      log_error "Most probably this is a user error, forcing a wrong name"
+      log_error "To support this variant please create file $VARIANT_CONFIG"
+    fi
+    exit 1
+  fi
+fi
+
diff --git a/variants.list b/variants.list
new file mode 100644 (file)
index 0000000..4ad96d5
--- /dev/null
@@ -0,0 +1 @@
+default