mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add a new API call to (re)init the replication on the remote
side via life-preserver
dataset = The local dataset/pool you are replicating
host = The target for replication, either IP or hostname
REST Request:
-------------------------------
PUT /sysadm/lifepreserver
{
"dataset" : "tank1",
"host" : "192.168.0.9",
"action" : "initreplication"
}
REST Response:
-------------------------------
{
"args": {
"initreplication": {
"dataset": "tank1",
"host": "192.168.0.9"
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"args" : {
"host" : "192.168.0.9",
"dataset" : "tank1",
"action" : "initreplication"
},
"namespace" : "sysadm",
"name" : "lifepreserver"
}
WebSocket Response:
-------------------------------
{
"args": {
"initreplication": {
"dataset": "tank1",
"host": "192.168.0.9"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -83,6 +83,46 @@ QJsonObject LifePreserver::addReplication(QJsonObject jsin) {
|
||||
return values;
|
||||
}
|
||||
|
||||
// Re-init the LP replication target
|
||||
QJsonObject LifePreserver::initReplication(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
QString dset, rhost;
|
||||
|
||||
QStringList keys = jsin.keys();
|
||||
if(! keys.contains("dataset") || ! keys.contains("host")){
|
||||
retObject.insert("error", "Missing dataset or host key");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Check which pool we are looking at
|
||||
dset = jsin.value("dataset").toString();
|
||||
rhost = jsin.value("host").toString();
|
||||
|
||||
// Make sure we have the pool key
|
||||
if ( dset.isEmpty() || rhost.isEmpty()) {
|
||||
retObject.insert("error", "Missing dataset or host key");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// TODO - This command can take a LONG TIME. Find a way to queue / background it and return an event
|
||||
// via websockets later, or block here and return when finished if this is REST
|
||||
QStringList output = General::RunCommand("lpreserver replicate init " + dset + " " + rhost).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;
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject values;
|
||||
values.insert("dataset", dset);
|
||||
values.insert("host", rhost);
|
||||
return values;
|
||||
}
|
||||
|
||||
// Build list of scheduled cron snapshot jobs
|
||||
QJsonObject LifePreserver::listCron() {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace sysadm{
|
||||
class LifePreserver{
|
||||
public:
|
||||
static QJsonObject addReplication(QJsonObject jsin);
|
||||
static QJsonObject initReplication(QJsonObject jsin);
|
||||
static QJsonObject listCron();
|
||||
static QJsonObject listSnap(QJsonObject jsin);
|
||||
static QJsonObject removeSnapshot(QJsonObject jsin);
|
||||
|
||||
@@ -189,6 +189,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
|
||||
ok = true;
|
||||
out->insert("cronsnap", sysadm::LifePreserver::scheduleSnapshot(in_args.toObject()));
|
||||
}
|
||||
if(act=="initreplication"){
|
||||
ok = true;
|
||||
out->insert("initreplication", sysadm::LifePreserver::initReplication(in_args.toObject()));
|
||||
}
|
||||
if(act=="listcron"){
|
||||
ok = true;
|
||||
out->insert("listcron", sysadm::LifePreserver::listCron());
|
||||
|
||||
Reference in New Issue
Block a user