From c020663ff8fb093343c0497f926f0104cd181789 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Mon, 21 Aug 2017 10:57:01 +0300 Subject: [PATCH] storage: NFS clients --- pkg/storaged/client.js | 86 +++++++++ pkg/storaged/dialog.js | 2 + pkg/storaged/index.html | 120 +++++++++++- pkg/storaged/nfs-mounts.py | 344 ++++++++++++++++++++++++++++++++++ pkg/storaged/overview.js | 261 ++++++++++++++++++++++++++ pkg/storaged/storage.css | 26 ++- test/verify/check-storage-nfs | 168 +++++++++++++++++ test/verify/storagelib.py | 4 + tools/cockpit.spec | 2 + tools/debian/control | 2 + 10 files changed, 1011 insertions(+), 4 deletions(-) create mode 100755 pkg/storaged/nfs-mounts.py create mode 100755 test/verify/check-storage-nfs diff --git a/pkg/storaged/client.js b/pkg/storaged/client.js index fdc6e319c4a..1599c5d02e0 100644 --- a/pkg/storaged/client.js +++ b/pkg/storaged/client.js @@ -25,6 +25,9 @@ var utils = require('./utils'); + var nfs_mounts_py = require("raw!./nfs-mounts.py"); + var pyinvoke = [ "sh", "-ec", "exec $(which python3 2>/dev/null || which python) $@", "--", "-" ]; + /* STORAGED CLIENT */ @@ -404,6 +407,89 @@ return utils.compare_versions(this.manager.Version, version) < 0; }; + /* NFS mounts + */ + + function nfs_mounts() { + var self = { + entries: [ ], + + update_entry: update_entry, + add_entry: add_entry, + remove_entry: remove_entry, + + entry_users: entry_users, + + mount_entry: mount_entry, + unmount_entry: unmount_entry, + stop_and_unmount_entry: stop_and_unmount_entry, + stop_and_remove_entry: stop_and_remove_entry + }; + + function spawn_nfs_mounts(args) { + return cockpit.spawn(pyinvoke.concat(args), + { superuser: "try", err: "message" }) + .input(nfs_mounts_py); + } + + var buf = ""; + spawn_nfs_mounts([ "monitor" ]) + .stream(function (output) { + var lines; + + buf += output; + lines = buf.split("\n"); + buf = lines[lines.length-1]; + if (lines.length >= 2) { + self.entries = JSON.parse(lines[lines.length-2]); + $(self).triggerHandler('changed'); + } + }). + fail(function (error) { + if (error != "closed") { + console.warn(error); + } + }); + + function update_entry(entry, new_fields) { + return spawn_nfs_mounts([ "update", JSON.stringify(entry), JSON.stringify(new_fields) ]); + } + + function add_entry(fields) { + return spawn_nfs_mounts([ "add", JSON.stringify(fields) ]); + } + + function remove_entry(entry) { + return spawn_nfs_mounts([ "remove", JSON.stringify(entry) ]); + } + + function mount_entry(entry) { + return spawn_nfs_mounts([ "mount", JSON.stringify(entry) ]); + } + + function unmount_entry(entry) { + return spawn_nfs_mounts([ "unmount", JSON.stringify(entry) ]); + } + + function stop_and_unmount_entry(users, entry) { + var units = users.map(function (u) { return u.unit; }); + return spawn_nfs_mounts([ "stop-and-unmount", JSON.stringify(units), JSON.stringify(entry) ]); + } + + function stop_and_remove_entry(users, entry) { + var units = users.map(function (u) { return u.unit; }); + return spawn_nfs_mounts([ "stop-and-remove", JSON.stringify(units), JSON.stringify(entry) ]); + } + + function entry_users(entry) { + return spawn_nfs_mounts([ "users", JSON.stringify(entry) ]).then(JSON.parse); + } + + return self; + } + + client.nfs = nfs_mounts(); + function init_manager() { /* Storaged 2.6 and later uses the UDisks2 API names, but try the * older storaged API first as a fallback. diff --git a/pkg/storaged/dialog.js b/pkg/storaged/dialog.js index 0cf0c05b093..ca857e6cfa9 100644 --- a/pkg/storaged/dialog.js +++ b/pkg/storaged/dialog.js @@ -57,6 +57,8 @@ f.HasOptions = (f.Options.length > 0); }); + if (def.Action && def.Action.Danger) + def.Action.DangerButton = true; function empty(obj) { return !obj || obj.length == 0; } diff --git a/pkg/storaged/index.html b/pkg/storaged/index.html index d945dff7ab4..ce13054dbd1 100644 --- a/pkg/storaged/index.html +++ b/pkg/storaged/index.html @@ -271,6 +271,109 @@

The "storaged" API is not available on this system.

+ + + +