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 <name>" 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"
}
This commit is contained in:
Kris Moore
2016-02-09 14:21:34 -05:00
parent bef748977e
commit e6b285ebfd
3 changed files with 34 additions and 0 deletions

View File

@@ -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());

View File

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

View File

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