From 3b08cd1c2c0e4b9d75ad2bd495e876c72c789d45 Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Date: Wed, 23 Jun 2010 16:47:36 +0300
Subject: [PATCH] Introduce constants.DTS_MAY_ADOPT

DTS_MAY_ADOPT include disk templates that may use disk adoption and will be
used in all respective checks.

Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/cmdlib.py    | 7 ++++---
 lib/constants.py | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 51e3941e6..2af052b27 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -6391,9 +6391,10 @@ class LUCreateInstance(LogicalUnit):
       raise errors.OpPrereqError("Either all disks are adopted or none is",
                                  errors.ECODE_INVAL)
     if has_adopt:
-      if self.op.disk_template != constants.DT_PLAIN:
-        raise errors.OpPrereqError("Disk adoption is only supported for the"
-                                   " 'plain' disk template",
+      if self.op.disk_template not in constants.DTS_MAY_ADOPT:
+        raise errors.OpPrereqError("Disk adoption is not supported for the"
+                                   " '%s' disk template" %
+                                   self.op.disk_template,
                                    errors.ECODE_INVAL)
       if self.op.iallocator is not None:
         raise errors.OpPrereqError("Disk adoption not allowed with an"
diff --git a/lib/constants.py b/lib/constants.py
index 1f91ce54d..b7cda08d9 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -325,6 +325,9 @@ DTS_NOT_LVM = frozenset([DT_DISKLESS, DT_FILE])
 # the set of disk templates which can be grown
 DTS_GROWABLE = frozenset([DT_PLAIN, DT_DRBD8, DT_FILE])
 
+# the set of disk templates that allow adoption
+DTS_MAY_ADOPT = frozenset([DT_PLAIN])
+
 # logical disk types
 LD_LV = "lvm"
 LD_DRBD8 = "drbd8"
-- 
GitLab