drive_del after device_del in disk hot-remove
[ganeti-local] / lib / storage / drbd.py
index a9598c5..5642f29 100644 (file)
@@ -163,10 +163,10 @@ class DRBD8Dev(base.BlockDev):
   doesn't do anything to the supposed peer. If you need a fully
   connected DRBD pair, you need to use this class on both hosts.
 
-  The unique_id for the drbd device is a (local_ip, local_port,
-  remote_ip, remote_port, local_minor, secret) tuple, and it must have
-  two children: the data device and the meta_device. The meta device
-  is checked for valid size and is zeroed on create.
+  The unique_id for the drbd device is a (pnode_uuid, snode_uuid,
+  port, pnode_minor, lnode_minor, secret) tuple, and it must have
+  two children: the data device and the meta_device. The meta
+  device is checked for valid size and is zeroed on create.
 
   """
   _DRBD_MAJOR = 147
@@ -174,21 +174,32 @@ class DRBD8Dev(base.BlockDev):
   # timeout constants
   _NET_RECONFIG_TIMEOUT = 60
 
-  def __init__(self, unique_id, children, size, params):
+  def __init__(self, unique_id, children, size, params, dyn_params):
     if children and children.count(None) > 0:
       children = []
     if len(children) not in (0, 2):
       raise ValueError("Invalid configuration data %s" % str(children))
     if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 6:
       raise ValueError("Invalid configuration data %s" % str(unique_id))
-    (self._lhost, self._lport,
-     self._rhost, self._rport,
-     self._aminor, self._secret) = unique_id
+    if constants.DDP_LOCAL_IP not in dyn_params or \
+       constants.DDP_REMOTE_IP not in dyn_params or \
+       constants.DDP_LOCAL_MINOR not in dyn_params or \
+       constants.DDP_REMOTE_MINOR not in dyn_params:
+      raise ValueError("Invalid dynamic parameters %s" % str(dyn_params))
+
+    self._lhost = dyn_params[constants.DDP_LOCAL_IP]
+    self._lport = unique_id[2]
+    self._rhost = dyn_params[constants.DDP_REMOTE_IP]
+    self._rport = unique_id[2]
+    self._aminor = dyn_params[constants.DDP_LOCAL_MINOR]
+    self._secret = unique_id[5]
+
     if children:
       if not _CanReadDevice(children[1].dev_path):
         logging.info("drbd%s: Ignoring unreadable meta device", self._aminor)
         children = []
-    super(DRBD8Dev, self).__init__(unique_id, children, size, params)
+    super(DRBD8Dev, self).__init__(unique_id, children, size, params,
+                                   dyn_params)
     self.major = self._DRBD_MAJOR
 
     info = DRBD8.GetProcInfo()
@@ -207,8 +218,8 @@ class DRBD8Dev(base.BlockDev):
 
     if (self._lhost is not None and self._lhost == self._rhost and
             self._lport == self._rport):
-      raise ValueError("Invalid configuration data, same local/remote %s" %
-                       (unique_id,))
+      raise ValueError("Invalid configuration data, same local/remote %s, %s" %
+                       (unique_id, dyn_params))
     self.Attach()
 
   @staticmethod
@@ -1005,7 +1016,8 @@ class DRBD8Dev(base.BlockDev):
       base.ThrowError("Can't initialize meta device: %s", result.output)
 
   @classmethod
-  def Create(cls, unique_id, children, size, spindles, params, excl_stor):
+  def Create(cls, unique_id, children, size, spindles, params, excl_stor,
+             dyn_params):
     """Create a new DRBD8 device.
 
     Since DRBD devices are not created per se, just assembled, this
@@ -1017,8 +1029,11 @@ class DRBD8Dev(base.BlockDev):
     if excl_stor:
       raise errors.ProgrammerError("DRBD device requested with"
                                    " exclusive_storage")
+    if constants.DDP_LOCAL_MINOR not in dyn_params:
+      raise errors.ProgrammerError("Invalid dynamic params for drbd device %s"
+                                   % dyn_params)
     # check that the minor is unused
-    aminor = unique_id[4]
+    aminor = dyn_params[constants.DDP_LOCAL_MINOR]
 
     info = DRBD8.GetProcInfo()
     if info.HasMinorStatus(aminor):
@@ -1036,7 +1051,7 @@ class DRBD8Dev(base.BlockDev):
                       aminor, meta)
     cls._CheckMetaSize(meta.dev_path)
     cls._InitMeta(aminor, meta.dev_path)
-    return cls(unique_id, children, size, params)
+    return cls(unique_id, children, size, params, dyn_params)
 
 
 def _CanReadDevice(path):