diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index bdcf431..1c49306 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -441,6 +441,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal ok = true; out->insert("listvms", sysadm::Iohyve::listVMs()); } + if(act=="fetchiso"){ + ok = true; + out->insert("fetchiso", sysadm::Iohyve::fetchISO(in_args.toObject())); + } } //end of "action" key usage diff --git a/src/server/library/sysadm-iohyve.cpp b/src/server/library/sysadm-iohyve.cpp index 0b3213b..9adb9a6 100644 --- a/src/server/library/sysadm-iohyve.cpp +++ b/src/server/library/sysadm-iohyve.cpp @@ -4,14 +4,43 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== +#include #include "sysadm-general.h" #include "sysadm-iohyve.h" #include "sysadm-global.h" +#include "globals.h" using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Queue the fetch of an ISO +QJsonObject Iohyve::fetchISO(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("url") ) { + retObject.insert("error", "Missing required key 'url'"); + return retObject; + } + + // Get the key values + QString url = jsin.value("url").toString(); + + // Create a unique ID for this queued action + QString ID = QUuid::createUuid().toString(); + + // Queue the fetch action + DISPATCHER->queueProcess(ID, "iohyve fetch " + url); + + // Return some details to user that the action was queued + retObject.insert("command", "iohyve fetch " + url); + retObject.insert("comment", "Task Queued"); + retObject.insert("queueid", ID); + return retObject; +} + + // List the VMs on the box QJsonObject Iohyve::listVMs() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iohyve.h b/src/server/library/sysadm-iohyve.h index 7dec2fc..aceb0ce 100644 --- a/src/server/library/sysadm-iohyve.h +++ b/src/server/library/sysadm-iohyve.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iohyve{ public: + static QJsonObject fetchISO(QJsonObject); static QJsonObject listVMs(); };