Make sure a DRBD disk has the same primary node as the instance where it
will be attached to.

Signed-off-by: Lisa Velden <[email protected]>
---
 lib/cmdlib/instance_set_params.py |  7 +++++++
 lib/objects.py                    | 11 +++++++++++
 2 files changed, 18 insertions(+)

diff --git a/lib/cmdlib/instance_set_params.py 
b/lib/cmdlib/instance_set_params.py
index b402483..a35e95c 100644
--- a/lib/cmdlib/instance_set_params.py
+++ b/lib/cmdlib/instance_set_params.py
@@ -408,6 +408,13 @@ class LUInstanceSetParams(LogicalUnit):
                                  " are %s" %
                                  (disk.nodes, instance_nodes),
                                  errors.ECODE_INVAL)
+    # Make sure a DRBD disk has the same primary node as the instance where it
+    # will be attached to.
+    disk_primary = disk.GetPrimaryNode(self.instance.primary_node)
+    if self.instance.primary_node != disk_primary:
+      raise errors.OpExecError("The disks' primary node is %s whereas the "
+                               "instance's primary node is %s."
+                               % (disk_primary, self.instance.primary_node))
 
   def ExpandNames(self):
     self._ExpandAndLockInstance()
diff --git a/lib/objects.py b/lib/objects.py
index 633353d..96e7092 100644
--- a/lib/objects.py
+++ b/lib/objects.py
@@ -675,6 +675,17 @@ class Disk(ConfigObject):
       raise errors.ProgrammerError("Unhandled device type %s" % self.dev_type)
     return result
 
+  def GetPrimaryNode(self, node_uuid):
+    """This function returns the primary node of the device.
+
+    If the device is not a DRBD device, we still return the node the device
+    lives on.
+
+    """
+    if self.dev_type in constants.DTS_DRBD:
+      return self.logical_id[0]
+    return node_uuid
+
   def ComputeNodeTree(self, parent_node_uuid):
     """Compute the node/disk tree for this disk and its children.
 
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to