Permalink
Browse files

Add the new backend class to life-preserver (for running lpreserver c…

…ommands), and start on the mainUI header file.
  • Loading branch information...
Ken Moore
Ken Moore committed Aug 8, 2013
1 parent 3d428ab commit 86b4b93f2e05982d78bd10a5f33e52a8e1d96e68
Showing with 175 additions and 9 deletions.
  1. +102 −0 life-preserver/LPBackend.cpp
  2. +24 −0 life-preserver/LPBackend.h
  3. +13 −5 life-preserver/configDialog.ui
  4. +14 −0 life-preserver/mainUI.h
  5. +22 −4 life-preserver/mainUI.ui
@@ -0,0 +1,102 @@
+#include "LPBackend.h"
+
+// ==============
+// Informational
+// ==============
+QStringList listDatasets(){
+ QString cmd = "lpreserver listcron";
+ //Need output, so run this in a QProcess
+ QProcess *proc = new QProcess;
+ proc->setProcessChannelMode(QProcess::MergedChannels);
+ proc->start(cmd);
+ proc->waitForFinished();
+ QStringList out = QString(proc->readAllStandardOutput()).split("\n");
+ delete proc;
+ //Now process the output
+ QStringList list;
+ for(int i=2; i<out.length(); i++){ //skip the first two lines (headers)
+ QString ds = out[i].section(" - ",0,0).simplified();
+ if(!ds.isEmpty()){ list << ds; }
+ }
+ return list;
+}
+
+QStringList listSnapshots(QString dataset){
+ QString cmd = "lpreserver listsnap "+dataset;
+ //Need output, so run this in a QProcess
+ QProcess *proc = new QProcess;
+ proc->setProcessChannelMode(QProcess::MergedChannels);
+ proc->start(cmd);
+ proc->waitForFinished();
+ QStringList out = QString(proc->readAllStandardOutput()).split("\n");
+ delete proc;
+ //Now process the output
+ QStringList list;
+ for(int i=0; i<out.length(); i++){
+ if(out[i].startsWIth(dataset+"@")){
+ QString snap = out[i].section("@",1,3).section(" ",0,0).simplified();;
+ if(!snap.isEmpty()){ list << snap; }
+ }
+ }
+ return list;
+}
+
+QStringList listReplicationTargets(){
+ QString cmd = "lpreserver replicate list";
+ //Need output, so run this in a QProcess
+ QProcess *proc = new QProcess;
+ proc->setProcessChannelMode(QProcess::MergedChannels);
+ proc->start(cmd);
+ proc->waitForFinished();
+ QStringList out = QString(proc->readAllStandardOutput()).split("\n");
+ delete proc;
+ //Now process the output
+ QStringList list;
+ for(int i=0; i<out.length(); i++){
+ if(out[i].contains("->")){
+ QString ds = out[i].section("->",0,0).simplified();
+ if(!ds.isEmpty()){ list << ds; }
+ }
+ }
+ return list;
+}
+
+// ==================
+// Snapshop Management
+// ==================
+void newSnapshot(QString dataset){
+ QString cmd = "lpreserver mksnap "+dataset;
+ system(cmd.toUtf8());
+}
+
+void removeSnapshot(QString dataset, QString snapshot){
+ QString cmd = "lpreserver rmsnap "+dataset +" "+snapshot;
+ system(cmd.toUtf8());
+}
+
+void revertSnapshot(QString dataset, QString snapshot){
+ QString cmd = "lpreserver revertsnap "+dataset +" "+snapshot;
+ system(cmd.toUtf8());
+}
+
+void browseSnapshot(QString dataset, QString snapshot){
+ //Not implemented yet
+}
+
+// ==================
+// Replication Management
+// ==================
+void setupReplication(QString dataset, QString remotehost, QString user, int port, QString remotedataset, int time){
+ QString stime = "sync"; //synchronize on snapshot creation
+ if(time < 0 || time > 24){
+
+ }else{ stime = QString::number(time); } //daily at a particular hour (24 hour notation)
+
+ QString cmd = "lpreserver replicate add "+remotehost+" "+user+" "+ QString::number(port)+" "+dataset+" "+remotedataset+" "+stime;
+ system(cmd.toUtf8());
+}
+
+void removeReplication(QString dataset){
+ QString cmd = "lpreserver replicate remove "+dataset;
+ system(cmd.toUtf8());
+}
View
@@ -0,0 +1,24 @@
+#ifndef _LP_BACKEND_H
+#define _LP_BACKEND_H
+
+#include <QProcess>
+
+//Class of static functions for using the "lpreserver" backend
+class LPBackend{
+
+public:
+ //Informational
+ QStringList listDatasets(); //list all lifepreserver datasets
+ QStringList listSnapshots(QString dataset); //list all snapshots for a particular dataset
+ QStringList listReplicationTargets(); //list all datasets with replication enabled
+ //Snapshop Management
+ void newSnapshot(QString dataset);
+ void removeSnapshot(QString dataset, QString snapshot);
+ void revertSnapshot(QString dataset, QString snapshot); //revert to given snapshot
+ void browseSnapshot(QString dataset, QString snapshot);
+ //Replication Management
+ void setupReplication(QString dataset, QString remotehost, QString user, int port, QString remotedataset, int time);
+ void removeReplication(QString dataset);
+
+};
+#endif
@@ -45,7 +45,7 @@
</property>
<widget class="QWidget" name="tab_local">
<attribute name="title">
- <string>Local Backups</string>
+ <string>Local Snapshots</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
@@ -87,7 +87,11 @@
</widget>
</item>
<item>
- <widget class="QTimeEdit" name="timeEdit"/>
+ <widget class="QTimeEdit" name="timeEdit">
+ <property name="displayFormat">
+ <string>h AP</string>
+ </property>
+ </widget>
</item>
</layout>
</item>
@@ -123,13 +127,13 @@
</widget>
<widget class="QWidget" name="tab_remote">
<attribute name="title">
- <string>Remote Backups</string>
+ <string>Replication</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupReplicate">
<property name="title">
- <string>Copy to Remote System</string>
+ <string>Replicate on a Remote System</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -262,7 +266,11 @@
</widget>
</item>
<item>
- <widget class="QTimeEdit" name="timeEdit_2"/>
+ <widget class="QTimeEdit" name="timeEdit_2">
+ <property name="displayFormat">
+ <string>h AP</string>
+ </property>
+ </widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
View
@@ -0,0 +1,14 @@
+#ifndef _LP_MAINUI_H
+#define _LP_MAINUI_H
+
+class mainUI : public QMainWindow{
+ Q_OBJECT
+
+public:
+
+private:
+
+private slots:
+
+};
+#endif
View
@@ -30,35 +30,46 @@
</column>
<column>
<property name="text">
- <string>Local Backups</string>
+ <string>Latest Snapshot</string>
</property>
</column>
<column>
<property name="text">
- <string>Remote Backups</string>
+ <string>Available</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Replication</string>
</property>
</column>
<item>
<property name="text">
<string>/home/user</string>
</property>
+ <property name="text">
+ <string/>
+ </property>
<property name="text">
<string>5</string>
</property>
<property name="text">
- <string> None Setup</string>
+ <string>None</string>
</property>
</item>
<item>
<property name="text">
<string>/home/user2</string>
</property>
<property name="text">
- <string>2</string>
+ <string/>
</property>
<property name="text">
<string>2</string>
</property>
+ <property name="text">
+ <string>Yes</string>
+ </property>
</item>
</widget>
</item>
@@ -101,6 +112,13 @@
</property>
</spacer>
</item>
+ <item>
+ <widget class="QToolButton" name="tool_browse">
+ <property name="text">
+ <string>Browse</string>
+ </property>
+ </widget>
+ </item>
<item>
<widget class="QToolButton" name="tool_revert">
<property name="text">

0 comments on commit 86b4b93

Please sign in to comment.