Add new API call to iohyve to rename an existing ISO file on

disk

REST Request:
-------------------------------
PUT /sysadm/iohyve
{
   "source" : "test.iso",
   "target" : "102.iso",
   "action" : "renameiso"
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "target" : "102.iso",
      "source" : "test.iso",
      "action" : "renameiso"
   },
   "id" : "fooid",
   "name" : "iohyve",
   "namespace" : "sysadm"
}

Response:
-------------------------------
{
  "args": {
    "renameiso": {
      "source": "test.iso",
      "target": "102.iso"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-02-04 15:23:44 -05:00
parent a727b4a8a2
commit 4d3b590f46
3 changed files with 35 additions and 0 deletions

View File

@@ -445,6 +445,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
ok = true;
out->insert("fetchiso", sysadm::Iohyve::fetchISO(in_args.toObject()));
}
if(act=="renameiso"){
ok = true;
out->insert("renameiso", sysadm::Iohyve::renameISO(in_args.toObject()));
}
} //end of "action" key usage

View File

@@ -69,3 +69,33 @@ QJsonObject Iohyve::listVMs() {
return retObject;
}
// Rename an ISO file
QJsonObject Iohyve::renameISO(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
if (! keys.contains("source") || ! keys.contains("target") ) {
retObject.insert("error", "Missing required key(s) 'source / target'");
return retObject;
}
// Get the key values
QString source = jsin.value("source").toString();
QString target = jsin.value("target").toString();
QStringList output = General::RunCommand("iohyve renameiso " + source + " " + 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("source", source);
retObject.insert("target", target);
return retObject;
}

View File

@@ -16,6 +16,7 @@ class Iohyve{
public:
static QJsonObject fetchISO(QJsonObject);
static QJsonObject listVMs();
static QJsonObject renameISO(QJsonObject);
};
} //end of pcbsd namespace