Revision 5a47ad20 lib/bdev.py

b/lib/bdev.py
936 936
      raise errors.BlockDeviceError("Can't read any data from /proc/drbd")
937 937
    return data
938 938

  
939
  @staticmethod
940
  def _MassageProcData(data):
941
    """Transform the output of _GetProdData into a nicer form.
942

  
943
    Returns:
944
      a dictionary of minor: joined lines from /proc/drbd for that minor
945

  
946
    """
947
    lmatch = re.compile("^ *([0-9]+):.*$")
948
    results = {}
949
    old_minor = old_line = None
950
    for line in data:
951
      lresult = lmatch.match(line)
952
      if lresult is not None:
953
        if old_minor is not None:
954
          results[old_minor] = old_line
955
        old_minor = int(lresult.group(1))
956
        old_line = line
957
      else:
958
        if old_minor is not None:
959
          old_line += " " + line.strip()
960
    # add last line
961
    if old_minor is not None:
962
      results[old_minor] = old_line
963
    return results
964

  
939 965
  @classmethod
940 966
  def _GetVersion(cls):
941 967
    """Return the DRBD version.
......
979 1005

  
980 1006
    return used_devs
981 1007

  
1008
  def _SetFromMinor(self, minor):
1009
    """Set our parameters based on the given minor.
1010

  
1011
    This sets our minor variable and our dev_path.
1012

  
1013
    """
1014
    if minor is None:
1015
      self.minor = self.dev_path = None
1016
    else:
1017
      self.minor = minor
1018
      self.dev_path = self._DevPath(minor)
1019

  
982 1020

  
983 1021
class DRBDev(BaseDRBD):
984 1022
  """DRBD block device.
......
1253 1291
    return not result.failed
1254 1292

  
1255 1293

  
1256
  def _SetFromMinor(self, minor):
1257
    """Set our parameters based on the given minor.
1258

  
1259
    This sets our minor variable and our dev_path.
1260

  
1261
    """
1262
    if minor is None:
1263
      self.minor = self.dev_path = None
1264
    else:
1265
      self.minor = minor
1266
      self.dev_path = self._DevPath(minor)
1267

  
1268

  
1269 1294
  def Assemble(self):
1270 1295
    """Assemble the drbd.
1271 1296

  
......
1449 1474
    return sync_percent, est_time, is_degraded
1450 1475

  
1451 1476

  
1452
  @staticmethod
1453
  def _MassageProcData(data):
1454
    """Transform the output of _GetProdData into a nicer form.
1455

  
1456
    Returns:
1457
      a dictionary of minor: joined lines from /proc/drbd for that minor
1458

  
1459
    """
1460
    lmatch = re.compile("^ *([0-9]+):.*$")
1461
    results = {}
1462
    old_minor = old_line = None
1463
    for line in data:
1464
      lresult = lmatch.match(line)
1465
      if lresult is not None:
1466
        if old_minor is not None:
1467
          results[old_minor] = old_line
1468
        old_minor = int(lresult.group(1))
1469
        old_line = line
1470
      else:
1471
        if old_minor is not None:
1472
          old_line += " " + line.strip()
1473
    # add last line
1474
    if old_minor is not None:
1475
      results[old_minor] = old_line
1476
    return results
1477 1477

  
1478 1478

  
1479 1479
  def GetStatus(self):

Also available in: Unified diff