mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add a new iocage API call to deactivate pools.
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"action" : "deactivatepool",
"pool" : "tank"
}
REST Response:
-------------------------------
{
"args": {
"deactivatepool": {
"success": "pool tank deactivated."
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"name" : "iocage",
"args" : {
"pool" : "tank",
"action" : "deactivatepool"
},
"namespace" : "sysadm"
}
WebSocket Response:
-------------------------------
{
"args": {
"deactivatepool": {
"success": "pool tank deactivated."
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
Also added some error control to the activate API call.
This commit is contained in:
@@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="deactivatepool"){
|
||||
ok = true;
|
||||
out->insert("deactivatepool", sysadm::Iocage::deactivatePool(in_args.toObject()));
|
||||
}
|
||||
if(act=="activatepool"){
|
||||
ok = true;
|
||||
out->insert("activatepool", sysadm::Iocage::activatePool(in_args.toObject()));
|
||||
|
||||
@@ -12,6 +12,34 @@ using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
// Deactivate a zpool for iocage on the box
|
||||
QJsonObject Iocage::deactivatePool(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList keys = jsin.keys();
|
||||
if (! keys.contains("pool") ) {
|
||||
retObject.insert("error", "Missing required keys");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Get the key values
|
||||
QString pool = jsin.value("pool").toString();
|
||||
QStringList output = General::RunCommand("iocage deactivate " + pool).split("\n");
|
||||
QJsonObject vals;
|
||||
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
if ( ! output.at(i).isEmpty())
|
||||
break;
|
||||
|
||||
// When a pool deactivation is successful, iocage doesn't return anything,
|
||||
// so we have to fudge the output a bit.
|
||||
retObject.insert("success", "pool " + pool + " deactivated.");
|
||||
}
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Activate a zpool for iocage on the box
|
||||
QJsonObject Iocage::activatePool(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
@@ -40,7 +68,13 @@ QJsonObject Iocage::activatePool(QJsonObject jsin) {
|
||||
|
||||
vals.insert(key, value);
|
||||
|
||||
// This means no pool exists, give them the error.
|
||||
if ( output.at(i).indexOf("ERROR:") != -1 ) {
|
||||
retObject.insert("error", output.at(i));
|
||||
break;
|
||||
|
||||
retObject.insert("currently active", vals);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace sysadm{
|
||||
|
||||
class Iocage{
|
||||
public:
|
||||
static QJsonObject deactivatePool(QJsonObject);
|
||||
static QJsonObject activatePool(QJsonObject);
|
||||
static QJsonObject stopJail(QJsonObject);
|
||||
static QJsonObject startJail(QJsonObject);
|
||||
|
||||
Reference in New Issue
Block a user