Add new iocage API call to clean all RELEASEs

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

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

Response:
-------------------------------
{
  "args": {
    "cleanreleases": {
      "success": "All RELEASEs have been cleaned."
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Brandon Schneider
2016-02-04 22:34:01 -06:00
parent dbbcf44d35
commit 920a51f997
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=="cleanreleases"){
ok = true;
out->insert("cleanreleases", sysadm::Iocage::cleanReleases());
}
if(act=="cleanjails"){
ok = true;
out->insert("cleanjails", sysadm::Iocage::cleanJails());

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 RELEASEs on a box
QJsonObject Iocage::cleanReleases() {
QJsonObject retObject;
QStringList output = General::RunCommand("iocage clean -fr ").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 RELEASEs have been cleaned.");
}
}
return retObject;
}
// Clean all jails on a box
QJsonObject Iocage::cleanJails() {
QJsonObject retObject;

View File

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