mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Added stopping an iocage jail API call
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"action" : "stopjail",
"jail" : "test"
}
REST Response:
-------------------------------
{
"args": {
"stopjail": {
"test": {
"* Stopping 0bf985de-ca0f-11e5-8d45-d05099728dbf (test)": "",
"+ Removing jail process OK": "",
"+ Running post-stop OK": "",
"+ Running pre-stop OK": "",
"+ Stopping services OK": ""
}
}
}
}
WebSocket Request:
-------------------------------
{
"args" : {
"jail" : "test",
"action" : "stopjail"
},
"namespace" : "sysadm",
"id" : "fooid",
"name" : "iocage"
}
WebSocket Response:
-------------------------------
{
"args": {
"stopjail": {
"test": {
"INFO": " 0bf985de-ca0f-11e5-8d45-d05099728dbf (test) is already down"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -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=="stopjail"){
|
||||
ok = true;
|
||||
out->insert("stopjail", sysadm::Iocage::stopJail(in_args.toObject()));
|
||||
}
|
||||
if(act=="startjail"){
|
||||
ok = true;
|
||||
out->insert("startjail", sysadm::Iocage::startJail(in_args.toObject()));
|
||||
|
||||
@@ -12,6 +12,40 @@ using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
// Stop a jail on the box
|
||||
QJsonObject Iocage::stopJail(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 = General::RunCommand("iocage stop " + jail).split("\n");
|
||||
|
||||
QJsonObject vals;
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
if ( output.at(i).indexOf("JID") != -1 )
|
||||
continue;
|
||||
|
||||
if ( output.at(i).isEmpty() )
|
||||
break;
|
||||
|
||||
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, vals);
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Start a jail on the box
|
||||
QJsonObject Iocage::startJail(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace sysadm{
|
||||
|
||||
class Iocage{
|
||||
public:
|
||||
static QJsonObject stopJail(QJsonObject);
|
||||
static QJsonObject startJail(QJsonObject);
|
||||
static QJsonObject getDefaultSettings();
|
||||
static QJsonObject getJailSettings(QJsonObject);
|
||||
|
||||
Reference in New Issue
Block a user