diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 6e9f09d..60f0a39 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -66,7 +66,11 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO if(QFile::exists("/usr/local/sbin/iohyve")){ out->insert("sysadm/iohyve", "read/write"); } - + + if(QFile::exists("/sbin/zfs") && QFile::exists("/sbin/zpool")){ + out->insert("sysadm/zfs", allaccess ? "read/write" : "read"); + } + // - Generic system information out->insert("sysadm/systemmanager","read/write"); @@ -117,6 +121,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru return EvaluateSysadmSystemMgmtRequest(IN.args, out); }else if(namesp=="sysadm" && name=="update"){ return EvaluateSysadmUpdateRequest(IN.args, out); + }else if(namesp=="sysadm" && name=="zfs"){ + return EvaluateSysadmZfsRequest(IN.args, out); }else{ return RestOutputStruct::BADREQUEST; } @@ -628,3 +634,37 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal } return RestOutputStruct::OK; } + +// ==== SYSADM ZFS API ==== +RestOutputStruct::ExitCode WebSocket::EvaluateSysadmZfsRequest(const QJsonValue in_args, QJsonObject *out){ + if(!in_args.isObject() || !in_args.toObject().contains("action") ){ return RestOutputStruct::BADREQUEST; } + QString act = in_args.toObject().value("action").toString(); + if(act=="list_pools"){ + bool ok = false; + QStringList info = sysadm::General::RunCommand(ok, "zpool list").split("\n"); + if(ok && info.length()>1){ //first line is headers + //Line Format (3/2/16): Name/Size/Alloc/Free/Expandsz/Frag/Cap/Dedup/Health/Altroot + for(int i=1; iinsert(name,obj); + } + } + }else{ + //unknown action + return RestOutputStruct::BADREQUEST; + } + + return RestOutputStruct::OK; +} \ No newline at end of file diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index 4b02952..a2adef6 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -65,6 +65,8 @@ private: RestOutputStruct::ExitCode EvaluateSysadmSystemMgmtRequest(const QJsonValue in_args, QJsonObject *out); // -- sysadm Update API RestOutputStruct::ExitCode EvaluateSysadmUpdateRequest(const QJsonValue in_args, QJsonObject *out); + // -- sysadm ZFS API + RestOutputStruct::ExitCode EvaluateSysadmZfsRequest(const QJsonValue in_args, QJsonObject *out); private slots: void checkIdle(); //see if the currently-connected client is idle