public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] ui: guest import: allow setting mac addresses to unique
Date: Tue, 26 Mar 2024 14:25:56 +0100	[thread overview]
Message-ID: <20240326132556.4050167-1-a.lauterer@proxmox.com> (raw)

by adding a new checkbox and render the grid accordingly.

If unique MAC addresses are enabled, set them to undefined when getting
the values from the grid.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
not sure if setting `uniqueMac` directly on the component is okay.
Though we do that dynamically for the `vmConfig` as well. So probably
okayish.

 www/manager6/window/GuestImport.js | 39 +++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/www/manager6/window/GuestImport.js b/www/manager6/window/GuestImport.js
index ae9bac5b..aee54706 100644
--- a/www/manager6/window/GuestImport.js
+++ b/www/manager6/window/GuestImport.js
@@ -15,6 +15,8 @@ Ext.define('PVE.window.GuestImport', {
     showTaskViewer: true,
     method: 'POST',
 
+    uniqueMac: false,
+
     loadUrl: function(_url, { storage, nodename, volumeName }) {
 	let args = Ext.Object.toQueryString({ volume: volumeName });
 	return `/nodes/${nodename}/storage/${storage}/import-metadata?${args}`;
@@ -187,6 +189,7 @@ Ext.define('PVE.window.GuestImport', {
 	refreshGrids: function() {
 	    this.lookup('diskGrid').reconfigure();
 	    this.lookup('cdGrid').reconfigure();
+	    this.lookup('netGrid').reconfigure();
 	},
 
 	onOSTypeChange: function(_cb, value) {
@@ -226,6 +229,21 @@ Ext.define('PVE.window.GuestImport', {
 	    me.getView().vmConfig.scsihw = value;
 	},
 
+	onUniqueMacChange: function(_cb, value) {
+	    let me = this;
+	    me.getView().uniqueMac = value;
+
+	    me.refreshGrids();
+	},
+
+	renderMacAddress: function(value, metaData, record, rowIndex, colIndex, store, view) {
+	    let me = this;
+	    if (me.getView().uniqueMac) {
+		return 'auto';
+	    }
+	    return value ? value : 'auto';
+	},
+
 	control: {
 	    'grid field': {
 		// update records from widgetcolumns
@@ -256,6 +274,9 @@ Ext.define('PVE.window.GuestImport', {
 	    'pveScsiHwSelector': {
 		change: 'onScsiHwChange',
 	    },
+	    'proxmoxcheckbox[reference=uniqueMac]': {
+		change: 'onUniqueMacChange',
+	    },
 	},
     },
 
@@ -364,6 +385,9 @@ Ext.define('PVE.window.GuestImport', {
 			    if (!data.bridge) {
 				data.bridge = defaultBridge;
 			    }
+			    if (grid.uniqueMac) {
+				data.macaddr = undefined;
+			    }
 			    config[id] = PVE.Parser.printQemuNetwork(data);
 			});
 
@@ -778,7 +802,7 @@ Ext.define('PVE.window.GuestImport', {
 				    text: gettext('MAC address'),
 				    flex: 1,
 				    dataIndex: 'macaddr',
-				    renderer: value => value ?? 'auto',
+				    renderer: 'renderMacAddress',
 				},
 				{
 				    text: gettext('Model'),
@@ -809,6 +833,19 @@ Ext.define('PVE.window.GuestImport', {
 				},
 			    ],
 			},
+			{
+			    xtype: 'proxmoxcheckbox',
+			    name: 'uniqueMACs',
+			    reference: 'uniqueMac',
+			    labelWidth: 200,
+			    fieldLabel: gettext('Unique MAC addresses'),
+			    uncheckedValue: false,
+			    checked: false,
+			    autoEl: {
+				tag: 'div',
+				'data-qtip': gettext('Generate new unique MAC addresses.'),
+			    },
+			},
 		    ],
 		},
 		{
-- 
2.39.2





             reply	other threads:[~2024-03-26 13:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 13:25 Aaron Lauterer [this message]
2024-03-27 10:26 ` [pve-devel] applied: " Thomas Lamprecht
2024-03-27 10:32   ` Aaron Lauterer
2024-03-27 10:33     ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240326132556.4050167-1-a.lauterer@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal