API call for mounting a boot environment. Can be passed the additional argument below of mountpoint to set a specific

mount point directory set by the user.

REST Request:
-------------------------------
PUT /sysadm/beadm
{
   "mountpoint" : "/tmp/mounteddir/",
   "action" : "mountbe",
   "be" : "green"
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "namespace" : "sysadm",
   "name" : "beadm",
   "args" : {
      "mountpoint" : "/tmp/mounteddir/",
      "be" : "green",
      "action" : "mountbe"
   }
}

Response:
-------------------------------
{
  "args": {
    "mountbe": {
      "be": "green",
      "mountpoint": ""
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
JoshDW19
2016-02-11 10:57:57 -05:00
parent 4ed13b1d46
commit e645840496
3 changed files with 45 additions and 9 deletions

View File

@@ -213,6 +213,9 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmBEADMRequest(const QJsonValu
}else if(act=="destroybe"){
ok = true;
out->insert("destroybe", sysadm::BEADM::destroyBE(in_args.toObject()));
}else if(act=="mountbe"){
ok = true;
out->insert("mountbe", sysadm::BEADM::mountBE(in_args.toObject()));
}
} //end of "action" key usage
@@ -517,10 +520,6 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
ok = true;
out->insert("rmiso", sysadm::Iohyve::rmISO(in_args.toObject()));
}
if(act=="setup"){
ok = true;
out->insert("setup", sysadm::Iohyve::setupIohyve(in_args.toObject()));
}
} //end of "action" key usage
//If nothing done - return the proper code

View File

@@ -50,7 +50,7 @@ QJsonObject BEADM::listBEs() {
// Rename the specified source BE to a a new target BE name
QJsonObject BEADM::renameBE(QJsonObject jsin) {
QJsonObject BEADM::renameBE(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
@@ -79,7 +79,7 @@ QJsonObject BEADM::renameBE(QJsonObject jsin) {
// Activate the given BeName for the next boot
QJsonObject BEADM::activateBE(QJsonObject jsin) {
QJsonObject BEADM::activateBE(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
@@ -109,7 +109,7 @@ QJsonObject BEADM::activateBE(QJsonObject jsin) {
// createbe (optional flag -e for cloning from an inactive BE) : Create a new Boot environment
QJsonObject BEADM::createBE(QJsonObject jsin) {
QJsonObject BEADM::createBE(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
@@ -146,7 +146,7 @@ QJsonObject BEADM::createBE(QJsonObject jsin) {
// Destroy the given boot environment and unmount it immediately withour confirmation
QJsonObject BEADM::destroyBE(QJsonObject jsin) {
QJsonObject BEADM::destroyBE(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
@@ -172,4 +172,40 @@ QJsonObject BEADM::destroyBE(QJsonObject jsin) {
retObject.insert("target", target);
return retObject;
}
}
// Mount a boot environment in a temporary directory / Also give the option to specifically tell it where to mount the BE
QJsonObject BEADM::mountBE(QJsonObject jsin) {
QJsonObject retObject;
QStringList keys = jsin.keys();
if (! keys.contains("be") ) {
retObject.insert("error", "Missing required key(s) 'be'");
return retObject;
}
// Get the key values
QString be = jsin.value("be").toString();
QString mountpoint;
if (keys.contains("mountpoint") ) {
mountpoint = jsin.value("mountpoint").toString();
}
QStringList output = General::RunCommand("beadm mount "+ be + " " + mountpoint).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;
}
if ( output.at(i).indexOf("Mounted successfully")) {
retObject.insert("mountpoint", output.at(i).section("'",1,1));
}
}
retObject.insert("be", be);
return retObject;
}

View File

@@ -19,6 +19,7 @@ public:
static QJsonObject activateBE(QJsonObject);
static QJsonObject createBE(QJsonObject);
static QJsonObject destroyBE(QJsonObject);
static QJsonObject mountBE(QJsonObject);
};
} //end of pcbsd namespace