[pve-devel] [PATCH manager v2] gui: expose lxc features

Dominik Csapak d.csapak at proxmox.com
Thu Oct 25 13:50:54 CEST 2018


but constrain editing to root at pam
give a checkbox (for now) for nfs and cifs, but keep all manually set
ones, the code makes it easy to add a new fstype to the gui

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* remove 'Allow' from gettext
* remove mounts but add 2 checkboxes
* add functionality to add more fstypes easily in the future (if necessary)

if we find that too many checkboxes are bad, we can still change it later,
though if we have many fstypes, a combobox is not prettier or more usable
any thoughts ?

 www/manager6/Makefile            |   1 +
 www/manager6/lxc/FeaturesEdit.js | 102 +++++++++++++++++++++++++++++++++++++++
 www/manager6/lxc/Options.js      |   6 +++
 3 files changed, 109 insertions(+)
 create mode 100644 www/manager6/lxc/FeaturesEdit.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 68b5227b..cc2f7203 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -146,6 +146,7 @@ JSSRC= 				                 	\
 	lxc/Summary.js					\
 	lxc/Network.js					\
 	lxc/Resources.js				\
+	lxc/FeaturesEdit.js				\
 	lxc/Options.js					\
 	lxc/DNS.js					\
 	lxc/Config.js					\
diff --git a/www/manager6/lxc/FeaturesEdit.js b/www/manager6/lxc/FeaturesEdit.js
new file mode 100644
index 00000000..51454103
--- /dev/null
+++ b/www/manager6/lxc/FeaturesEdit.js
@@ -0,0 +1,102 @@
+Ext.define('PVE.lxc.FeaturesInputPanel', {
+    extend: 'Proxmox.panel.InputPanel',
+    xtype: 'pveLxcFeaturesInputPanel',
+
+    // used to save the mounts fstypes until sending
+    mounts: [],
+
+    // checkboxes will be autogenerated from these
+    // fstype[x] uses fstypeLabels[x] as fieldLabel
+    fstypes: ['nfs', 'cifs'],
+    fstypesLabels: ['NFS', 'CIFS'],
+
+    initComponent: function() {
+	var me = this;
+	me.items= [
+	    {
+		xtype: 'proxmoxcheckbox',
+		fieldLabel: gettext('keyctl'),
+		name: 'keyctl'
+	    },
+	    {
+		xtype: 'proxmoxcheckbox',
+		fieldLabel: gettext('Nesting'),
+		name: 'nesting'
+	    }
+	];
+
+	// autogenerate fs checkboxes
+	var i;
+	for (i = 0; i < me.fstypes.length; i++) {
+	    me.items.push({
+		xtype: 'proxmoxcheckbox',
+		name: me.fstypes[i],
+		fieldLabel: me.fstypesLabels[i]
+	    });
+	}
+
+	me.callParent();
+    },
+
+    onGetValues: function(values) {
+	console.log(values);
+	var me = this;
+	var mounts = me.mounts;
+	me.fstypes.forEach(function(fs) {
+	    if (values[fs]) {
+		mounts.push(fs);
+	    }
+	    delete values[fs];
+	});
+
+	if (mounts.length) {
+	    values.mount = mounts.join(';');
+	}
+
+	var featuresstring = PVE.Parser.printPropertyString(values, undefined);
+	if (featuresstring == '') {
+	    return { 'delete': 'features' };
+	}
+	return { features: featuresstring };
+    },
+
+    setValues: function(values) {
+	var me = this;
+
+	me.down('field[name=keyctl]').setDisabled(!values.unprivileged);
+
+	if (values.features) {
+	    var res = PVE.Parser.parsePropertyString(values.features);
+	    me.mounts = [];
+	    if (res.mount) {
+		res.mount.split(/[; ]/).forEach(function(item) {
+		    if (me.fstypes.indexOf(item) === -1) {
+			me.mounts.push(item);
+		    } else {
+			res[item] = 1;
+		    }
+	    });
+	    }
+	    this.callParent([res]);
+	}
+    }
+});
+
+Ext.define('PVE.lxc.FeaturesEdit', {
+    extend: 'Proxmox.window.Edit',
+    xtype: 'pveLxcFeaturesEdit',
+
+    subject: gettext('Features'),
+
+    items: [{
+	xtype: 'pveLxcFeaturesInputPanel'
+    }],
+
+    initComponent : function() {
+	var me = this;
+
+	me.callParent();
+
+	me.load();
+    }
+});
diff --git a/www/manager6/lxc/Options.js b/www/manager6/lxc/Options.js
index 3a9959fe..e4a8d86b 100644
--- a/www/manager6/lxc/Options.js
+++ b/www/manager6/lxc/Options.js
@@ -134,6 +134,12 @@ Ext.define('PVE.lxc.Options', {
 		header: gettext('Unprivileged container'),
 		renderer: Proxmox.Utils.format_boolean,
 		defaultValue: 0
+	    },
+	    features: {
+		header: gettext('Features'),
+		defaultValue: Proxmox.Utils.noneText,
+		editor: Proxmox.UserName === 'root at pam' ?
+		    'PVE.lxc.FeaturesEdit' : undefined
 	    }
 	};
 
-- 
2.11.0





More information about the pve-devel mailing list