Add API call for BEADM to rename a boot environment

REST Request:
-------------------------------
PUT /sysadm/beadm
{
   "source" : "newname",
   "action" : "renamebe",
   "target" : "bootthingy"
}

WebSocket Request:
-------------------------------
{
   "namespace" : "sysadm",
   "name" : "beadm",
   "id" : "fooid",
   "args" : {
      "source" : "newname",
      "target" : "bootthingy",
      "action" : "renamebe"
   }
}

Response:
-------------------------------
{
  "args": {
    "renamebe": {
      "source": "newname",
      "target": "bootthingy"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
This commit is contained in:
JoshDW19
2016-02-08 14:24:16 -05:00
parent 20114a9d04
commit 849230bf2f
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1 @@
,josh,localhost,08.02.2016 13:33,file:///usr/home/josh/.config/libreoffice/4;

View File

@@ -47,3 +47,31 @@ QJsonObject BEADM::listBEs() {
return retObject;
}
QJsonObject BEADM::renameBE(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("beadm rename " + source + " " + target).split("\n");
for ( int i = 0; i < output.size(); i++)
{
if ( output.at(i).indexOf("ERROR") != -1 ) {
retObject.insert("error", output.at(i));
return retObject;
}
}
retObject.insert("source", source);
retObject.insert("target", target);
return retObject;
}

View File

@@ -15,6 +15,7 @@ namespace sysadm{
class BEADM{
public:
static QJsonObject listBEs();
static QJsonObject renameBE(QJsonObject);
};
} //end of pcbsd namespace