commit 27c7d9c3e1a9d44b2349caa27a6f1ce7c3c48461
Author: Thomas Thrainer <thomasth@google.com>
Date:   Mon Apr 29 13:51:24 2013 +0200

    Use DRBD84ShowInfo based on DRBD version
    
    Now the DRBD8 class actually checks which version of DRBD is running on
    the system and chooses the right class to parse the `drbdsetup show`
    output.
    
    Signed-off-by: Thomas Thrainer <thomasth@google.com>
    Signed-off-by: Michele Tartara <mtartara@google.com>
    Reviewed-by: Michele Tartara <mtartara@google.com>

diff --git a/lib/block/drbd.py b/lib/block/drbd.py
index 5889768..f51cb85 100644
--- a/lib/block/drbd.py
+++ b/lib/block/drbd.py
@@ -34,6 +34,7 @@ from ganeti import objects
 from ganeti.block import base
 from ganeti.block.drbd_info import DRBD8Info
 from ganeti.block.drbd_info import DRBD83ShowInfo
+from ganeti.block.drbd_info import DRBD84ShowInfo
 
 
 # Size of reads in _CanReadDevice
@@ -93,6 +94,11 @@ class DRBD8(base.BlockDev):
                       " usage: kernel is %s.%s, ganeti wants 8.x",
                       version["k_major"], version["k_minor"])
 
+    if version["k_minor"] <= 3:
+      self._show_info_cls = DRBD83ShowInfo
+    else:
+      self._show_info_cls = DRBD84ShowInfo
+
     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" %
@@ -236,6 +242,9 @@ class DRBD8(base.BlockDev):
       return None
     return result.stdout
 
+  def _GetShowInfo(self, minor):
+    return self._show_info_cls.GetDevInfo(self._GetShowData(minor))
+
   def _MatchesLocal(self, info):
     """Test if our local config matches with an existing device.
 
@@ -452,7 +461,7 @@ class DRBD8(base.BlockDev):
                       minor, result.fail_reason, result.output)
 
     def _CheckNetworkConfig():
-      info = DRBD83ShowInfo.GetDevInfo(self._GetShowData(minor))
+      info = self._GetShowInfo(minor)
       if not "local_addr" in info or not "remote_addr" in info:
         raise utils.RetryAgain()
 
@@ -474,7 +483,7 @@ class DRBD8(base.BlockDev):
                       self._aminor)
     if len(devices) != 2:
       base.ThrowError("drbd%d: need two devices for AddChildren", self.minor)
-    info = DRBD83ShowInfo.GetDevInfo(self._GetShowData(self.minor))
+    info = self._GetShowInfo(self.minor)
     if "local_dev" in info:
       base.ThrowError("drbd%d: already attached to a local disk", self.minor)
     backend, meta = devices
@@ -497,7 +506,7 @@ class DRBD8(base.BlockDev):
       base.ThrowError("drbd%d: can't attach to drbd8 during RemoveChildren",
                       self._aminor)
     # early return if we don't actually have backing storage
-    info = DRBD83ShowInfo.GetDevInfo(self._GetShowData(self.minor))
+    info = self._GetShowInfo(self.minor)
     if "local_dev" not in info:
       return
     if len(self._children) != 2:
@@ -849,7 +858,7 @@ class DRBD8(base.BlockDev):
     # pylint: disable=W0631
     net_data = (self._lhost, self._lport, self._rhost, self._rport)
     for minor in (self._aminor,):
-      info = DRBD83ShowInfo.GetDevInfo(self._GetShowData(minor))
+      info = self._GetShowInfo(minor)
       match_l = self._MatchesLocal(info)
       match_r = self._MatchesNet(info)
 
@@ -861,8 +870,7 @@ class DRBD8(base.BlockDev):
         # disk matches, but not attached to network, attach and recheck
         self._AssembleNet(minor, net_data, constants.DRBD_NET_PROTOCOL,
                           hmac=constants.DRBD_HMAC_ALG, secret=self._secret)
-        if self._MatchesNet(DRBD83ShowInfo.GetDevInfo(
-            self._GetShowData(minor))):
+        if self._MatchesNet(self._GetShowInfo(minor)):
           break
         else:
           base.ThrowError("drbd%d: network attach successful, but 'drbdsetup"
@@ -872,8 +880,7 @@ class DRBD8(base.BlockDev):
         # no local disk, but network attached and it matches
         self._AssembleLocal(minor, self._children[0].dev_path,
                             self._children[1].dev_path, self.size)
-        if self._MatchesNet(DRBD83ShowInfo.GetDevInfo(
-            self._GetShowData(minor))):
+        if self._MatchesNet(self._GetShowInfo(minor)):
           break
         else:
           base.ThrowError("drbd%d: disk attach successful, but 'drbdsetup"
@@ -900,8 +907,7 @@ class DRBD8(base.BlockDev):
         # None)
         self._AssembleNet(minor, net_data, constants.DRBD_NET_PROTOCOL,
                           hmac=constants.DRBD_HMAC_ALG, secret=self._secret)
-        if self._MatchesNet(DRBD83ShowInfo.GetDevInfo(
-            self._GetShowData(minor))):
+        if self._MatchesNet(self._GetShowInfo(minor)):
           break
         else:
           base.ThrowError("drbd%d: network attach successful, but 'drbdsetup"
