Add new API call to schedule a cron scrub

Frequency Options: none, daily@XX, weekly@YY@XX, monthly@ZZ@XX
XX = Hour to execute, YY = Day of week to execute, ZZ = Day of month

REST Request:
-------------------------------
PUT /sysadm/lifepreserver
{
   "action" : "cronscrub",
   "pool" : "tank",
   "frequency" : "daily@22"
}

REST Response:
-------------------------------
{
    "args": {
        "cronscrub": {
            "frequency": "daily@22",
            "pool": "tank"
        }
    }
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "cronscrub",
      "pool" : "tank",
      "frequency" : "daily@22"
   },
   "namespace" : "sysadm",
   "name" : "lifepreserver",
   "id" : "fooid"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "cronscrub": {
      "frequency": "daily@22",
      "pool": "tank"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-01-12 12:12:19 -05:00
parent a892e539f2
commit cbf3ce8b8b
4 changed files with 61 additions and 2 deletions

View File

@@ -178,6 +178,10 @@ Create a Schedule
The "cronsnap" action is used to create snapshot schedules for Life Preserver. When creating a schedule, specify the ZFS pool to snapshot, how many snapshots to keep, and at what time the
snapshots should occur.
Frequency: none, daily@XX, hourly, 30min, 10min, 5min (Specifying 'none' disables)
Keep: <number>
**REST Request**
.. code-block:: json
@@ -300,4 +304,4 @@ Run :command:`lpreserver help set` for more information about each available set
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
}

View File

@@ -106,6 +106,52 @@ QJsonObject LifePreserver::listSnap(QJsonObject jsin) {
return retObject;
}
// Schedule a new scrub routine
QJsonObject LifePreserver::scheduleScrub(QJsonObject jsin) {
QJsonObject retObject;
QString pool, frequency;
QStringList keys = jsin.keys();
bool ok = false;
if(! keys.contains("pool") || ! keys.contains("frequency")){
retObject.insert("error", "Requires pool and frequency keys");
return retObject;
}
// Check which pool we are looking at
pool = jsin.value("pool").toString();
frequency = jsin.value("frequency").toString();
// Make sure we have the pool / frequency / keep key(s)
if ( pool.isEmpty() || frequency.isEmpty() ) {
retObject.insert("error", "Empty pool or frequency keys ");
return retObject;
}
QStringList output;
if ( frequency == "none" )
output = General::RunCommand("lpreserver cronscrub " + pool + " stop " + frequency).split("\n");
else
output = General::RunCommand("lpreserver cronscrub " + pool + " start " + frequency).split("\n");
// Check for any errors
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("ERROR:") != -1 ) {
retObject.insert("error", output.at(i));
return retObject;
}
}
// Got to the end, return the good json
QJsonObject values;
values.insert("pool", pool);
values.insert("frequency", frequency);
return values;
}
// Schedule a new snapshot routine
QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) {
QJsonObject retObject;
@@ -129,7 +175,11 @@ QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) {
return retObject;
}
QStringList output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n");
QStringList output;
if ( frequency == "none" )
output = General::RunCommand("lpreserver cronsnap " + pool + " stop " ).split("\n");
else
output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n");
// Check for any errors
for ( int i = 0; i < output.size(); i++)

View File

@@ -18,6 +18,7 @@ public:
static QJsonObject listCron();
static QJsonObject listSnap(QJsonObject jsin);
static QJsonObject scheduleSnapshot(QJsonObject jsin);
static QJsonObject scheduleScrub(QJsonObject jsin);
static QJsonObject settings();
};

View File

@@ -149,6 +149,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
ok = true;
out->insert("listsnap", sysadm::LifePreserver::listSnap(in_args.toObject()));
}
if(act=="cronscrub"){
ok = true;
out->insert("cronscrub", sysadm::LifePreserver::scheduleScrub(in_args.toObject()));
}
if(act=="cronsnap"){
ok = true;
out->insert("cronsnap", sysadm::LifePreserver::scheduleSnapshot(in_args.toObject()));