mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add new API call to run replication tasks manually
REST Request:
-------------------------------
PUT /sysadm/lifepreserver
{
"host" : "10.0.10.100",
"dataset" : "mypool",
"action" : "runreplication"
}
REST Response:
-------------------------------
{
"args": {
"runreplication": {
"dataset": "mypool",
"host": "10.0.10.100"
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"name" : "lifepreserver",
"args" : {
"host" : "10.0.10.100",
"dataset" : "mypool",
"action" : "runreplication"
},
"namespace" : "sysadm"
}
WebSocket Response:
-------------------------------
{
"args": {
"runreplication": {
"dataset": "mypool",
"host": "10.0.10.100"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -369,6 +369,47 @@ QJsonObject LifePreserver::removeSnapshot(QJsonObject jsin) {
|
||||
return values;
|
||||
}
|
||||
|
||||
// Run a replication task
|
||||
QJsonObject LifePreserver::runReplication(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
QString dataset, host;
|
||||
|
||||
QStringList keys = jsin.keys();
|
||||
if(! keys.contains("dataset") || ! keys.contains("host")){
|
||||
retObject.insert("error", "Requires dataset and host keys");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Get the dataset / host
|
||||
dataset = jsin.value("dataset").toString();
|
||||
host = jsin.value("host").toString();
|
||||
|
||||
// Make sure we have the dataset / host key(s)
|
||||
if ( dataset.isEmpty() || host.isEmpty() ) {
|
||||
retObject.insert("error", "Empty dataset or host keys ");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
QStringList output;
|
||||
output = General::RunCommand("lpreserver replicate run " + dataset + " " + host).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("dataset", dataset);
|
||||
values.insert("host", host);
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
// Revert to a snapshot
|
||||
QJsonObject LifePreserver::revertSnapshot(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
static QJsonObject removeReplication(QJsonObject jsin);
|
||||
static QJsonObject removeSnapshot(QJsonObject jsin);
|
||||
static QJsonObject revertSnapshot(QJsonObject jsin);
|
||||
static QJsonObject runReplication(QJsonObject jsin);
|
||||
static QJsonObject saveSettings(QJsonObject jsin);
|
||||
static QJsonObject scheduleSnapshot(QJsonObject jsin);
|
||||
static QJsonObject scheduleScrub(QJsonObject jsin);
|
||||
|
||||
@@ -217,6 +217,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
|
||||
ok = true;
|
||||
out->insert("revertsnap", sysadm::LifePreserver::revertSnapshot(in_args.toObject()));
|
||||
}
|
||||
if(act=="runreplication"){
|
||||
ok = true;
|
||||
out->insert("runreplication", sysadm::LifePreserver::runReplication(in_args.toObject()));
|
||||
}
|
||||
if(act=="savesettings"){
|
||||
ok = true;
|
||||
out->insert("savesettings", sysadm::LifePreserver::saveSettings(in_args.toObject()));
|
||||
|
||||
Reference in New Issue
Block a user