Add new iohyve API call to set properties

Requires "name" of the VM, and then any other args
will be set on the VM as properties

REST Request:
-------------------------------
PUT /sysadm/iohyve
{
   "ram" : "512M",
   "name" : "bsdguest",
   "action" : "setprop"
}

WebSocket Request:
-------------------------------
{
   "namespace" : "sysadm",
   "id" : "fooid",
   "args" : {
      "ram" : "512M",
      "name" : "bsdguest",
      "action" : "setprop"
   },
   "name" : "iohyve"
}

Response:
-------------------------------
{
  "args": {
    "setprop": {
      "bsdguest": {
        "ram": "512M"
      }
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-03-25 11:24:13 -04:00
parent 87f1b49fed
commit 3dfe44dbb0
3 changed files with 54 additions and 0 deletions

View File

@@ -641,6 +641,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
ok = true;
out->insert("resizedisk", sysadm::Iohyve::resizeDisk(in_args.toObject()));
}
else if(act=="setprop"){
ok = true;
out->insert("setprop", sysadm::Iohyve::setProp(in_args.toObject()));
}
else if(act=="setup"){
ok = true;
out->insert("setup", sysadm::Iohyve::setupIohyve(in_args.toObject()));

View File

@@ -452,6 +452,55 @@ QJsonObject Iohyve::setupIohyve(QJsonObject jsin) {
return retObject;
}
// Set properties
QJsonObject Iohyve::setProp(QJsonObject jsin) {
QJsonObject retObject;
QJsonObject props;
QStringList keys = jsin.keys();
if (! keys.contains("name") ) {
retObject.insert("error", "Missing required key 'name'");
return retObject;
}
// Get the key values
QString name = jsin.value("name").toString();
// Load the supplied settings
QStringList settings;
QStringList values;
for ( int i = 0; i < keys.size(); i++)
{
if ( keys.at(i) == "name" )
continue;
if ( keys.at(i) == "action" )
continue;
settings << keys.at(i);
values << jsin.value(keys.at(i)).toString();
props.insert(keys.at(i), jsin.value(keys.at(i)).toString());
}
if ( settings.isEmpty() ) {
retObject.insert("error", "No settings supplied!");
return retObject;
}
QStringList setargs;
setargs << "set" << name;
for ( int i = 0; i < settings.size(); i++)
{
setargs << settings.at(i) + "=" + values.at(i);
}
// Set it now
QString output = General::RunCommand("iohyve", setargs);
retObject.insert(name, props);
return retObject;
}
// Start a guest
QJsonObject Iohyve::startGuest(QJsonObject jsin) {
QJsonObject retObject;

View File

@@ -30,6 +30,7 @@ public:
static QJsonObject resizeDisk(QJsonObject);
static QJsonObject rmISO(QJsonObject);
static QJsonObject setupIohyve(QJsonObject);
static QJsonObject setProp(QJsonObject);
static QJsonObject startGuest(QJsonObject);
static QJsonObject stopGuest(QJsonObject);
static QJsonObject version();