Add new iocage API call to clone jails.

If you supply props your output will look like this:

REST Request:
-------------------------------
PUT /sysadm/iocage
{
   "props" : "tag=newtest",
   "jail" : "test",
   "action" : "clonejail"
}

WebSocket Request:
-------------------------------
{
   "namespace" : "sysadm",
   "name" : "iocage",
   "args" : {
      "action" : "clonejail",
      "jail" : "test",
      "props" : "tag=newtest"
   },
   "id" : "fooid"
}

Response:
-------------------------------
{
  "args": {
    "clonejail": {
      "jail": "test",
      "props": "tag=newtest",
      "success": {
        "Successfully created": " 5e1fe97e-cfba-11e5-8209-d05099728dbf (newtest)"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}

Otherwise iocage will populate it's own values and the props returned by the API will be empty:

REST Request:
-------------------------------
PUT /sysadm/iocage
{
   "action" : "clonejail",
   "jail" : "test"
}

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

Response:
-------------------------------
{
  "args": {
    "clonejail": {
      "jail": "test",
      "props": "",
      "success": {
        "Successfully created": " 89e78032-cfba-11e5-8209-d05099728dbf (2016-02-09@23"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Brandon Schneider
2016-02-09 23:55:18 -06:00
parent 9af28e5369
commit 2adb8537e1
3 changed files with 47 additions and 2 deletions

View File

@@ -41,7 +41,7 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
if(QFile::exists("/usr/local/sbin/beadm")){
out->insert("sysadm/beadm", "read/write");
}
// - dispatcher (Internal to server - always available)
//"read" is the event notifications, "write" is the ability to queue up jobs
@@ -213,7 +213,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmBEADMRequest(const QJsonValu
}else if(act=="destroybe"){
ok = true;
out->insert("destroybe", sysadm::BEADM::destroyBE(in_args.toObject()));
}
}
} //end of "action" key usage
//If nothing done - return the proper code
@@ -433,6 +433,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
bool ok = false;
if(keys.contains("action")){
QString act = JsonValueToString(in_args.toObject().value("action"));
if(act=="clonejail"){
ok = true;
out->insert("clonejail", sysadm::Iocage::cloneJail(in_args.toObject()));
}
if(act=="cleanall"){
ok = true;
out->insert("cleanall", sysadm::Iocage::cleanAll());

View File

@@ -12,6 +12,46 @@ using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Clone a jail on the box
QJsonObject Iocage::cloneJail(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
if (! keys.contains("jail") ) {
retObject.insert("error", "Missing required keys");
return retObject;
}
// Get the key values
QString jail = jsin.value("jail").toString();
QString props = jsin.value("props").toString();
QStringList output = General::RunCommand("iocage clone " + jail + " " + props).split("\n");
QJsonObject vals;
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).isEmpty() )
break;
if ( output.at(i).indexOf("ERROR:") != -1 ) {
retObject.insert("error", output.at(i));
return retObject;
} 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("jail", jail);
retObject.insert("props", props);
retObject.insert("success", vals);
return retObject;
}
// Clean everything iocage related on a box
QJsonObject Iocage::cleanAll() {
QJsonObject retObject;

View File

@@ -14,6 +14,7 @@ namespace sysadm{
class Iocage{
public:
static QJsonObject cloneJail(QJsonObject);
static QJsonObject cleanAll();
static QJsonObject cleanTemplates();
static QJsonObject cleanReleases();