Revision 3840729d lib/bdev.py

b/lib/bdev.py
1737 1737
    return bnf
1738 1738

  
1739 1739
  @classmethod
1740
  def _GetDevInfo(cls, minor):
1741
    """Get details about a given DRBD minor.
1742

  
1743
    This return, if available, the local backing device (as a path)
1744
    and the local and remote (ip, port) information.
1740
  def _GetShowData(cls, minor):
1741
    """Return the `drbdsetup show` data for a minor.
1745 1742

  
1746 1743
    """
1747
    data = {}
1748 1744
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "show"])
1749 1745
    if result.failed:
1750 1746
      logger.Error("Can't display the drbd config: %s" % result.fail_reason)
1751
      return data
1752
    out = result.stdout
1747
      return None
1748
    return result.stdout
1749

  
1750
  @classmethod
1751
  def _GetDevInfo(cls, out):
1752
    """Parse details about a given DRBD minor.
1753

  
1754
    This return, if available, the local backing device (as a path)
1755
    and the local and remote (ip, port) information from a string
1756
    containing the output of the `drbdsetup show` command as returned
1757
    by _GetShowData.
1758

  
1759
    """
1760
    data = {}
1753 1761
    if not out:
1754 1762
      return data
1755 1763

  
......
1881 1889
    timeout = time.time() + 10
1882 1890
    ok = False
1883 1891
    while time.time() < timeout:
1884
      info = cls._GetDevInfo(minor)
1892
      info = cls._GetDevInfo(cls._GetShowData(minor))
1885 1893
      if not "local_addr" in info or not "remote_addr" in info:
1886 1894
        time.sleep(1)
1887 1895
        continue
......
1904 1912
      raise errors.BlockDeviceError("Can't attach to dbrd8 during AddChildren")
1905 1913
    if len(devices) != 2:
1906 1914
      raise errors.BlockDeviceError("Need two devices for AddChildren")
1907
    info = self._GetDevInfo(self.minor)
1915
    info = self._GetDevInfo(self._GetShowData(self.minor))
1908 1916
    if "local_dev" in info:
1909 1917
      raise errors.BlockDeviceError("DRBD8 already attached to a local disk")
1910 1918
    backend, meta = devices
......
1930 1938
      raise errors.BlockDeviceError("Can't attach to drbd8 during"
1931 1939
                                    " RemoveChildren")
1932 1940
    # early return if we don't actually have backing storage
1933
    info = self._GetDevInfo(self.minor)
1941
    info = self._GetDevInfo(self._GetShowData(self.minor))
1934 1942
    if "local_dev" not in info:
1935 1943
      return
1936 1944
    if len(self._children) != 2:
......
2083 2091

  
2084 2092
    """
2085 2093
    for minor in self._GetUsedDevs():
2086
      info = self._GetDevInfo(minor)
2094
      info = self._GetDevInfo(self._GetShowData(minor))
2087 2095
      match_l = self._MatchesLocal(info)
2088 2096
      match_r = self._MatchesNet(info)
2089 2097
      if match_l and match_r:
......
2093 2101
                                  (self._lhost, self._lport,
2094 2102
                                   self._rhost, self._rport),
2095 2103
                                  "C")
2096
        if res_r and self._MatchesNet(self._GetDevInfo(minor)):
2097
          break
2104
        if res_r:
2105
          if self._MatchesNet(self._GetDevInfo(self._GetShowData(minor))):
2106
            break
2098 2107
      # the weakest case: we find something that is only net attached
2099 2108
      # even though we were passed some children at init time
2100 2109
      if match_r and "local_dev" not in info:
......
2114 2123
        # None)
2115 2124
        if (self._AssembleNet(minor, (self._lhost, self._lport,
2116 2125
                                      self._rhost, self._rport), "C") and
2117
            self._MatchesNet(self._GetDevInfo(minor))):
2126
            self._MatchesNet(self._GetDevInfo(self._GetShowData(minor)))):
2118 2127
          break
2119 2128

  
2120 2129
    else:

Also available in: Unified diff