From a727b4a8a234b38646eb699657175c5970d72fec Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Thu, 4 Feb 2016 14:58:29 -0500 Subject: [PATCH] Add new API call to fetch an ISO for iohyve Uses the "url" argument, which should be the address understood by "fetch" to grab an ISO from, I.E. http://, ftp://, file://, etc The task will queue, and return an event when finished REST Request: ------------------------------- PUT /sysadm/iohyve { "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "action" : "fetchiso" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "name" : "iohyve", "args" : { "url" : "ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "action" : "fetchiso" }, "id" : "fooid" } Response: ------------------------------- { "args": { "fetchiso": { "command": "iohyve fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso", "comment": "Task Queued", "queueid": "{b3a8b980-a564-4ff8-86a2-1971bd4f58d1}" } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-iohyve.cpp | 29 ++++++++++++++++++++++++++++ src/server/library/sysadm-iohyve.h | 1 + 3 files changed, 34 insertions(+) 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(); };