mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
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:
@@ -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()));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user