Add a new iocage API call to activate zpools.

It has 2 different outputs depending on if `pool` was actually specified.

If you specify a pool this is what you get:
REST Request:
-------------------------------
PUT /sysadm/iocage
{
   "action" : "activatepool",
   "pool" : "tank"
}

REST Response:
-------------------------------
{
    "args": {
        "activatepool": {
            "success": "pool tank activated."
        }
    }
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "activatepool",
      "pool" : "tank"
   },
   "name" : "iocage",
   "id" : "fooid",
   "namespace" : "sysadm"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "activatepool": {
      "success": "pool tank activated."
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}

If you do not specify a pool, this is your output:
REST Request:
-------------------------------
PUT /sysadm/iocage
{
   "action" : "activatepool"
}

REST Response:
-------------------------------
{
    "args": {
        "activatepool": {
            "currently active": {
                "pool": " tank"
            }
        }
    }
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "activatepool"
   },
   "namespace" : "sysadm",
   "name" : "iocage",
   "id" : "fooid"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "activatepool": {
      "currently active": {
        "pool": " tank"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Brandon Schneider
2016-02-03 19:14:18 -06:00
parent 437b3d76f3
commit 1048b3a6da
3 changed files with 40 additions and 6 deletions

View File

@@ -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=="activatepool"){
ok = true;
out->insert("activatepool", sysadm::Iocage::activatePool(in_args.toObject()));
}
if(act=="stopjail"){
ok = true;
out->insert("stopjail", sysadm::Iocage::stopJail(in_args.toObject()));

View File

@@ -12,6 +12,41 @@ using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Activate a zpool for iocage on the box
QJsonObject Iocage::activatePool(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
// Get the key values
QString pool = jsin.value("pool").toString();
QStringList output = General::RunCommand("iocage activate " + pool).split("\n");
QJsonObject vals;
for ( int i = 0; i < output.size(); i++)
{
// Otherwise we get null output before the actual active pool
if ( i > 0 )
break;
// When a pool activation is successful, iocage doesn't return anything,
// so we have to fudge the output a bit.
if ( output.at(i).isEmpty())
{
retObject.insert("success", "pool " + pool + " activated.");
break;
} else {
QString key = output.at(i).simplified().section(":", 0, 0);
QString value = output.at(i).simplified().section(":", 1, 1);
vals.insert(key, value);
retObject.insert("currently active", vals);
}
}
return retObject;
}
// Stop a jail on the box
QJsonObject Iocage::stopJail(QJsonObject jsin) {
QJsonObject retObject;
@@ -30,9 +65,6 @@ QJsonObject Iocage::stopJail(QJsonObject jsin) {
QJsonObject vals;
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("JID") != -1 )
continue;
if ( output.at(i).isEmpty() )
break;
@@ -64,9 +96,6 @@ QJsonObject Iocage::startJail(QJsonObject jsin) {
QJsonObject vals;
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("JID") != -1 )
continue;
if ( output.at(i).isEmpty() )
break;

View File

@@ -14,6 +14,7 @@ namespace sysadm{
class Iocage{
public:
static QJsonObject activatePool(QJsonObject);
static QJsonObject stopJail(QJsonObject);
static QJsonObject startJail(QJsonObject);
static QJsonObject getDefaultSettings();