+class DRBD8Status(object):
+ """A DRBD status representation class.
+
+ Note that this doesn't support unconfigured devices (cs:Unconfigured).
+
+ """
+ LINE_RE = re.compile(r"\s*[0-9]+:\s*cs:(\S+)\s+st:([^/]+)/(\S+)"
+ "\s+ds:([^/]+)/(\S+)\s+.*$")
+ SYNC_RE = re.compile(r"^.*\ssync'ed:\s*([0-9.]+)%.*"
+ "\sfinish: ([0-9]+):([0-9]+):([0-9]+)\s.*$")
+
+ def __init__(self, procline):
+ m = self.LINE_RE.match(procline)
+ if not m:
+ raise errors.BlockDeviceError("Can't parse input data '%s'" % procline)
+ self.cstatus = m.group(1)
+ self.lrole = m.group(2)
+ self.rrole = m.group(3)
+ self.ldisk = m.group(4)
+ self.rdisk = m.group(5)
+
+ self.is_standalone = self.cstatus == "StandAlone"
+ self.is_wfconn = self.cstatus == "WFConnection"
+ self.is_connected = self.cstatus == "Connected"
+ self.is_primary = self.lrole == "Primary"
+ self.is_secondary = self.lrole == "Secondary"
+ self.peer_primary = self.rrole == "Primary"
+ self.peer_secondary = self.rrole == "Secondary"
+ self.both_primary = self.is_primary and self.peer_primary
+ self.both_secondary = self.is_secondary and self.peer_secondary
+
+ self.is_diskless = self.ldisk == "Diskless"
+ self.is_disk_uptodate = self.ldisk == "UpToDate"
+
+ m = self.SYNC_RE.match(procline)
+ if m:
+ self.sync_percent = float(m.group(1))
+ hours = int(m.group(2))
+ minutes = int(m.group(3))
+ seconds = int(m.group(4))
+ self.est_time = hours * 3600 + minutes * 60 + seconds
+ else:
+ self.sync_percent = None
+ self.est_time = None
+
+ self.is_sync_target = self.peer_sync_source = self.cstatus == "SyncTarget"
+ self.peer_sync_target = self.is_sync_source = self.cstatus == "SyncSource"
+ self.is_resync = self.is_sync_target or self.is_sync_source
+
+