From c074a9e8d902c4c1a06e81f9af3d026bbef23160 Mon Sep 17 00:00:00 2001
From: Helga Velroyen <helgav@google.com>
Date: Thu, 14 Mar 2013 11:49:21 +0100
Subject: [PATCH] gnt-cluster init: add enabled_storage_types parameter

This patch extends the 'gnt-cluster init' command to set the list
of enabled storage types on cluster creation.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/bootstrap.py          | 16 +++++++++++++++-
 lib/client/gnt_cluster.py | 10 +++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index cffaaada3..7bd189c70 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -372,11 +372,14 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                 maintain_node_health=False, drbd_helper=None, uid_pool=None,
                 default_iallocator=None, primary_ip_version=None, ipolicy=None,
                 prealloc_wipe_disks=False, use_external_mip_script=False,
-                hv_state=None, disk_state=None):
+                hv_state=None, disk_state=None, enabled_storage_types=None):
   """Initialise the cluster.
 
   @type candidate_pool_size: int
   @param candidate_pool_size: master candidate pool size
+  @type enabled_storage_types: list of string
+  @param enabled_storage_types: list of storage types to be used in this
+    cluster
 
   """
   # TODO: complete the docstring
@@ -393,6 +396,16 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                                " entries: %s" % invalid_hvs,
                                errors.ECODE_INVAL)
 
+  if not enabled_storage_types:
+    raise errors.OpPrereqError("Enabled storage types list must contain at"
+                               " least one member", errors.ECODE_INVAL)
+  invalid_storage_types = \
+    set(enabled_storage_types) - constants.VALID_STORAGE_TYPES
+  if invalid_storage_types:
+    raise errors.OpPrereqError("Enabled storage_types contains invalid"
+                               " entries: %s" % invalid_storage_types,
+                               errors.ECODE_INVAL)
+
   try:
     ipcls = netutils.IPAddress.GetClassFromIpVersion(primary_ip_version)
   except errors.ProgrammerError:
@@ -621,6 +634,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
     ipolicy=full_ipolicy,
     hv_state_static=hv_state,
     disk_state_static=disk_state,
+    enabled_storage_types=enabled_storage_types,
     )
   master_node_config = objects.Node(name=hostname.name,
                                     primary_ip=hostname.ip,
diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py
index 61b3f604e..b5e1b7753 100644
--- a/lib/client/gnt_cluster.py
+++ b/lib/client/gnt_cluster.py
@@ -194,6 +194,12 @@ def InitCluster(opts, args):
 
   hv_state = dict(opts.hv_state)
 
+  enabled_storage_types = opts.enabled_storage_types
+  if enabled_storage_types is not None:
+    enabled_storage_types = enabled_storage_types.split(",")
+  else:
+    enabled_storage_types = list(constants.DEFAULT_ENABLED_STORAGE_TYPES)
+
   bootstrap.InitCluster(cluster_name=args[0],
                         secondary_ip=opts.secondary_ip,
                         vg_name=vg_name,
@@ -221,6 +227,7 @@ def InitCluster(opts, args):
                         use_external_mip_script=external_ip_setup_script,
                         hv_state=hv_state,
                         disk_state=disk_state,
+                        enabled_storage_types=enabled_storage_types,
                         )
   op = opcodes.OpClusterPostInit()
   SubmitOpCode(op, opts=opts)
@@ -1495,7 +1502,8 @@ commands = {
      MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT, DRBD_HELPER_OPT, NODRBD_STORAGE_OPT,
      DEFAULT_IALLOCATOR_OPT, PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT,
      NODE_PARAMS_OPT, GLOBAL_SHARED_FILEDIR_OPT, USE_EXTERNAL_MIP_SCRIPT,
-     DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT] + INSTANCE_POLICY_OPTS,
+     DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT, ENABLED_STORAGE_TYPES_OPT]
+     + INSTANCE_POLICY_OPTS,
     "[opts...] <cluster_name>", "Initialises a new cluster configuration"),
   "destroy": (
     DestroyCluster, ARGS_NONE, [YES_DOIT_OPT],
-- 
GitLab