gnt-group add/modify: ipolicy vs disk templates
authorHelga Velroyen <helgav@google.com>
Wed, 7 Aug 2013 12:08:51 +0000 (14:08 +0200)
committerHelga Velroyen <helgav@google.com>
Thu, 8 Aug 2013 15:48:40 +0000 (17:48 +0200)
This patch adds a consistency check between the ipolicy's
list of allowed disk templates with the cluster-wide
enable disk templates when a new node group is added
or a group is modified.

It also fixes a bug in gnt-group where the list of allowed
disk templates was not propagated properly.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/client/gnt_group.py
lib/cmdlib/group.py

index 6cf5b6a..4c797fa 100644 (file)
@@ -53,6 +53,7 @@ def AddGroup(opts, args):
     minmax_ispecs=opts.ipolicy_bounds_specs,
     ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio,
     ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio,
+    ipolicy_disk_templates=opts.ipolicy_disk_templates,
     group_ipolicy=True)
 
   (group_name,) = args
@@ -159,7 +160,7 @@ def SetGroupParams(opts, args):
   allmods = [opts.ndparams, opts.alloc_policy, opts.diskparams, opts.hv_state,
              opts.disk_state, opts.ipolicy_bounds_specs,
              opts.ipolicy_vcpu_ratio, opts.ipolicy_spindle_ratio,
-             opts.diskparams]
+             opts.diskparams, opts.ipolicy_disk_templates]
   if allmods.count(None) == len(allmods):
     ToStderr("Please give at least one of the parameters.")
     return 1
index 8419925..9d328b5 100644 (file)
@@ -38,7 +38,8 @@ from ganeti.cmdlib.common import MergeAndVerifyHvState, \
   MergeAndVerifyDiskState, GetWantedNodes, GetUpdatedParams, \
   CheckNodeGroupInstances, GetUpdatedIPolicy, \
   ComputeNewInstanceViolations, GetDefaultIAllocator, ShareAll, \
-  CheckInstancesNodeGroups, LoadNodeEvacResult, MapInstanceLvsToNodes
+  CheckInstancesNodeGroups, LoadNodeEvacResult, MapInstanceLvsToNodes, \
+  CheckIpolicyVsDiskTemplates
 
 import ganeti.masterd.instance
 
@@ -59,6 +60,21 @@ class LUGroupAdd(LogicalUnit):
     self.needed_locks = {}
     self.add_locks[locking.LEVEL_NODEGROUP] = self.group_uuid
 
+  def _CheckIpolicy(self):
+    """Checks the group's ipolicy for consistency and validity.
+
+    """
+    if self.op.ipolicy:
+      cluster = self.cfg.GetClusterInfo()
+      full_ipolicy = cluster.SimpleFillIPolicy(self.op.ipolicy)
+      try:
+        objects.InstancePolicy.CheckParameterSyntax(full_ipolicy, False)
+      except errors.ConfigurationError, err:
+        raise errors.OpPrereqError("Invalid instance policy: %s" % err,
+                                   errors.ECODE_INVAL)
+      CheckIpolicyVsDiskTemplates(full_ipolicy,
+                                  cluster.enabled_disk_templates)
+
   def CheckPrereq(self):
     """Check prerequisites.
 
@@ -103,14 +119,7 @@ class LUGroupAdd(LogicalUnit):
     else:
       self.new_diskparams = {}
 
-    if self.op.ipolicy:
-      cluster = self.cfg.GetClusterInfo()
-      full_ipolicy = cluster.SimpleFillIPolicy(self.op.ipolicy)
-      try:
-        objects.InstancePolicy.CheckParameterSyntax(full_ipolicy, False)
-      except errors.ConfigurationError, err:
-        raise errors.OpPrereqError("Invalid instance policy: %s" % err,
-                                   errors.ECODE_INVAL)
+    self._CheckIpolicy()
 
   def BuildHooksEnv(self):
     """Build hooks env.
@@ -427,6 +436,35 @@ class LUGroupSetParams(LogicalUnit):
     utils.ForceDictType(new_params, constants.DISK_DT_TYPES)
     return new_params
 
+  def _CheckIpolicy(self, cluster, owned_instance_names):
+    """Sanity checks for the ipolicy.
+
+    @type cluster: C{objects.Cluster}
+    @param cluster: the cluster's configuration
+    @type owned_instance_names: list of string
+    @param owned_instance_names: list of instances
+
+    """
+    if self.op.ipolicy:
+      self.new_ipolicy = GetUpdatedIPolicy(self.group.ipolicy,
+                                           self.op.ipolicy,
+                                           group_policy=True)
+
+      new_ipolicy = cluster.SimpleFillIPolicy(self.new_ipolicy)
+      CheckIpolicyVsDiskTemplates(new_ipolicy,
+                                  cluster.enabled_disk_templates)
+      instances = self.cfg.GetMultiInstanceInfoByName(owned_instance_names)
+      gmi = ganeti.masterd.instance
+      violations = \
+          ComputeNewInstanceViolations(gmi.CalculateGroupIPolicy(cluster,
+                                                                 self.group),
+                                       new_ipolicy, instances, self.cfg)
+
+      if violations:
+        self.LogWarning("After the ipolicy change the following instances"
+                        " violate them: %s",
+                        utils.CommaJoin(violations))
+
   def CheckPrereq(self):
     """Check prerequisites.
 
@@ -475,23 +513,7 @@ class LUGroupSetParams(LogicalUnit):
         MergeAndVerifyDiskState(self.op.disk_state,
                                 self.group.disk_state_static)
 
-    if self.op.ipolicy:
-      self.new_ipolicy = GetUpdatedIPolicy(self.group.ipolicy,
-                                           self.op.ipolicy,
-                                           group_policy=True)
-
-      new_ipolicy = cluster.SimpleFillIPolicy(self.new_ipolicy)
-      instances = self.cfg.GetMultiInstanceInfoByName(owned_instance_names)
-      gmi = ganeti.masterd.instance
-      violations = \
-          ComputeNewInstanceViolations(gmi.CalculateGroupIPolicy(cluster,
-                                                                 self.group),
-                                       new_ipolicy, instances, self.cfg)
-
-      if violations:
-        self.LogWarning("After the ipolicy change the following instances"
-                        " violate them: %s",
-                        utils.CommaJoin(violations))
+    self._CheckIpolicy(cluster, owned_instance_names)
 
   def BuildHooksEnv(self):
     """Build hooks env.