Revision 3c003d9d

b/lib/bdev.py
569 569
  SYNC_RE = re.compile(r"^.*\ssync'ed:\s*([0-9.]+)%.*"
570 570
                       "\sfinish: ([0-9]+):([0-9]+):([0-9]+)\s.*$")
571 571

  
572
  CS_UNCONFIGURED = "Unconfigured"
573
  CS_STANDALONE = "StandAlone"
574
  CS_WFCONNECTION = "WFConnection"
575
  CS_WFREPORTPARAMS = "WFReportParams"
576
  CS_CONNECTED = "Connected"
577
  CS_STARTINGSYNCS = "StartingSyncS"
578
  CS_STARTINGSYNCT = "StartingSyncT"
579
  CS_WFBITMAPS = "WFBitMapS"
580
  CS_WFBITMAPT = "WFBitMapT"
581
  CS_WFSYNCUUID = "WFSyncUUID"
582
  CS_SYNCSOURCE = "SyncSource"
583
  CS_SYNCTARGET = "SyncTarget"
584
  CS_PAUSEDSYNCS = "PausedSyncS"
585
  CS_PAUSEDSYNCT = "PausedSyncT"
586
  CSET_SYNC = frozenset([
587
    CS_WFREPORTPARAMS,
588
    CS_STARTINGSYNCS,
589
    CS_STARTINGSYNCT,
590
    CS_WFBITMAPS,
591
    CS_WFBITMAPT,
592
    CS_WFSYNCUUID,
593
    CS_SYNCSOURCE,
594
    CS_SYNCTARGET,
595
    CS_PAUSEDSYNCS,
596
    CS_PAUSEDSYNCT,
597
    ])
598

  
599
  DS_DISKLESS = "Diskless"
600
  DS_ATTACHING = "Attaching" # transient state
601
  DS_FAILED = "Failed" # transient state, next: diskless
602
  DS_NEGOTIATING = "Negotiating" # transient state
603
  DS_INCONSISTENT = "Inconsistent" # while syncing or after creation
604
  DS_OUTDATED = "Outdated"
605
  DS_DUNKNOWN = "DUnknown" # shown for peer disk when not connected
606
  DS_CONSISTENT = "Consistent"
607
  DS_UPTODATE = "UpToDate" # normal state
608

  
609
  RO_PRIMARY = "Primary"
610
  RO_SECONDARY = "Secondary"
611
  RO_UNKNOWN = "Unknown"
612

  
572 613
  def __init__(self, procline):
573 614
    u = self.UNCONF_RE.match(procline)
574 615
    if u:
575
      self.cstatus = "Unconfigured"
616
      self.cstatus = self.CS_UNCONFIGURED
576 617
      self.lrole = self.rrole = self.ldisk = self.rdisk = None
577 618
    else:
578 619
      m = self.LINE_RE.match(procline)
......
586 627

  
587 628
    # end reading of data from the LINE_RE or UNCONF_RE
588 629

  
589
    self.is_standalone = self.cstatus == "StandAlone"
590
    self.is_wfconn = self.cstatus == "WFConnection"
591
    self.is_connected = self.cstatus == "Connected"
592
    self.is_primary = self.lrole == "Primary"
593
    self.is_secondary = self.lrole == "Secondary"
594
    self.peer_primary = self.rrole == "Primary"
595
    self.peer_secondary = self.rrole == "Secondary"
630
    self.is_standalone = self.cstatus == self.CS_STANDALONE
631
    self.is_wfconn = self.cstatus == self.CS_WFCONNECTION
632
    self.is_connected = self.cstatus == self.CS_CONNECTED
633
    self.is_primary = self.lrole == self.RO_PRIMARY
634
    self.is_secondary = self.lrole == self.RO_SECONDARY
635
    self.peer_primary = self.rrole == self.RO_PRIMARY
636
    self.peer_secondary = self.rrole == self.RO_SECONDARY
596 637
    self.both_primary = self.is_primary and self.peer_primary
597 638
    self.both_secondary = self.is_secondary and self.peer_secondary
598 639

  
599
    self.is_diskless = self.ldisk == "Diskless"
600
    self.is_disk_uptodate = self.ldisk == "UpToDate"
640
    self.is_diskless = self.ldisk == self.DS_DISKLESS
641
    self.is_disk_uptodate = self.ldisk == self.DS_UPTODATE
601 642

  
602
    self.is_in_resync = self.cstatus in ("SyncSource", "SyncTarget")
603
    self.is_in_use = self.cstatus != "Unconfigured"
643
    self.is_in_resync = self.cstatus in self.CSET_SYNC
644
    self.is_in_use = self.cstatus != self.CS_UNCONFIGURED
604 645

  
605 646
    m = self.SYNC_RE.match(procline)
606 647
    if m:
......
610 651
      seconds = int(m.group(4))
611 652
      self.est_time = hours * 3600 + minutes * 60 + seconds
612 653
    else:
613
      self.sync_percent = None
654
      # we have (in this if branch) no percent information, but if
655
      # we're resyncing we need to 'fake' a sync percent information,
656
      # as this is how cmdlib determines if it makes sense to wait for
657
      # resyncing or not
658
      if self.is_in_resync:
659
        self.sync_percent = 0
660
      else:
661
        self.sync_percent = None
614 662
      self.est_time = None
615 663

  
616
    self.is_sync_target = self.peer_sync_source = self.cstatus == "SyncTarget"
617
    self.peer_sync_target = self.is_sync_source = self.cstatus == "SyncSource"
618
    self.is_resync = self.is_sync_target or self.is_sync_source
619

  
620 664

  
621 665
class BaseDRBD(BlockDev):
622 666
  """Base DRBD class.

Also available in: Unified diff