Merge branch 'master' of github.com:pcbsd/sysadm

This commit is contained in:
Ken Moore
2016-01-08 14:02:20 -05:00
4 changed files with 71 additions and 2 deletions

View File

@@ -6,12 +6,14 @@
//===========================================
#include "sysadm-general.h"
#include "sysadm-lifepreserver.h"
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
#include "sysadm-global.h"
#include "QJsonValue"
using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Build list of scheduled cron snapshot jobs
QJsonObject LifePreserver::listCron() {
QJsonObject retObject;
@@ -49,3 +51,57 @@ QJsonObject LifePreserver::listCron() {
return retObject;
}
// Return a list of snapshots on a particular pool / dataset
QJsonObject LifePreserver::listSnap(QJsonObject jsin) {
QJsonObject retObject;
QString pool;
QStringList keys = jsin.keys();
bool ok = false;
if(! keys.contains("pool")){
retObject.insert("error", "Missing pool key");
return retObject;
}
// Check which pool we are looking at
pool = jsin.value("pool").toString();
// Make sure we have the pool key
if ( pool.isEmpty() ) {
retObject.insert("error", "Missing pool key");
return retObject;
}
QStringList output = General::RunCommand("lpreserver listsnap " + pool ).split("\n");
QList<QStringList> snaps;
QStringList snapitems;
QRegExp sep("\\s+");
// Parse the output
bool inSection = false;
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("-----------------") != -1 ) {
inSection = true;
continue;
}
if (!inSection)
continue;
if ( output.at(i).isEmpty() || output.at(i).indexOf("-----------------") != -1 )
break;
// Breakdown this snapshot
snapitems.clear();
snapitems << output.at(i).section(sep, 0, 0).simplified();
snapitems << output.at(i).section(sep, 1, -1).simplified();
QJsonObject values;
values.insert("comment", snapitems.at(1));
retObject.insert(snapitems.at(0), values);
}
return retObject;
}

View File

@@ -16,6 +16,7 @@ class LifePreserver{
public:
// List schedule snapshots
static QJsonObject listCron();
static QJsonObject listSnap(QJsonObject jsin);
};
} //end of pcbsd namespace

View File

@@ -145,6 +145,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
ok = true;
out->insert("listcron", sysadm::LifePreserver::listCron());
}
if(act=="listsnap"){
ok = true;
out->insert("listsnap", sysadm::LifePreserver::listSnap(in_args.toObject()));
}
} //end of "action" key usage

View File

@@ -25,6 +25,14 @@ if [ ! -d "${HOME}/.npm/ws" ] ; then
fi
fi
if [ ! -d "${HOME}/.npm/wss" ] ; then
npm install wss
if [ $? -ne 0 ] ; then
echo "Failed installing wss node module"
exit 1
fi
fi
echo "Enter your username:"
echo -e ">\c"
read fuser