Commit 770fe0f9 authored by Iustin Pop's avatar Iustin Pop
Browse files

Move some methods from DRBDev to BaseDRBD

Since some of the methods and constants are valid for both 0.7 and 8.x
versions, we move them to the base class.

Reviewed-by: imsnah
parent aa4260ca
......@@ -917,7 +917,10 @@ class BaseDRBD(BlockDev):
"""
_VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)"
r" \(api:(\d+)/proto:(\d+)\)")
_DRBD_KVER = 0
_DRBD_MAJOR = 147
_ST_UNCONFIGURED = "Unconfigured"
_ST_WFCONNECTION = "WFConnection"
_ST_CONNECTED = "Connected"
@staticmethod
def _GetProcData():
......@@ -948,6 +951,34 @@ class BaseDRBD(BlockDev):
first_line)
return [int(val) for val in version.groups()]
@staticmethod
def _DevPath(minor):
"""Return the path to a drbd device for a given minor.
"""
return "/dev/drbd%d" % minor
@classmethod
def _GetUsedDevs(cls):
"""Compute the list of used DRBD devices.
"""
data = cls._GetProcData()
used_devs = {}
valid_line = re.compile("^ *([0-9]+): cs:([^ ]+).*$")
for line in data:
match = valid_line.match(line)
if not match:
continue
minor = int(match.group(1))
state = match.group(2)
if state == cls._ST_UNCONFIGURED:
continue
used_devs[minor] = state, line
return used_devs
class DRBDev(BaseDRBD):
"""DRBD block device.
......@@ -962,11 +993,6 @@ class DRBDev(BaseDRBD):
valid size and is zeroed on create.
"""
_DRBD_MAJOR = 147
_ST_UNCONFIGURED = "Unconfigured"
_ST_WFCONNECTION = "WFConnection"
_ST_CONNECTED = "Connected"
def __init__(self, unique_id, children):
super(DRBDev, self).__init__(unique_id, children)
self.major = self._DRBD_MAJOR
......@@ -983,35 +1009,6 @@ class DRBDev(BaseDRBD):
self._lhost, self._lport, self._rhost, self._rport = unique_id
self.Attach()
@staticmethod
def _DevPath(minor):
"""Return the path to a drbd device for a given minor.
"""
return "/dev/drbd%d" % minor
@classmethod
def _GetUsedDevs(cls):
"""Compute the list of used DRBD devices.
"""
data = cls._GetProcData()
used_devs = {}
valid_line = re.compile("^ *([0-9]+): cs:([^ ]+).*$")
for line in data:
match = valid_line.match(line)
if not match:
continue
minor = int(match.group(1))
state = match.group(2)
if state == cls._ST_UNCONFIGURED:
continue
used_devs[minor] = state, line
return used_devs
@classmethod
def _FindUnusedMinor(cls):
"""Find an unused DRBD device.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment