Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add the latest snapshot/replication detection into the new life-prese…

…rver UI
  • Loading branch information...
commit 9b07c663f449d023473c7bba0d21d8f58f5bcac2 1 parent a4521eb
Ken Moore beanpole135 authored
23 life-preserver/LPBackend.cpp
@@ -113,6 +113,29 @@ QStringList LPBackend::listReplicationTargets(){
113 113 return list;
114 114 }
115 115
  116 +QStringList LPBackend::listCurrentStatus(){
  117 + QString cmd = "lpreserver status";
  118 + //Need output, so run this in a QProcess
  119 + QProcess *proc = new QProcess;
  120 + proc->setProcessChannelMode(QProcess::MergedChannels);
  121 + proc->start(cmd);
  122 + proc->waitForFinished();
  123 + QStringList out = QString(proc->readAllStandardOutput()).split("\n");
  124 + delete proc;
  125 + QStringList list;
  126 + //Now process the output
  127 + for(int i=2; i<out.length(); i++){ //first 2 lines are headers
  128 + //Format: <dataset>:::<lastsnapshot | NONE>:::<lastreplication | NONE>
  129 + QString ds = out[i].section(" - ",0,0).simplified();
  130 + QString snap = out[i].section(" - ",1,1).simplified();
  131 + QString rep = out[i].section(" - ",2,2).simplified();
  132 + if(snap == "NONE"){ snap = "-"; }
  133 + if(rep == "NONE"){ rep = "-"; }
  134 + list << ds +":::"+ snap+":::"+rep;
  135 + }
  136 + return list;
  137 +}
  138 +
116 139 // ==================
117 140 // Dataset Management
118 141 // ==================
1  life-preserver/LPBackend.h
@@ -18,6 +18,7 @@ class LPBackend{
18 18 static QStringList listSnapshots(QString dsmountpoint); //list all snapshots for a particular dataset mountpoint
19 19 static QStringList listLPSnapshots(QString dataset); //list all snapshots created by life preserver
20 20 static QStringList listReplicationTargets(); //list all datasets with replication enabled
  21 + static QStringList listCurrentStatus(); //list the current snapshot/replication status
21 22 //Dataset Management
22 23 static bool setupDataset(QString dataset, int time, int numToKeep); //add or configure dataset
23 24 static bool removeDataset(QString dataset);
26 life-preserver/mainUI.cpp
@@ -57,18 +57,35 @@ LPDataset mainUI::newDataset(QString ds){
57 57 }
58 58 }
59 59 //Get the time for the latest life-preserver snapshot (and total number)
  60 + //Find the index for the current list
  61 + int ci = 0;
  62 + while(ci < CLIST.length()){
  63 + if(CLIST[ci].startsWith(ds+":::")){ break; }
  64 + else{ ci++; }
  65 + }
  66 + if(CLIST.isEmpty()){ ci = -1; } //catch for empty list
  67 +
60 68 if(subsets.isEmpty()){
61 69 DSC.numberOfSnapshots = "0";
62   - DSC.latestSnapshot="";
  70 + DSC.latestSnapshot= "";
63 71 }else{
64 72 QStringList fSnap = DSC.subsetHash[subsets[0]].filter("auto-"); //filtered snapshot list (just life preserver snapshots)
65 73 DSC.numberOfSnapshots = QString::number(fSnap.length());
66 74 if(fSnap.isEmpty()){ DSC.latestSnapshot=""; }
67   - else{ DSC.latestSnapshot=fSnap[0]; }
  75 + else if(ci > -1){
  76 + QString sna = CLIST[ci].section(":::",1,1);
  77 + if(sna != "-"){ DSC.latestSnapshot= sna; }
  78 + else{ DSC.latestSnapshot = ""; }
  79 + }else{ DSC.latestSnapshot=fSnap[0]; }
68 80 }
69 81 //List the replication status
70   - if(RLIST.contains(ds)){ DSC.latestReplication= tr("Enabled"); }
71   - else{ DSC.latestReplication= tr("Disabled"); }
  82 + if(RLIST.contains(ds) && (ci > -1)){
  83 + QString rep = CLIST[ci].section(":::",2,2);
  84 + if(rep != "-"){ DSC.latestReplication = rep; }
  85 + else{ DSC.latestReplication= tr("Enabled"); }
  86 + }else{
  87 + DSC.latestReplication= tr("Disabled");
  88 + }
72 89 //Return the dataset
73 90 return DSC;
74 91 }
@@ -79,6 +96,7 @@ LPDataset mainUI::newDataset(QString ds){
79 96 void mainUI::updateHash(QString ds){
80 97 RLIST = LPBackend::listReplicationTargets(); //update list of replication datasets
81 98 SLIST = LPBackend::listPossibleDatasets();
  99 + CLIST = LPBackend::listCurrentStatus();
82 100 if(HLIST.contains(ds) && !ds.isEmpty()){
83 101 //only update the entry for the given dataset
84 102 HLIST.insert(ds, newDataset(ds)); //will overwrite the current entry in the hash
1  life-preserver/mainUI.h
@@ -37,6 +37,7 @@ class mainUI : public QMainWindow{
37 37 QHash<QString,LPDataset> HLIST;
38 38 QStringList RLIST; //datasets that have replication enabled
39 39 QStringList SLIST; //available datasets on the system
  40 + QStringList CLIST; //current status for all datasets
40 41 QMenu *revMenu, *brMenu, *addMenu; //revert/browse menu's
41 42
42 43 void updateHash(QString ds="");

0 comments on commit 9b07c66

Please sign in to comment.
Something went wrong with that request. Please try again.