Skip to content

Commit

Permalink
Add the new backend class to life-preserver (for running lpreserver c…
Browse files Browse the repository at this point in the history
…ommands), and start on the mainUI header file.
  • Loading branch information
Ken Moore committed Aug 8, 2013
1 parent 3d428ab commit 86b4b93
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 9 deletions.
102 changes: 102 additions & 0 deletions life-preserver/LPBackend.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
24 changes: 24 additions & 0 deletions life-preserver/LPBackend.h
Original file line number Diff line number Diff line change
@@ -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
18 changes: 13 additions & 5 deletions life-preserver/configDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
14 changes: 14 additions & 0 deletions life-preserver/mainUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _LP_MAINUI_H
#define _LP_MAINUI_H

class mainUI : public QMainWindow{
Q_OBJECT

public:

private:

private slots:

};
#endif
26 changes: 22 additions & 4 deletions life-preserver/mainUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down

0 comments on commit 86b4b93

Please sign in to comment.