[pve-devel] [PATCH manager 6/6] ui: ProcessorEdit: allow modifications with inaccessible CPU model

Stefan Reiter s.reiter at proxmox.com
Wed Apr 22 15:39:10 CEST 2020


An administrator can set a custom CPU model for a VM where the general user
does not have permission to use this particular model. Prior to this change
the ProcessorEdit component would be broken by this, since the store of the
CPU type selector did not contain the configured CPU model.

Add it in manually if this situation occurs (with 'Unknown' vendor, since
we cannot retrieve it from the API), but warn the user that changing it
would be an irreversible action.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 www/manager6/qemu/ProcessorEdit.js | 43 ++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/www/manager6/qemu/ProcessorEdit.js b/www/manager6/qemu/ProcessorEdit.js
index d555b2d8..0eba746c 100644
--- a/www/manager6/qemu/ProcessorEdit.js
+++ b/www/manager6/qemu/ProcessorEdit.js
@@ -9,6 +9,7 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	data: {
 	    socketCount: 1,
 	    coreCount: 1,
+	    showCustomModelPermWarning: false,
 	},
 	formulas: {
 	    totalCoreCount: get => get('socketCount') * get('coreCount'),
@@ -73,6 +74,27 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	let totalCoreDisplay = me.lookupReference('totalcores');
 	totalCoreDisplay.originalValue = values.cores * values.sockets;
 
+	let type = values.cputype;
+	let typeSelector = me.lookupReference('cputype');
+	let typeStore = typeSelector.getStore();
+	typeStore.on('load', (store, records, success) => {
+	    if (!success || !type || records.some(x => x.data.name === type)) {
+		return;
+	    }
+
+	    // if we get here, a custom CPU model is selected for the VM but we
+	    // don't have permission to configure it - it will not be in the
+	    // list retrieved from the API, so add it manually to allow changing
+	    // other processor options
+	    typeStore.add({
+		name: type,
+		displayname: type.replace(/custom-/, ''),
+		custom: 1,
+		vendor: gettext("Unknown"),
+	    });
+	    typeSelector.select(type);
+	});
+
 	me.callParent([values]);
     },
 
@@ -109,6 +131,7 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	{
 	    xtype: 'CPUModelSelector',
 	    name: 'cputype',
+	    reference: 'cputype',
 	    fieldLabel: gettext('Type')
 	},
 	{
@@ -122,6 +145,18 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	},
     ],
 
+    columnB: [
+	{
+	    xtype: 'displayfield',
+	    userCls: 'pmx-hint',
+	    value: gettext('WARNING: You do not have permission to configure custom CPU types, if you change the type you will not be able to go back!'),
+	    hidden: true,
+	    bind: {
+		hidden: '{!showCustomModelPermWarning}',
+	    },
+	},
+    ],
+
     advancedColumn1: [
 	{
 	    xtype: 'proxmoxintegerfield',
@@ -209,6 +244,14 @@ Ext.define('PVE.qemu.ProcessorEdit', {
 		    if (cpu.flags) {
 			data.flags = cpu.flags;
 		    }
+
+		    let caps = Ext.state.Manager.get('GuiCap');
+		    if (data.cputype.indexOf('custom-') === 0 &&
+			!caps.nodes['Sys.Audit'])
+		    {
+			let vm = ipanel.getViewModel();
+			vm.set("showCustomModelPermWarning", true);
+		    }
 		}
 		me.setValues(data);
 	    }
-- 
2.26.2





More information about the pve-devel mailing list