]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: lxc: add edit window for device passthrough
authorFilip Schauer <f.schauer@proxmox.com>
Wed, 17 Apr 2024 08:44:19 +0000 (10:44 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 17 Apr 2024 08:51:21 +0000 (10:51 +0200)
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
www/manager6/Makefile
www/manager6/Utils.js
www/manager6/lxc/DeviceEdit.js [new file with mode: 0644]
www/manager6/lxc/Resources.js

index c756cae6dc85b16dba1a218a43b61e2ed223ce5d..5e16f2a57d733960b5a06ef589fbcc9de09e98e8 100644 (file)
@@ -188,6 +188,7 @@ JSSRC=                                                      \
        lxc/CmdMenu.js                                  \
        lxc/Config.js                                   \
        lxc/CreateWizard.js                             \
+       lxc/DeviceEdit.js                               \
        lxc/DNS.js                                      \
        lxc/FeaturesEdit.js                             \
        lxc/MPEdit.js                                   \
index 8205598af1d60af66819c52098f5ffc1c9b6ffd6..2c3c56caab4dbd7c04e60d046eb80b8922a1014e 100644 (file)
@@ -1615,6 +1615,17 @@ Ext.define('PVE.Utils', {
        }
     },
 
+    lxc_dev_count: 256,
+
+    forEachLxcDev: function(func) {
+       for (let i = 0; i < PVE.Utils.lxc_dev_count; i++) {
+           let cont = func(i);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
+    },
+
     hardware_counts: {
        net: 32,
        usb: 14,
diff --git a/www/manager6/lxc/DeviceEdit.js b/www/manager6/lxc/DeviceEdit.js
new file mode 100644 (file)
index 0000000..845c452
--- /dev/null
@@ -0,0 +1,176 @@
+Ext.define('PVE.lxc.DeviceInputPanel', {
+    extend: 'Proxmox.panel.InputPanel',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    autoComplete: false,
+
+    controller: {
+       xclass: 'Ext.app.ViewController',
+    },
+
+    setVMConfig: function(vmconfig) {
+       let me = this;
+       me.vmconfig = vmconfig;
+
+       if (me.isCreate) {
+           PVE.Utils.forEachLxcDev((i) => {
+               let name = "dev" + i.toString();
+               if (!Ext.isDefined(vmconfig[name])) {
+                   me.confid = name;
+                   me.down('field[name=devid]').setValue(i);
+                   return false;
+               }
+               return undefined;
+           });
+       }
+    },
+
+    onGetValues: function(values) {
+       let me = this;
+       let confid = me.isCreate ? "dev" + values.devid : me.confid;
+       delete values.devid;
+       let val = PVE.Parser.printPropertyString(values, 'path');
+       let ret = {};
+       ret[confid] = val;
+       return ret;
+    },
+
+    items: [
+       {
+           xtype: 'proxmoxintegerfield',
+           name: 'devid',
+           fieldLabel: gettext('Passthrough ID'),
+           minValue: 0,
+           maxValue: PVE.Utils.dev_count - 1,
+           hidden: true,
+           allowBlank: false,
+           disabled: true,
+           labelAlign: 'right',
+           cbind: {
+               hidden: '{!isCreate}',
+               disabled: '{!isCreate}',
+           },
+           validator: function(value) {
+               let view = this.up('inputpanel');
+               if (!view.vmconfig) {
+                   return undefined;
+               }
+               if (Ext.isDefined(view.vmconfig["dev" + value])) {
+                   return "Device passthrough is already in use.";
+               }
+               return true;
+           },
+       },
+       {
+           xtype: 'textfield',
+           type: 'device',
+           name: 'path',
+           editable: true,
+           allowBlank: false,
+           fieldLabel: gettext('Device Path'),
+           emptyText: '/dev/xyz',
+           labelAlign: 'right',
+           validator: function(value) {
+               if (value.startsWith('/dev/')) {
+                   return true;
+               }
+
+               return "Path has to start with /dev/";
+           },
+       },
+    ],
+
+    advancedColumn1: [
+       {
+           xtype: 'proxmoxintegerfield',
+           name: 'uid',
+           editable: true,
+           fieldLabel: 'UID',
+           emptyText: '0',
+           minValue: 0,
+           labelAlign: 'right',
+       },
+       {
+           xtype: 'proxmoxintegerfield',
+           name: 'gid',
+           editable: true,
+           fieldLabel: 'GID',
+           emptyText: '0',
+           minValue: 0,
+           labelAlign: 'right',
+       },
+    ],
+
+    advancedColumn2: [
+       {
+           xtype: 'textfield',
+           name: 'mode',
+           editable: true,
+           fieldLabel: gettext('Access Mode'),
+           emptyText: '0660',
+           labelAlign: 'right',
+           validator: function(value) {
+               if (/^0[0-7]{3}$|^$/i.test(value)) {
+                   return true;
+               }
+
+               return "Access mode has to be an octal number";
+           },
+       },
+    ],
+});
+
+Ext.define('PVE.lxc.DeviceEdit', {
+    extend: 'Proxmox.window.Edit',
+
+    vmconfig: undefined,
+
+    isAdd: true,
+    width: 400,
+
+    initComponent: function() {
+       let me = this;
+
+       me.isCreate = !me.confid;
+
+       let ipanel = Ext.create('PVE.lxc.DeviceInputPanel', {
+           confid: me.confid,
+           isCreate: me.isCreate,
+           pveSelNode: me.pveSelNode,
+       });
+
+       let subject;
+       if (me.isCreate) {
+           subject = gettext('Device');
+       } else {
+           subject = gettext('Device') + ' (' + me.confid + ')';
+       }
+
+       Ext.apply(me, {
+           subject: subject,
+           items: [ipanel],
+       });
+
+       me.callParent();
+
+       me.load({
+           success: function(response, options) {
+               ipanel.setVMConfig(response.result.data);
+               if (me.isCreate) {
+                   return;
+               }
+
+               let data = PVE.Parser.parsePropertyString(response.result.data[me.confid], 'path');
+
+               let values = {
+                   path: data.path,
+                   mode: data.mode,
+                   uid: data.uid,
+                   gid: data.gid,
+               };
+
+               ipanel.setValues(values);
+           },
+       });
+    },
+});
index 61182ef3e56121464e6ddfa91d73f0cb901979a4..8203d32bc0642e0425d4761cf5682f1c2730dc33 100644 (file)
@@ -135,6 +135,19 @@ Ext.define('PVE.lxc.RessourceView', {
            };
        }, true);
 
+       let deveditor = Proxmox.UserName === 'root@pam' ? 'PVE.lxc.DeviceEdit' : undefined;
+
+       PVE.Utils.forEachLxcDev(function(i) {
+           confid = 'dev' + i;
+           rows[confid] = {
+               group: 7,
+               order: i,
+               tdCls: 'pve-itype-icon-pci',
+               editor: deveditor,
+               header: gettext('Device') + ' (' + confid + ')',
+           };
+       });
+
        var baseurl = 'nodes/' + nodename + '/lxc/' + vmid + '/config';
 
        me.selModel = Ext.create('Ext.selection.RowModel', {});
@@ -311,6 +324,7 @@ Ext.define('PVE.lxc.RessourceView', {
            let isDisk = isRootFS || key.match(/^(mp|unused)\d+/);
            let isUnusedDisk = key.match(/^unused\d+/);
            let isUsedDisk = isDisk && !isUnusedDisk;
+           let isDevice = key.match(/^dev\d+/);
 
            let noedit = isDelete || !rowdef.editor;
            if (!noedit && Proxmox.UserName !== 'root@pam' && key.match(/^mp\d+$/)) {
@@ -326,7 +340,7 @@ Ext.define('PVE.lxc.RessourceView', {
            reassign_menuitem.setDisabled(isRootFS);
            resize_menuitem.setDisabled(isUnusedDisk);
 
-           remove_btn.setDisabled(!isDisk || isRootFS || !diskCap || pending);
+           remove_btn.setDisabled(!(isDisk || isDevice) || isRootFS || !diskCap || pending);
            revert_btn.setDisabled(!pending);
 
            remove_btn.setText(isUsedDisk ? remove_btn.altText : remove_btn.defaultText);
@@ -380,6 +394,21 @@ Ext.define('PVE.lxc.RessourceView', {
                                    });
                                },
                            },
+                           {
+                               text: gettext('Device Passthrough'),
+                               iconCls: 'pve-itype-icon-pci',
+                               disabled: Proxmox.UserName !== 'root@pam',
+                               handler: function() {
+                                   Ext.create('PVE.lxc.DeviceEdit', {
+                                       autoShow: true,
+                                       url: `/api2/extjs/${baseurl}`,
+                                       pveSelNode: me.pveSelNode,
+                                       listeners: {
+                                           destroy: () => me.reload(),
+                                       },
+                                   });
+                               },
+                           },
                        ],
                    }),
                },