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

Stefan Reiter s.reiter at proxmox.com
Mon May 4 12:58:43 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>
---

v2:
* Anchor displayname-regex with ^

 www/manager6/qemu/ProcessorEdit.js | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/www/manager6/qemu/ProcessorEdit.js b/www/manager6/qemu/ProcessorEdit.js
index f437a82c..e65631e1 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'),
@@ -66,6 +67,33 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	return values;
     },
 
+    setValues: function(values) {
+	let me = this;
+
+	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]);
+    },
+
     cpu: {},
 
     column1: [
@@ -99,6 +127,7 @@ Ext.define('PVE.qemu.ProcessorInputPanel', {
 	{
 	    xtype: 'CPUModelSelector',
 	    name: 'cputype',
+	    reference: 'cputype',
 	    fieldLabel: gettext('Type')
 	},
 	{
@@ -112,6 +141,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',
@@ -199,6 +240,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.20.1





More information about the pve-devel mailing list