cluster init: don't discard the hypervisor
authorGuido Trotter <ultrotter@google.com>
Tue, 2 Dec 2008 10:54:03 +0000 (10:54 +0000)
committerGuido Trotter <ultrotter@google.com>
Tue, 2 Dec 2008 10:54:03 +0000 (10:54 +0000)
On cluster init if the user specifies a default hypervisor (with -t)
which is not in the default list of enabled hypervisors (currently just
xen-pvm) without explicitely specifying the list we silently override
the choice.

With this patch we set the list by default to just the required one, and
we bail out should the list be hand-specified and not contain the
default one. This still has an issue when the user doesn't specify a
default hypervisor but specifies a list which doesn't include xen-pvm:
in this case though we give an error, rather than silently discarding
choices.

Reviewed-by: imsnah

scripts/gnt-cluster

index 53cb6a3..e763aa1 100755 (executable)
@@ -60,13 +60,14 @@ def InitCluster(opts, args):
   if hvlist is not None:
     hvlist = hvlist.split(",")
   else:
-    hvlist = [constants.DEFAULT_ENABLED_HYPERVISOR]
+    hvlist = [opts.default_hypervisor]
 
   # avoid an impossible situation
-  if opts.default_hypervisor in hvlist:
-    default_hypervisor = opts.default_hypervisor
-  else:
-    default_hypervisor = hvlist[0]
+  if opts.default_hypervisor not in hvlist:
+    ToStderr("The default hypervisor requested (%s) is not"
+             " within the enabled hypervisor list (%s)" %
+             (opts.default_hypervisor, hvlist))
+    return 1
 
   hvparams = opts.hvparams
   if hvparams:
@@ -120,7 +121,7 @@ def InitCluster(opts, args):
                         master_netdev=opts.master_netdev,
                         file_storage_dir=opts.file_storage_dir,
                         enabled_hypervisors=hvlist,
-                        default_hypervisor=default_hypervisor,
+                        default_hypervisor=opts.default_hypervisor,
                         hvparams=hvparams,
                         beparams=beparams)
   return 0