mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add new API call to stop a guest VM
REST Request:
-------------------------------
PUT /sysadm/iohyve
{
"action" : "stop",
"name" : "bsdguest"
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"args" : {
"action" : "stop",
"name" : "bsdguest"
},
"name" : "iohyve",
"namespace" : "sysadm"
}
Response:
-------------------------------
{
"args": {
"stop": {
"name": "bsdguest"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -537,6 +537,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
|
||||
ok = true;
|
||||
out->insert("start", sysadm::Iohyve::startGuest(in_args.toObject()));
|
||||
}
|
||||
if(act=="stop"){
|
||||
ok = true;
|
||||
out->insert("stop", sysadm::Iohyve::stopGuest(in_args.toObject()));
|
||||
}
|
||||
} //end of "action" key usage
|
||||
|
||||
//If nothing done - return the proper code
|
||||
|
||||
@@ -256,3 +256,38 @@ QJsonObject Iohyve::startGuest(QJsonObject jsin) {
|
||||
retObject.insert("name", name);
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Stop a guest
|
||||
QJsonObject Iohyve::stopGuest(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
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();
|
||||
|
||||
QString stoparg = "stop";
|
||||
if (! keys.contains("force") ) {
|
||||
if ( jsin.value("force").toString() == "true" ) {
|
||||
stoparg = "forcekill";
|
||||
}
|
||||
}
|
||||
|
||||
// Do the stop right now
|
||||
QStringList output = General::RunCommand("iohyve " + stoparg + " " + name).split("\n");
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
// This doesn't work, iohyve doesn't return error message right now
|
||||
if ( output.at(i).indexOf("No such guest") != -1 ) {
|
||||
retObject.insert("error", output.at(i));
|
||||
return retObject;
|
||||
}
|
||||
}
|
||||
|
||||
retObject.insert("name", name);
|
||||
return retObject;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
static QJsonObject rmISO(QJsonObject);
|
||||
static QJsonObject setupIohyve(QJsonObject);
|
||||
static QJsonObject startGuest(QJsonObject);
|
||||
static QJsonObject stopGuest(QJsonObject);
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
Reference in New Issue
Block a user