mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add new iocage API call to destroy jails.
This uses the `force` switch to bypass interaction.
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"action" : "destroyjail",
"jail" : "test"
}
WebSocket Request:
-------------------------------
{
"args" : {
"action" : "destroyjail",
"jail" : "test"
},
"name" : "iocage",
"id" : "fooid",
"namespace" : "sysadm"
}
Response:
-------------------------------
{
"args": {
"destroyjail": {
"success": {
"Destroying": " 3030c554-d05e-11e5-8209-d05099728dbf"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -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=="destroyjail"){
|
||||
ok = true;
|
||||
out->insert("destroyjail", sysadm::Iocage::destroyJail(in_args.toObject()));
|
||||
}
|
||||
if(act=="createjail"){
|
||||
ok = true;
|
||||
out->insert("createjail", sysadm::Iocage::createJail(in_args.toObject()));
|
||||
|
||||
@@ -12,6 +12,44 @@ using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
// Destroy a jail on the box
|
||||
QJsonObject Iocage::destroyJail(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();
|
||||
QStringList output;
|
||||
|
||||
output = General::RunCommand("iocage destroy -f " + jail).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("success", vals);
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Create a jail on the box
|
||||
QJsonObject Iocage::createJail(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace sysadm{
|
||||
|
||||
class Iocage{
|
||||
public:
|
||||
static QJsonObject destroyJail(QJsonObject);
|
||||
static QJsonObject createJail(QJsonObject);
|
||||
static QJsonObject cloneJail(QJsonObject);
|
||||
static QJsonObject cleanAll();
|
||||
|
||||
Reference in New Issue
Block a user