From e04ec58e2508764c0cb8c00cced4fbf283417981 Mon Sep 17 00:00:00 2001
From: Helga Velroyen <helgav@google.com>
Date: Tue, 26 Mar 2013 18:10:18 +0100
Subject: [PATCH] gnt-instance: no instance creation with disabled templates

This patch makes sure that no instances can be created which use
disk templates which are not enabled on the cluster.

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

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 80282df55..9855aedb1 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -10154,6 +10154,14 @@ class LUInstanceCreate(LogicalUnit):
     for nic in self.op.nics:
       utils.ForceDictType(nic, constants.INIC_PARAMS_TYPES)
 
+    cluster = self.cfg.GetClusterInfo()
+    if not self.op.disk_template in cluster.enabled_disk_templates:
+      raise errors.OpPrereqError("Cannot create an instance with disk template"
+                                 " '%s', because it is not enabled in the"
+                                 " cluster. Enabled disk templates are: %s." %
+                                 (self.op.disk_template,
+                                  ",".join(cluster.enabled_disk_templates)))
+
     # check disks. parameter names and consistent adopt/no-adopt strategy
     has_adopt = has_no_adopt = False
     for disk in self.op.disks:
-- 
GitLab