Revision 0f7f32d9 lib/bdev.py
b/lib/bdev.py | ||
---|---|---|
908 | 908 |
return True |
909 | 909 |
|
910 | 910 |
|
911 |
class BaseDRBD(BlockDev): |
|
912 |
"""Base DRBD class. |
|
911 | 913 |
|
912 |
class DRBDev(BlockDev): |
|
914 |
This class contains a few bits of common functionality between the |
|
915 |
0.7 and 8.x versions of DRBD. |
|
916 |
|
|
917 |
""" |
|
918 |
_VERSION_RE = re.compile(r"^version: (\d+)\.(\d+)\.(\d+)" |
|
919 |
r" \(api:(\d+)/proto:(\d+)\)") |
|
920 |
_DRBD_KVER = 0 |
|
921 |
|
|
922 |
@staticmethod |
|
923 |
def _GetProcData(): |
|
924 |
"""Return data from /proc/drbd. |
|
925 |
|
|
926 |
""" |
|
927 |
stat = open("/proc/drbd", "r") |
|
928 |
try: |
|
929 |
data = stat.read().splitlines() |
|
930 |
finally: |
|
931 |
stat.close() |
|
932 |
if not data: |
|
933 |
raise errors.BlockDeviceError("Can't read any data from /proc/drbd") |
|
934 |
return data |
|
935 |
|
|
936 |
@classmethod |
|
937 |
def _GetVersion(cls): |
|
938 |
"""Return the DRBD version. |
|
939 |
|
|
940 |
This will return a list [k_major, k_minor, k_point, api, proto]. |
|
941 |
|
|
942 |
""" |
|
943 |
proc_data = cls._GetProcData() |
|
944 |
first_line = proc_data[0].strip() |
|
945 |
version = cls._VERSION_RE.match(first_line) |
|
946 |
if not version: |
|
947 |
raise errors.BlockDeviceError("Can't parse DRBD version from '%s'" % |
|
948 |
first_line) |
|
949 |
return [int(val) for val in version.groups()] |
|
950 |
|
|
951 |
|
|
952 |
class DRBDev(BaseDRBD): |
|
913 | 953 |
"""DRBD block device. |
914 | 954 |
|
915 | 955 |
This implements the local host part of the DRBD device, i.e. it |
... | ... | |
930 | 970 |
def __init__(self, unique_id, children): |
931 | 971 |
super(DRBDev, self).__init__(unique_id, children) |
932 | 972 |
self.major = self._DRBD_MAJOR |
973 |
[kmaj, kmin, kfix, api, proto] = self._GetVersion() |
|
974 |
if kmaj != 0 and kmin != 7: |
|
975 |
raise errors.BlockDeviceError("Mismatch in DRBD kernel version and" |
|
976 |
" requested ganeti usage: kernel is" |
|
977 |
" %s.%s, ganeti wants 0.7" % (kmaj, kmin)) |
|
978 |
|
|
933 | 979 |
if len(children) != 2: |
934 | 980 |
raise ValueError("Invalid configuration data %s" % str(children)) |
935 | 981 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 4: |
... | ... | |
944 | 990 |
""" |
945 | 991 |
return "/dev/drbd%d" % minor |
946 | 992 |
|
947 |
@staticmethod |
|
948 |
def _GetProcData(): |
|
949 |
"""Return data from /proc/drbd. |
|
950 |
|
|
951 |
""" |
|
952 |
stat = open("/proc/drbd", "r") |
|
953 |
data = stat.read().splitlines() |
|
954 |
stat.close() |
|
955 |
return data |
|
956 |
|
|
957 |
|
|
958 | 993 |
@classmethod |
959 | 994 |
def _GetUsedDevs(cls): |
960 | 995 |
"""Compute the list of used DRBD devices. |
Also available in: Unified diff