Add new API class for 'iohyve' along with the initial 'listvms'

API call

REST Request:
-------------------------------
PUT /sysadm/iohyve
{
   "action" : "listvms"
}

REST Response:
-------------------------------
{
    "args": {
        "listvms": {
            "testguest": {
                "description": "February 1, 2016 at 03:11:57 PM EST",
                "rcboot": "NO",
                "running": "NO",
                "vmm": "YES"
            }
        }
    }
}

WebSocket Request:
-------------------------------
{
   "namespace" : "sysadm",
   "args" : {
      "action" : "listvms"
   },
   "name" : "iohyve",
   "id" : "fooid"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "listvms": {
      "testguest": {
        "description": "February 1, 2016 at 03:11:57 PM EST",
        "rcboot": "NO",
        "running": "NO",
        "vmm": "YES"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-02-01 15:23:21 -05:00
parent e65a967729
commit bd53bbc29b
5 changed files with 100 additions and 0 deletions

View File

@@ -11,6 +11,7 @@
//sysadm library interface classes
#include "library/sysadm-general.h"
#include "library/sysadm-iocage.h"
#include "library/sysadm-iohyve.h"
#include "library/sysadm-lifepreserver.h"
#include "library/sysadm-network.h"
#include "library/sysadm-systeminfo.h"
@@ -52,6 +53,11 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
out->insert("sysadm/iocage", "read/write");
}
// - iohyve
if(QFile::exists("/usr/local/sbin/iohyve")){
out->insert("sysadm/iohyve", "read/write");
}
// - Generic system information
out->insert("sysadm/systeminfo","read/write");
@@ -86,6 +92,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
return EvaluateDispatcherRequest(IN.fullaccess, IN.args, out);
}else if(namesp=="sysadm" && name=="iocage"){
return EvaluateSysadmIocageRequest(IN.args, out);
}else if(namesp=="sysadm" && name=="iohyve"){
return EvaluateSysadmIohyveRequest(IN.args, out);
}else if(namesp=="sysadm" && name=="lifepreserver"){
return EvaluateSysadmLifePreserverRequest(IN.args, out);
}else if(namesp=="sysadm" && name=="network"){
@@ -387,3 +395,27 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
}
return RestOutputStruct::OK;
}
//==== SYSADM -- iohyve ====
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(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=="listvms"){
ok = true;
out->insert("listvms", sysadm::Iohyve::listVMs());
}
} //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;
}

View File

@@ -48,6 +48,8 @@ private:
RestOutputStruct::ExitCode EvaluateDispatcherRequest(bool allaccess, const QJsonValue in_args, QJsonObject *out);
// -- sysadm iocage API
RestOutputStruct::ExitCode EvaluateSysadmIocageRequest(const QJsonValue in_args, QJsonObject *out);
// -- sysadm iohyve API
RestOutputStruct::ExitCode EvaluateSysadmIohyveRequest(const QJsonValue in_args, QJsonObject *out);
// -- sysadm Network API
RestOutputStruct::ExitCode EvaluateSysadmNetworkRequest(const QJsonValue in_args, QJsonObject *out);
// -- sysadm LifePreserver API

View File

@@ -4,6 +4,7 @@ CONFIG += c++11
HEADERS += $${PWD}/sysadm-global.h \
$${PWD}/sysadm-general.h \
$${PWD}/sysadm-iocage.h \
$${PWD}/sysadm-iohyve.h \
$${PWD}/sysadm-lifepreserver.h \
$${PWD}/sysadm-network.h \
$${PWD}/sysadm-firewall.h \
@@ -15,6 +16,7 @@ HEADERS += $${PWD}/sysadm-global.h \
SOURCES += $${PWD}/NetDevice.cpp \
$${PWD}/sysadm-general.cpp \
$${PWD}/sysadm-iocage.cpp \
$${PWD}/sysadm-iohyve.cpp \
$${PWD}/sysadm-lifepreserver.cpp \
$${PWD}/sysadm-network.cpp \
$${PWD}/sysadm-firewall.cpp \

View File

@@ -0,0 +1,42 @@
//===========================================
// PC-BSD source code
// Copyright (c) 2016, PC-BSD Software/iXsystems
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "sysadm-general.h"
#include "sysadm-iohyve.h"
#include "sysadm-global.h"
using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// List the VMs on the box
QJsonObject Iohyve::listVMs() {
QJsonObject retObject;
QStringList output = General::RunCommand("iohyve list").split("\n");
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("VMM") != -1 )
continue;
if ( output.at(i).isEmpty() )
break;
QJsonObject vm;
QString line = output.at(i).simplified();
QString guest = line.section(" ", 0, 0);
vm.insert("vmm", line.section(" ", 1, 1));
vm.insert("running", line.section(" ", 2, 2));
vm.insert("rcboot", line.section(" ", 3, 3));
vm.insert("description", line.section(" ", 4, -1));
retObject.insert(guest, vm);
}
return retObject;
}

View File

@@ -0,0 +1,22 @@
//===========================================
// PC-BSD source code
// Copyright (c) 2016, PC-BSD Software/iXsystems
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#ifndef __PCBSD_LIB_UTILS_IOHYVE_H
#define __PCBSD_LIB_UTILS_IOHYVE_H
#include <QJsonObject>
#include "sysadm-global.h"
namespace sysadm{
class Iohyve{
public:
static QJsonObject listVMs();
};
} //end of pcbsd namespace
#endif