mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
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:
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace sysadm{
|
||||
|
||||
class Iohyve{
|
||||
public:
|
||||
static QJsonObject createGuest(QJsonObject);
|
||||
static QJsonObject fetchISO(QJsonObject);
|
||||
static QJsonObject isSetup();
|
||||
static QJsonObject listVMs();
|
||||
|
||||
Reference in New Issue
Block a user