Add new iocage API call to list resource usage for jails.

REST Request:
-------------------------------
PUT /sysadm/iocage
{
   "action" : "df"
}

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

Response:
-------------------------------
{
  "args": {
    "df": {
      "f250ab25-d062-11e5-8209-d05099728dbf": {
        "ava": "83.4G",
        "crt": "2.30x",
        "qta": "none",
        "res": "none",
        "tag": "test",
        "use": "1.69M"
      },
      "f39318ae-d064-11e5-8209-d05099728dbf": {
        "ava": "83.4G",
        "crt": "2.30x",
        "qta": "none",
        "res": "none",
        "tag": "test2",
        "use": "1.69M"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Brandon Schneider
2016-02-10 20:14:03 -06:00
parent e2cede4fa0
commit 76dec01bb4
3 changed files with 40 additions and 0 deletions

View File

@@ -471,6 +471,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
bool ok = false;
if(keys.contains("action")){
QString act = JsonValueToString(in_args.toObject().value("action"));
if(act=="df"){
ok = true;
out->insert("df", sysadm::Iocage::df());
}
if(act=="destroyjail"){
ok = true;
out->insert("destroyjail", sysadm::Iocage::destroyJail(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
// Show resource usage for jails on the box
QJsonObject Iocage::df() {
QJsonObject retObject;
// Get the key values
QStringList output = General::RunCommand("iocage df").split("\n");
QJsonObject vals;
for ( int i = 0; i < output.size(); i++)
{
// Null output at first
if ( output.at(i).isEmpty() )
continue;
QJsonObject jail;
QString line = output.at(i).simplified();
QString uuid = line.section(" ", 0, 0);
// Otherwise we get a list of what we already know.
if ( line.section(" ", 0, 0) == "UUID" )
continue;
jail.insert("crt", line.section(" ", 1, 1));
jail.insert("res", line.section(" ", 2, 2));
jail.insert("qta", line.section(" ", 3, 3));
jail.insert("use", line.section(" ", 4, 4));
jail.insert("ava", line.section(" ", 5, 5));
jail.insert("tag", line.section(" ", 6, 6));
retObject.insert(uuid, jail);
}
return retObject;
}
// Destroy a jail on the box
QJsonObject Iocage::destroyJail(QJsonObject jsin) {
QJsonObject retObject;

View File

@@ -14,6 +14,7 @@ namespace sysadm{
class Iocage{
public:
static QJsonObject df();
static QJsonObject destroyJail(QJsonObject);
static QJsonObject createJail(QJsonObject);
static QJsonObject cloneJail(QJsonObject);