From 83a309f9cd7f697572805c37eed0416e4d24b93c Mon Sep 17 00:00:00 2001
From: Helga Velroyen <helgav@google.com>
Date: Tue, 26 Mar 2013 13:11:07 +0100
Subject: [PATCH] gnt-cluster modify: verify instance's disk template usage

Adds a verification step to 'gnt-cluster modify' to make sure that no
disk template is disabled that is currently in use by at least one instance.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Michele Tartara <mtarara@google.com>
---
 lib/cmdlib.py | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 016453982..29589dbe8 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -4424,7 +4424,7 @@ class LUClusterSetParams(LogicalUnit):
           hv_class.CheckParameterSyntax(hv_params)
           _CheckHVParams(self, node_list, hv_name, hv_params)
 
-    self._CheckDiskTypeConsistency()
+    self._CheckDiskTemplateConsistency()
 
     if self.op.os_hvp:
       # no need to check any newly-enabled hypervisors, since the
@@ -4448,26 +4448,22 @@ class LUClusterSetParams(LogicalUnit):
                                    " specified" % self.op.default_iallocator,
                                    errors.ECODE_INVAL)
 
-  def _CheckDiskTypeConsistency(self):
-    """Check whether the storage types that are going to be disabled
+  def _CheckDiskTemplateConsistency(self):
+    """Check whether the disk templates that are going to be disabled
        are still in use by some instances.
 
     """
-    if self.op.enabled_storage_types:
+    if self.op.enabled_disk_templates:
       cluster = self.cfg.GetClusterInfo()
       instances = self.cfg.GetAllInstancesInfo()
 
-      storage_types_to_remove = set(cluster.enabled_storage_types) \
-        - set(self.op.enabled_storage_types)
+      disk_templates_to_remove = set(cluster.enabled_disk_templates) \
+        - set(self.op.enabled_disk_templates)
       for instance in instances.itervalues():
-        storage_type = constants.DISK_TEMPLATES_STORAGE_TYPE[
-                         instance.disk_template]
-        if storage_type in storage_types_to_remove:
-          raise errors.OpPrereqError("Cannot disable storage type '%s',"
-                                     " because instance '%s' is using disk"
-                                     " template '%s'." %
-                                     (storage_type, instance.name,
-                                      instance.disk_template))
+        if instance.disk_template in disk_templates_to_remove:
+          raise errors.OpPrereqError("Cannot disable disk template '%s',"
+                                     " because instance '%s' is using it." %
+                                     (instance.disk_template, instance.name))
 
   def Exec(self, feedback_fn):
     """Change the parameters of the cluster.
-- 
GitLab