Add new API call for creating a replication task in Life-Preserver

host = <Remote hostname/ip>
port = <SSH port>
password = <Your SSH password>
dataset = <Local Dataset to replicate>
remotedataset = <Target location for remote dataset>
frequency = <time> XX/sync/hour/30min/10min/manual
            XX= Time to perform replication (in 24 hour notation)
          sync= Do replication with snaps (Not recommended for frequent snaps)
          hour= Replicate hourly
         30min= Replicate every 30 minutes
         10min= Replicate every 10 minutes
        manual= Only replicate when requested by user

REST Request:
-------------------------------
PUT /sysadm/lifepreserver
{
   "action" : "addreplication",
   "password" : "mypass",
   "dataset" : "tank1",
   "remotedataset" : "tank/backups",
   "user" : "backupuser",
   "frequency" : "22",
   "port" : "22",
   "host" : "192.168.0.10"
}

REST Response:
-------------------------------
{
    "args": {
        "addreplication": {
            "frequency": "22",
            "host": "192.168.0.10",
            "ldataset": "tank1",
            "port": "22",
            "rdataset": "tank/backups",
            "user": "backupuser"
        }
    }
}

WebSocket Request:
-------------------------------
{
   "namespace" : "sysadm",
   "name" : "lifepreserver",
   "args" : {
      "action" : "addreplication",
      "user" : "backupuser",
      "dataset" : "tank1",
      "frequency" : "22",
      "port" : "22",
      "password" : "mypass",
      "host" : "192.168.0.10",
      "remotedataset" : "tank/backups"
   },
   "id" : "fooid"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "addreplication": {
      "frequency": "22",
      "host": "192.168.0.10",
      "ldataset": "tank1",
      "port": "22",
      "rdataset": "tank/backups",
      "user": "backupuser"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-01-12 16:53:46 -05:00
parent 5d834fabbd
commit 5bb6fb7d33
3 changed files with 74 additions and 1 deletions

View File

@@ -14,6 +14,75 @@ using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Add a new replication target
QJsonObject LifePreserver::addReplication(QJsonObject jsin) {
QJsonObject retObject;
QString host, user, port, password, ldataset, rdataset, frequency;
QStringList keys = jsin.keys();
if (! keys.contains("host")
|| ! keys.contains("user")
|| ! keys.contains("port")
|| ! keys.contains("password")
|| ! keys.contains("dataset")
|| ! keys.contains("remotedataset")
|| ! keys.contains("frequency") ) {
retObject.insert("error", "Missing required keys");
return retObject;
}
// Get the key values
host = jsin.value("host").toString();
user = jsin.value("user").toString();
port = jsin.value("port").toString();
password = jsin.value("password").toString();
ldataset = jsin.value("dataset").toString();
rdataset = jsin.value("remotedataset").toString();
frequency = jsin.value("frequency").toString();
// Make sure we have the dataset / snap key(s)
if ( host.isEmpty()
|| user.isEmpty()
|| port.isEmpty()
|| password.isEmpty()
|| ldataset.isEmpty()
|| rdataset.isEmpty()
|| frequency.isEmpty() ) {
retObject.insert("error", "Empty dataset or snap keys ");
return retObject;
}
// Run the command with the SSHPASS env variable set
QStringList output;
output = General::RunCommand("lpreserver", QStringList() << "replicate" << "add"
<< host
<< user
<< port
<< ldataset
<< rdataset
<< frequency, "", QStringList() << "SSHPASS=" + password ).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("host", host);
values.insert("user", user);
values.insert("port", port);
values.insert("ldataset", ldataset);
values.insert("rdataset", rdataset);
values.insert("frequency", frequency);
return values;
}
// Build list of scheduled cron snapshot jobs
QJsonObject LifePreserver::listCron() {
QJsonObject retObject;

View File

@@ -14,7 +14,7 @@ namespace sysadm{
class LifePreserver{
public:
// List schedule snapshots
static QJsonObject addReplication(QJsonObject jsin);
static QJsonObject listCron();
static QJsonObject listSnap(QJsonObject jsin);
static QJsonObject removeSnapshot(QJsonObject jsin);

View File

@@ -141,6 +141,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
bool ok = false;
if(keys.contains("action")){
QString act = JsonValueToString(in_args.toObject().value("action"));
if(act=="addreplication"){
ok = true;
out->insert("addreplication", sysadm::LifePreserver::addReplication(in_args.toObject()));
}
if(act=="cronscrub"){
ok = true;
out->insert("cronscrub", sysadm::LifePreserver::scheduleScrub(in_args.toObject()));