public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v3 5/6] ui: vm: make cloudinit drive editable
Date: Wed, 23 Oct 2024 14:37:21 +0200	[thread overview]
Message-ID: <20241023123722.124478-6-d.kral@proxmox.com> (raw)
In-Reply-To: <20241023123722.124478-1-d.kral@proxmox.com>

Implements the functionality to allow changes to the CloudInit drive
under the VM "Hardware" tab after it has already been created by the
user.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 www/manager6/qemu/CIDriveEdit.js  | 63 +++++++++++++++++++++++++------
 www/manager6/qemu/HardwareView.js |  4 +-
 2 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/www/manager6/qemu/CIDriveEdit.js b/www/manager6/qemu/CIDriveEdit.js
index 006f9565..d12124e8 100644
--- a/www/manager6/qemu/CIDriveEdit.js
+++ b/www/manager6/qemu/CIDriveEdit.js
@@ -9,14 +9,16 @@ Ext.define('PVE.qemu.CIDriveInputPanel', {
     onGetValues: function(values) {
 	let me = this;
 
-	let drive = {};
 	let params = {};
-	let confid = values.controller + values.deviceid;
+	let confid = me.confid || values.controller + values.deviceid;
 
-	drive.file = values.hdstorage + ":cloudinit";
-	drive.format = values.diskformat;
+	// only set these when we create cloudinit files
+	if (me.isCreate) {
+	    me.drive.file = values.hdstorage + ":cloudinit";
+	    me.drive.format = values.diskformat;
+	}
 
-	params[confid] = PVE.Parser.printQemuDrive(drive);
+	params[confid] = PVE.Parser.printQemuDrive(me.drive);
 
 	return params;
     },
@@ -31,7 +33,25 @@ Ext.define('PVE.qemu.CIDriveInputPanel', {
     setVMConfig: function(config) {
 	let me = this;
 
-	me.busSelector.setVMConfig(config, 'cdrom');
+	if (me.busSelector) {
+	    me.busSelector.setVMConfig(config, 'cdrom');
+	}
+    },
+
+    setDrive: function(drive) {
+	let me = this;
+
+	let values = {};
+
+	let match = drive.file.match(/^([^:]+):/);
+	if (match) {
+	    values.hdstorage = match[1];
+	}
+	values.hdimage = drive.file;
+
+	me.drive = drive;
+
+	me.setValues(values);
     },
 
     initComponent: function() {
@@ -41,10 +61,12 @@ Ext.define('PVE.qemu.CIDriveInputPanel', {
 
 	let items = [];
 
-	me.busSelector = Ext.create('PVE.form.ControllerSelector', {
-	    withVirtIO: false,
-	    fieldLabel: gettext('CloudInit Drive'),
-	});
+	if (me.isCreate) {
+	    me.busSelector = Ext.create('PVE.form.ControllerSelector', {
+		withVirtIO: false,
+		fieldLabel: gettext('CloudInit Drive'),
+	    });
+	}
 
 	items.push(me.busSelector);
 	items.push({
@@ -52,6 +74,8 @@ Ext.define('PVE.qemu.CIDriveInputPanel', {
 	    itemId: 'storselector',
 	    storageContent: 'images',
 	    nodename: me.nodename,
+	    disabled: !me.isCreate,
+	    hideFormat: !me.isCreate,
 	    hideSize: true,
 	});
 
@@ -65,8 +89,6 @@ Ext.define('PVE.qemu.CIDriveEdit', {
     extend: 'Proxmox.window.Edit',
     xtype: 'pveCIDriveEdit',
 
-    isCreate: true,
-
     initComponent: function() {
 	let me = this;
 
@@ -75,8 +97,12 @@ Ext.define('PVE.qemu.CIDriveEdit', {
 	    throw "no node name specified";
 	}
 
+	me.isCreate = !me.confid;
+
 	let ipanel = Ext.create('PVE.qemu.CIDriveInputPanel', {
+	    confid: me.confid,
 	    nodename: nodename,
+	    isCreate: me.isCreate,
 	});
 
 	Ext.applyIf(me, {
@@ -89,6 +115,19 @@ Ext.define('PVE.qemu.CIDriveEdit', {
 	me.load({
 	    success: function(response, opts) {
 		ipanel.setVMConfig(response.result.data);
+
+		if (me.confid) {
+		    let value = response.result.data[me.confid];
+		    let drive = PVE.Parser.parseQemuDrive(me.confid, value);
+
+		    if (!drive) {
+			Ext.Msg.alert('Error', 'Unable to parse drive options');
+			me.close();
+			return;
+		    }
+
+		    ipanel.setDrive(drive);
+		}
 	    },
 	});
     },
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 86d5f4cf..c7a77bd9 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -350,7 +350,7 @@ Ext.define('PVE.qemu.HardwareView', {
 	    if (rowdef.isOnStorageBus) {
 		let value = me.getObjectValue(rec.data.key, '', true);
 		if (isCloudInitKey(value)) {
-		    return;
+		    editor = 'PVE.qemu.CIDriveEdit';
 		} else if (value.match(/media=cdrom/)) {
 		    editor = 'PVE.qemu.CDEdit';
 		} else if (!diskCap) {
@@ -629,7 +629,7 @@ Ext.define('PVE.qemu.HardwareView', {
 	    remove_btn.RESTMethod = isUnusedDisk || (isDisk && isRunning) ? 'POST' : 'PUT';
 
 	    edit_btn.setDisabled(
-	        deleted || !row.editor || isCloudInit || (isCDRom && !cdromCap) || (isDisk && !diskCap));
+	        deleted || !row.editor || (isCDRom && !cdromCap) || (isDisk && !diskCap));
 
 	    diskaction_btn.setDisabled(
 		pending ||
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2024-10-23 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-23 12:37 [pve-devel] [PATCH manager v3 0/6] fix #5430: ocfs2 io_uring read write Daniel Kral
2024-10-23 12:37 ` [pve-devel] [PATCH manager v3 1/6] ui: vm: change var to let in CDROM and CloudInit edit modals Daniel Kral
2024-10-23 12:37 ` [pve-devel] [PATCH manager v3 2/6] ui: vm: improve code readability of " Daniel Kral
2024-10-23 12:37 ` [pve-devel] [PATCH manager v3 3/6] ui: vm: factor out async I/O type selector Daniel Kral
2024-10-23 12:37 ` [pve-devel] [PATCH manager v3 4/6] fix #5430: ui: vm: allow editing cdrom aio and cache options Daniel Kral
2024-10-23 12:37 ` Daniel Kral [this message]
2024-10-23 12:37 ` [pve-devel] [PATCH manager v3 6/6] fix #5430: ui: vm: allow editing cloudinit " Daniel Kral

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=20241023123722.124478-6-d.kral@proxmox.com \
    --to=d.kral@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