From e6b285ebfd9bc1123c14fa1780cd4c2de85889a6 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Tue, 9 Feb 2016 14:21:34 -0500 Subject: [PATCH] Add API call to start the iohyve installation of a guest from an ISO FYI, this only boots the VM with the ISO, to do the install the user still needs to run "iohyve console " from the system, which uses serial mode to bring up a terminal REST Request: ------------------------------- PUT /sysadm/iohyve { "name" : "bsdguest", "iso" : "FreeBSD-10.2-RELEASE-amd64-disc1.iso", "action" : "install" } WebSocket Request: ------------------------------- { "namespace" : "sysadm", "name" : "iohyve", "id" : "fooid", "args" : { "action" : "install", "iso" : "FreeBSD-10.2-RELEASE-amd64-disc1.iso", "name" : "bsdguest" } } Response: ------------------------------- { "args": { "install": { "iso": "FreeBSD-10.2-RELEASE-amd64-disc1.iso", "name": "bsdguest" } }, "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 7f8a102..70d3c95 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -513,6 +513,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal ok = true; out->insert("fetchiso", sysadm::Iohyve::fetchISO(in_args.toObject())); } + if(act=="install"){ + ok = true; + out->insert("install", sysadm::Iohyve::installGuest(in_args.toObject())); + } if(act=="issetup"){ ok = true; out->insert("issetup", sysadm::Iohyve::isSetup()); diff --git a/src/server/library/sysadm-iohyve.cpp b/src/server/library/sysadm-iohyve.cpp index 767d326..3bddd62 100644 --- a/src/server/library/sysadm-iohyve.cpp +++ b/src/server/library/sysadm-iohyve.cpp @@ -69,6 +69,35 @@ QJsonObject Iohyve::fetchISO(QJsonObject jsin) { return retObject; } +// Create a new guest VM +QJsonObject Iohyve::installGuest(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + if (! keys.contains("name") || !keys.contains("iso") ) { + retObject.insert("error", "Missing required key(s) 'name/iso'"); + return retObject; + } + + // Get the key values + QString name = jsin.value("name").toString(); + QString iso = jsin.value("iso").toString(); + + QStringList output = General::RunCommand("iohyve install " + name + " " + iso).split("\n"); + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("Could not open") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } + } + + // Return some details to user that the action was queued + retObject.insert("name", name); + retObject.insert("iso", iso); + return retObject; +} + // Return if iohyve is setup on the box QJsonObject Iohyve::isSetup() { QJsonObject retObject; diff --git a/src/server/library/sysadm-iohyve.h b/src/server/library/sysadm-iohyve.h index 23d8009..20ffd6a 100644 --- a/src/server/library/sysadm-iohyve.h +++ b/src/server/library/sysadm-iohyve.h @@ -16,6 +16,7 @@ class Iohyve{ public: static QJsonObject createGuest(QJsonObject); static QJsonObject fetchISO(QJsonObject); + static QJsonObject installGuest(QJsonObject); static QJsonObject isSetup(); static QJsonObject listVMs(); static QJsonObject renameISO(QJsonObject);