Add API call to create a new iohyve guest

REST Request:
-------------------------------
PUT /sysadm/iohyve
{
   "action" : "create",
   "name" : "bsdguest",
   "size" : "10G"
}

WebSocket Request:
-------------------------------
{
   "name" : "iohyve",
   "namespace" : "sysadm",
   "id" : "fooid",
   "args" : {
      "name" : "bsdguest",
      "action" : "create",
      "size" : "10G"
   }
}

Response:
-------------------------------
{
  "args": {
    "create": {
      "name": "bsdguest",
      "size": "10G"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-02-09 13:49:33 -05:00
parent 3c329b4292
commit 2fa64a2031
3 changed files with 35 additions and 0 deletions

View File

@@ -501,6 +501,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
bool ok = false;
if(keys.contains("action")){
QString act = JsonValueToString(in_args.toObject().value("action"));
if(act=="create"){
ok = true;
out->insert("create", sysadm::Iohyve::createGuest(in_args.toObject()));
}
if(act=="listvms"){
ok = true;
out->insert("listvms", sysadm::Iohyve::listVMs());

View File

@@ -13,6 +13,36 @@
using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
// Create a new guest VM
QJsonObject Iohyve::createGuest(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
if (! keys.contains("name") || !keys.contains("size") ) {
retObject.insert("error", "Missing required key(s) 'name/size'");
return retObject;
}
// Get the key values
QString name = jsin.value("name").toString();
QString size = jsin.value("size").toString();
QStringList output = General::RunCommand("iohyve create " + name + " " + size).split("\n");
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("cannot create") != -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("size", size);
return retObject;
}
// Queue the fetch of an ISO
QJsonObject Iohyve::fetchISO(QJsonObject jsin) {
QJsonObject retObject;

View File

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