Add new iocage API call to clean all jails.

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

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

Response:
-------------------------------
{
  "args": {
    "cleanjails": {
      "success": "All jails have been cleaned."
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Brandon Schneider
2016-02-04 22:31:19 -06:00
parent 27cc7f279e
commit dbbcf44d35
3 changed files with 28 additions and 0 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=="cleanjails"){
ok = true;
out->insert("cleanjails", sysadm::Iocage::cleanJails());
}
if(act=="capjail"){
ok = true;
out->insert("capjail", sysadm::Iocage::capJail(in_args.toObject()));

View File

@@ -12,6 +12,29 @@ using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Clean all jails on a box
QJsonObject Iocage::cleanJails() {
QJsonObject retObject;
QStringList output = General::RunCommand("iocage clean -fj ").split("\n");
for ( int i = 0; i < output.size(); i++)
{
// This means either a mount is stuck or a jail cannot be stopped,
// give them the error.
if ( output.at(i).indexOf("ERROR:") != -1 ) {
retObject.insert("error", output.at(i));
break;
} else {
// iocage does a spinner for these that is distracting to see returned,
// returning what a user wants to actually see.
retObject.insert("success", "All jails have been cleaned.");
}
}
return retObject;
}
// Resource cap a jail on the box
QJsonObject Iocage::capJail(QJsonObject jsin) {
QJsonObject retObject;

View File

@@ -14,6 +14,7 @@ namespace sysadm{
class Iocage{
public:
static QJsonObject cleanJails();
static QJsonObject capJail(QJsonObject);
static QJsonObject deactivatePool(QJsonObject);
static QJsonObject activatePool(QJsonObject);