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"
}
This commit is contained in:
Kris Moore
2016-02-04 14:58:29 -05:00
parent dda2ede751
commit a727b4a8a2
3 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -4,14 +4,43 @@
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include <QUuid>
#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;

View File

@@ -14,6 +14,7 @@ namespace sysadm{
class Iohyve{
public:
static QJsonObject fetchISO(QJsonObject);
static QJsonObject listVMs();
};