commit ea3a925f19eeaff932410dbc7b571b3a111fe91d
Author: Alexander Schreiber <als@google.com>
Date:   Sat Oct 18 22:27:43 2008 +0000

    Fix gnt-cluster init to set cluster defaults.
    
    Reviewed-by: iustinp

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 5d4e665..10fe728 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -108,7 +108,8 @@ def _InitGanetiServerSetup():
 def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
                 master_netdev, file_storage_dir,
                 secondary_ip=None,
-                vg_name=None):
+                vg_name=None, beparams=None, hvparams=None,
+                enabled_hypervisors=None):
   """Initialise the cluster.
 
   """
@@ -224,6 +225,9 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
     master_netdev=master_netdev,
     cluster_name=clustername.name,
     file_storage_dir=file_storage_dir,
+    enabled_hypervisors=enabled_hypervisors,
+    beparams={constants.BEGR_DEFAULT: beparams},
+    hvparams=hvparams,
     )
   master_node_config = objects.Node(name=hostname.name,
                                     primary_ip=hostname.ip,
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 19ac7f3..1c3fca8 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -50,6 +50,54 @@ def InitCluster(opts, args):
   if opts.lvm_storage and not opts.vg_name:
     vg_name = constants.DEFAULT_VG
 
+  hvlist = opts.enabled_hypervisors
+  if hvlist is not None:
+    hvlist = hvlist.split(",")
+  else:
+    hvlist = constants.DEFAULT_ENABLED_HYPERVISOR
+
+  hvparams = opts.hvparams
+  if hvparams:
+    # a list of (name, dict) we can pass directly to dict()
+    hvparams = dict(opts.hvparams)
+  else:
+    # otherwise init as empty dict
+    hvparams = {}
+
+  beparams = opts.beparams
+  # check for invalid parameters
+  for parameter in beparams:
+    if parameter not in constants.BES_PARAMETERS:
+      print "Invalid backend parameter: %s" % parameter
+      return 1
+
+  # prepare beparams dict
+  for parameter in constants.BES_PARAMETERS:
+    if parameter not in beparams:
+      beparams[parameter] = constants.BEC_DEFAULTS[parameter]
+
+  # type wrangling
+  try:
+    beparams[constants.BE_VCPUS] = int(beparams[constants.BE_VCPUS])
+  except ValueError:
+    print "%s must be an integer" % constants.BE_VCPUS
+    return 1
+
+  beparams[constants.BE_MEMORY] = utils.ParseUnit(beparams[constants.BE_MEMORY])
+
+  # prepare hvparams dict
+  for hv in constants.HYPER_TYPES:
+    if hv not in hvparams:
+      hvparams[hv] = {}
+    for parameter in constants.HVC_DEFAULTS[hv]:
+      if parameter not in hvparams[hv]:
+        hvparams[hv][parameter] = constants.HVC_DEFAULTS[hv][parameter]
+
+  for hv in hvlist:
+    if hv not in constants.HYPER_TYPES:
+      print "invalid hypervisor: %s" % hv
+      return 1
+
   bootstrap.InitCluster(cluster_name=args[0],
                         secondary_ip=opts.secondary_ip,
                         hypervisor_type=opts.hypervisor_type,
@@ -57,7 +105,10 @@ def InitCluster(opts, args):
                         mac_prefix=opts.mac_prefix,
                         def_bridge=opts.def_bridge,
                         master_netdev=opts.master_netdev,
-                        file_storage_dir=opts.file_storage_dir)
+                        file_storage_dir=opts.file_storage_dir,
+                        enabled_hypervisors=hvlist,
+                        hvparams=hvparams,
+                        beparams=beparams)
   return 0
 
 
@@ -445,6 +496,19 @@ commands = {
                         help="No support for lvm based instances"
                              " (cluster-wide)",
                         action="store_false", default=True,),
+            make_option("--enabled-hypervisors", dest="enabled_hypervisors",
+                        help="Comma-separated list of hypervisors",
+                        type="string", default=None),
+            ikv_option("-H", "--hypervisor-parameters", dest="hvparams",
+                       help="Hypervisor and hypervisor options, in the"
+                         " format"
+                       " hypervisor:option=value,option=value,...",
+                       default=[],
+                       action="append",
+                       type="identkeyval"),
+            keyval_option("-B", "--backend-parameters", dest="beparams",
+                          type="keyval", default={},
+                          help="Backend parameters"),
             ],
            "[opts...] <cluster_name>",
            "Initialises a new cluster configuration"),
