Signed-off-by: Filip Schauer <[email protected]>
---
www/manager6/lxc/MPEdit.js | 203 +++++++++++++++++++++++++++++++++++++
1 file changed, 203 insertions(+)
diff --git a/www/manager6/lxc/MPEdit.js b/www/manager6/lxc/MPEdit.js
index 4ed2d07b..b07f8882 100644
--- a/www/manager6/lxc/MPEdit.js
+++ b/www/manager6/lxc/MPEdit.js
@@ -48,6 +48,7 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
setMPOpt('acl', values.acl);
setMPOpt('replicate', values.replicate);
setMPOpt('keepattrs', values.keepattrs);
+ setMPOpt('idmap', values.idmap);
let res = {};
res[confid] = PVE.Parser.printLxcMountPoint(me.mp);
@@ -132,6 +133,12 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
me.getViewModel().set('type', rec.data.type);
},
},
+ 'grid proxmoxintegerfield': {
+ change: 'idmapChanged',
+ },
+ 'field[name=idmap]': {
+ change: 'setGridData',
+ },
},
init: function (view) {
let _me = this;
@@ -154,6 +161,90 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
view.setVMConfig(view.vmconfig);
}
},
+ idmapChanged: function (field, value) {
+ let me = this;
+ if (value === null) {
+ return;
+ }
+ let record = field.getWidgetRecord();
+ if (record === undefined) {
+ return;
+ }
+ let col = field.getWidgetColumn();
+ record.set(col.dataIndex, value);
+ record.commit();
+
+ me.updateIDMapField();
+ },
+ idmapTypeChanged: function (button, newValue) {
+ let me = this;
+ let record = button.getWidgetRecord();
+ if (record === undefined || record.get('type') === newValue) {
+ return;
+ }
+ record.set('type', newValue);
+ record.commit();
+ me.updateIDMapField();
+ },
+ addIDMap: function () {
+ let me = this;
+ me.lookup('idmaps').getStore().add({
+ type: 'u',
+ ct: '',
+ host: '',
+ length: '',
+ });
+
+ me.updateIDMapField();
+ },
+ removeIDMap: function (field) {
+ let me = this;
+ let record = field.getWidgetRecord();
+ if (record === undefined) {
+ return;
+ }
+
+ me.lookup('idmaps').getStore().remove(record);
+ me.updateIDMapField();
+ },
+ updateIDMapField: function () {
+ let me = this;
+
+ let idmaps = [];
+ me.lookup('idmaps')
+ .getStore()
+ .each((rec) => {
+ let { type, ct, host, length } = rec.data;
+ idmaps.push(`${type}:${ct}:${host}:${length}`);
+ });
+
+ let field = me.lookup('idmap');
+ field.suspendEvent('change');
+ field.setValue(idmaps.join(' '));
+ field.resumeEvent('change');
+ },
+ parseIDMap: function (idmap) {
+ let [type, ct, host, length] = idmap.split(':');
+
+ let record = {
+ type,
+ ct,
+ host,
+ length,
+ };
+
+ return record;
+ },
+ setGridData: function (field, value) {
+ let me = this;
+ if (!value) {
+ return;
+ }
+
+ value = value.split(' ');
+ let records = value.map((idmap) => me.parseIDMap(idmap));
+ me.lookup('idmaps').getStore().setData(records);
+ },
},
viewModel: {
@@ -354,6 +445,118 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
},
},
],
+
+ advancedColumnB: [
+ {
+ xtype: 'displayfield',
+ fieldLabel: gettext('ID Mapping'),
+ },
+ {
+ xtype: 'fieldcontainer',
+ items: [
+ {
+ xtype: 'grid',
+ height: 200,
+ scrollable: true,
+ reference: 'idmaps',
+ viewConfig: {
+ emptyText: gettext('No ID maps configured'),
+ },
+ store: {
+ fields: ['type', 'ct', 'host', 'length'],
+ data: [],
+ },
+ columns: [
+ {
+ text: gettext('ID Type'),
+ xtype: 'widgetcolumn',
+ dataIndex: 'type',
+ widget: {
+ xtype: 'segmentedbutton',
+ items: [
+ {
+ text: 'UID',
+ value: 'u',
+ },
+ {
+ text: 'GID',
+ value: 'g',
+ },
+ ],
+ listeners: {
+ change: 'idmapTypeChanged',
+ },
+ },
+ flex: 1,
+ },
+ {
+ text: gettext('Container'),
+ xtype: 'widgetcolumn',
+ dataIndex: 'ct',
+ widget: {
+ xtype: 'proxmoxintegerfield',
+ margin: '4 0',
+ emptyText: gettext('Container'),
+ isFormField: false,
+ allowBlank: false,
+ minValue: 0,
+ },
+ flex: 1,
+ },
+ {
+ text: gettext('Host'),
+ xtype: 'widgetcolumn',
+ dataIndex: 'host',
+ widget: {
+ xtype: 'proxmoxintegerfield',
+ margin: '4 0',
+ emptyText: gettext('Host'),
+ isFormField: false,
+ allowBlank: false,
+ minValue: 0,
+ },
+ flex: 1,
+ },
+ {
+ text: gettext('Length'),
+ xtype: 'widgetcolumn',
+ dataIndex: 'length',
+ widget: {
+ xtype: 'proxmoxintegerfield',
+ margin: '4 0',
+ emptyText: gettext('Length'),
+ isFormField: false,
+ allowBlank: false,
+ minValue: 1,
+ },
+ flex: 1,
+ },
+ {
+ xtype: 'widgetcolumn',
+ width: 40,
+ widget: {
+ xtype: 'button',
+ margin: '4 0',
+ iconCls: 'fa fa-trash-o',
+ handler: 'removeIDMap',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ {
+ xtype: 'button',
+ text: gettext('Add'),
+ iconCls: 'fa fa-plus-circle',
+ handler: 'addIDMap',
+ },
+ {
+ xtype: 'hidden',
+ reference: 'idmap',
+ name: 'idmap',
+ },
+ ],
});
Ext.define('PVE.lxc.MountPointEdit', {
--
2.47.3