Add new API call to iohyve to remove a iso dataset

Target is the iso we are removing from iohyve

REST Request:
-------------------------------
PUT /sysadm/iohyve
{
   "action" : "rmiso",
   "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso"
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "name" : "iohyve",
   "args" : {
      "target" : "FreeBSD-10.2-RELEASE-amd64-bootonly.iso",
      "action" : "rmiso"
   },
   "namespace" : "sysadm"
}

Response:
-------------------------------
{
  "args": {
    "rmiso": {
      "target": "FreeBSD-10.2-RELEASE-amd64-bootonly.iso"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
JoshDW19
2016-02-04 15:53:45 -05:00
parent 4d3b590f46
commit 5cb8dcf026
3 changed files with 29 additions and 1 deletions

View File

@@ -449,7 +449,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
ok = true;
out->insert("renameiso", sysadm::Iohyve::renameISO(in_args.toObject()));
}
if(act=="rmiso"){
ok = true;
out->insert("rmiso", sysadm::Iohyve::rmISO(in_args.toObject()));
}
} //end of "action" key usage
//If nothing done - return the proper code

View File

@@ -98,4 +98,28 @@ QJsonObject Iohyve::renameISO(QJsonObject jsin) {
return retObject;
}
// Remove an ISO file
QJsonObject Iohyve::rmISO(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
if (! keys.contains("target") ) {
retObject.insert("error", "Missing required key 'target'");
return retObject;
}
// Get the key values
QString target = jsin.value("target").toString();
QStringList output = General::RunCommand("iohyve rmiso " + target).split("\n");
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("cannot open") != -1 ) {
retObject.insert("error", output.at(i));
return retObject;
}
}
retObject.insert("target", target);
return retObject;
}

View File

@@ -17,6 +17,7 @@ public:
static QJsonObject fetchISO(QJsonObject);
static QJsonObject listVMs();
static QJsonObject renameISO(QJsonObject);
static QJsonObject rmISO(QJsonObject);
};
} //end of pcbsd namespace