mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add the first iocage sysadm API call
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"action" : "listjails"
}
REST Response:
-------------------------------
{
"args": {
"listjails": {
"611c89ae-c43c-11e5-9602-54ee75595566": {
"boot": "off",
"jid": "-",
"state": "down",
"tag": "testjail",
"type": "basejail"
}
}
}
}
WebSocket Request:
-------------------------------
{
"args" : {
"action" : "listjails"
},
"name" : "iocage",
"id" : "fooid",
"namespace" : "sysadm"
}
WebSocket Response:
-------------------------------
{
"args": {
"listjails": {
"611c89ae-c43c-11e5-9602-54ee75595566": {
"boot": "off",
"jid": "-",
"state": "down",
"tag": "testjail",
"type": "basejail"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -12,6 +12,7 @@ VERSION = 1.0.0
|
||||
|
||||
HEADERS += sysadm-global.h \
|
||||
sysadm-general.h \
|
||||
sysadm-iocage.h \
|
||||
sysadm-lifepreserver.h \
|
||||
sysadm-network.h \
|
||||
sysadm-firewall.h \
|
||||
@@ -22,6 +23,7 @@ HEADERS += sysadm-global.h \
|
||||
|
||||
SOURCES += NetDevice.cpp \
|
||||
sysadm-general.cpp \
|
||||
sysadm-iocage.cpp \
|
||||
sysadm-lifepreserver.cpp \
|
||||
sysadm-network.cpp \
|
||||
sysadm-firewall.cpp \
|
||||
|
||||
43
src/library/sysadm-iocage.cpp
Normal file
43
src/library/sysadm-iocage.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//===========================================
|
||||
// PC-BSD source code
|
||||
// Copyright (c) 2015, PC-BSD Software/iXsystems
|
||||
// Available under the 3-clause BSD license
|
||||
// See the LICENSE file for full details
|
||||
//===========================================
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-iocage.h"
|
||||
#include "sysadm-global.h"
|
||||
|
||||
using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
// List the jails on the box
|
||||
QJsonObject Iocage::listJails() {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList output = General::RunCommand("iocage list").split("\n");
|
||||
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
if ( output.at(i).indexOf("JID") != -1 )
|
||||
continue;
|
||||
|
||||
if ( output.at(i).isEmpty() )
|
||||
break;
|
||||
|
||||
QJsonObject jail;
|
||||
QString line = output.at(i).simplified();
|
||||
QString uuid = line.section(" ", 1, 1);
|
||||
|
||||
jail.insert("jid", line.section(" ", 0, 0));
|
||||
jail.insert("boot", line.section(" ", 2, 2));
|
||||
jail.insert("state", line.section(" ", 3, 3));
|
||||
jail.insert("tag", line.section(" ", 4, 4));
|
||||
jail.insert("type", line.section(" ", 5, 5));
|
||||
|
||||
retObject.insert(uuid, jail);
|
||||
}
|
||||
|
||||
return retObject;
|
||||
}
|
||||
22
src/library/sysadm-iocage.h
Normal file
22
src/library/sysadm-iocage.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//===========================================
|
||||
// PC-BSD source code
|
||||
// Copyright (c) 2015, PC-BSD Software/iXsystems
|
||||
// Available under the 3-clause BSD license
|
||||
// See the LICENSE file for full details
|
||||
//===========================================
|
||||
#ifndef __PCBSD_LIB_UTILS_IOCAGE_H
|
||||
#define __PCBSD_LIB_UTILS_IOCAGE_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include "sysadm-global.h"
|
||||
|
||||
namespace sysadm{
|
||||
|
||||
class Iocage{
|
||||
public:
|
||||
static QJsonObject listJails();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
//sysadm library interface classes
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-iocage.h"
|
||||
#include "sysadm-lifepreserver.h"
|
||||
#include "sysadm-network.h"
|
||||
#include "sysadm-systeminfo.h"
|
||||
@@ -73,14 +74,16 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
|
||||
//Go through and forward this request to the appropriate sub-system
|
||||
if(namesp=="rpc" && name=="query"){
|
||||
return AvailableSubsystems(IN.fullaccess, out);
|
||||
}else if(namesp=="rpc" && name=="syscache"){
|
||||
return EvaluateSyscacheRequest(IN.args, out);
|
||||
}else if(namesp=="rpc" && name=="dispatcher"){
|
||||
return EvaluateDispatcherRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="network"){
|
||||
return EvaluateSysadmNetworkRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="iocage"){
|
||||
return EvaluateSysadmIocageRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="lifepreserver"){
|
||||
return EvaluateSysadmLifePreserverRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="network"){
|
||||
return EvaluateSysadmNetworkRequest(IN.args, out);
|
||||
}else if(namesp=="rpc" && name=="syscache"){
|
||||
return EvaluateSyscacheRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="systeminfo"){
|
||||
return EvaluateSysadmSystemInfoRequest(IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="update"){
|
||||
@@ -332,3 +335,27 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal
|
||||
}
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
//==== SYSADM -- iocage ====
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonValue in_args, QJsonObject *out){
|
||||
if(in_args.isObject()){
|
||||
QStringList keys = in_args.toObject().keys();
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="listjails"){
|
||||
ok = true;
|
||||
out->insert("listjails", sysadm::Iocage::listJails());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
}else{ // if(in_args.isArray()){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ private:
|
||||
// -- Individual subsystems
|
||||
RestOutputStruct::ExitCode EvaluateSyscacheRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
RestOutputStruct::ExitCode EvaluateDispatcherRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm iocage API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmIocageRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm Network API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmNetworkRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm LifePreserver API
|
||||
|
||||
Reference in New Issue
Block a user