From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 04AD19A9E1
 for <pve-devel@lists.proxmox.com>; Fri, 17 Nov 2023 16:04:15 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id DBE9435BED
 for <pve-devel@lists.proxmox.com>; Fri, 17 Nov 2023 16:03:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Fri, 17 Nov 2023 16:03:44 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F412F43EB9
 for <pve-devel@lists.proxmox.com>; Fri, 17 Nov 2023 16:03:43 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 17 Nov 2023 16:03:43 +0100
Message-Id: <20231117150343.2099607-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20231117150343.2099607-1-d.csapak@proxmox.com>
References: <20231117150343.2099607-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.017 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pve-devel] [PATCH manager 2/2] ui: vm wizard: allow second iso for
 windows vms
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 17 Nov 2023 15:04:15 -0000

This is useful for adding the virtio-win iso for new installs, and thus
we change the default disk type to scsi and network type to virtio.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
there is still a bug (can look into it monday) where when the the
checkbox is unselected again, the default disk is ide1 instead of ide0
(which won't work because q35 only knows ide0 and ide2)
it seems to be a timing issue of when the vmconfig for the disk panel is
updated and how we generate the baseconfig

 www/manager6/qemu/CreateWizard.js |  3 ++
 www/manager6/qemu/MultiHDEdit.js  |  8 +++-
 www/manager6/qemu/OSTypeEdit.js   | 64 ++++++++++++++++++++++++++++++-
 3 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/www/manager6/qemu/CreateWizard.js b/www/manager6/qemu/CreateWizard.js
index 74b1feb6..443e42c6 100644
--- a/www/manager6/qemu/CreateWizard.js
+++ b/www/manager6/qemu/CreateWizard.js
@@ -161,6 +161,9 @@ Ext.define('PVE.qemu.CreateWizard', {
 		{
 		    xtype: 'pveQemuOSTypePanel',
 		    insideWizard: true,
+		    bind: {
+			nodename: '{nodename}',
+		    },
 		},
 	    ],
 	},
diff --git a/www/manager6/qemu/MultiHDEdit.js b/www/manager6/qemu/MultiHDEdit.js
index caf74fad..27884f3f 100644
--- a/www/manager6/qemu/MultiHDEdit.js
+++ b/www/manager6/qemu/MultiHDEdit.js
@@ -37,11 +37,17 @@ Ext.define('PVE.qemu.MultiHDPanel', {
 	    let me = this;
 	    let vm = me.getViewModel();
 
-	    return {
+	    let res = {
 		ide2: 'media=cdrom',
 		scsihw: vm.get('current.scsihw'),
 		ostype: vm.get('current.ostype'),
 	    };
+
+	    if (vm.get('current.ide0') === "some") {
+		res.ide0 = "media=cdrom";
+	    }
+
+	    return res;
 	},
 
 	diskSorter: {
diff --git a/www/manager6/qemu/OSTypeEdit.js b/www/manager6/qemu/OSTypeEdit.js
index 3332a0bc..b3c8fda8 100644
--- a/www/manager6/qemu/OSTypeEdit.js
+++ b/www/manager6/qemu/OSTypeEdit.js
@@ -14,9 +14,19 @@ Ext.define('PVE.qemu.OSTypeInputPanel', {
 		afterrender: 'onOSTypeChange',
 		change: 'onOSTypeChange',
 	    },
+	    'checkbox[reference=enableSecondCD]': {
+		change: 'onSecondCDChange',
+	    },
 	},
 	onOSBaseChange: function(field, value) {
-	    this.lookup('ostype').getStore().setData(PVE.Utils.kvm_ostypes[value]);
+	    let me = this;
+	    me.lookup('ostype').getStore().setData(PVE.Utils.kvm_ostypes[value]);
+	    let isWindows = value === 'Microsoft Windows';
+	    let enableSecondCD = me.lookup('enableSecondCD');
+	    enableSecondCD.setVisible(isWindows);
+	    if (!isWindows) {
+		enableSecondCD.setValue(false);
+	    }
 	},
 	onOSTypeChange: function(field) {
 	    var me = this, ostype = field.getValue();
@@ -42,6 +52,30 @@ Ext.define('PVE.qemu.OSTypeInputPanel', {
 		// ignore multiple disks, we only want to set the type if there is a single disk
 	    }
 	},
+	onSecondCDChange: function(widget, value, lastValue) {
+	    let me = this;
+	    let vm = me.getViewModel();
+	    if (value) {
+		// only for windows
+		vm.set('current.ide0', "some");
+		vm.notify();
+		me.setWidget('pveBusSelector', 'scsi');
+		me.setWidget('pveNetworkCardSelector', 'virtio');
+	    } else {
+		vm.set('current.ide0', "");
+		vm.notify();
+		console.log('set ide0 to 0');
+		me.setWidget('pveBusSelector', 'scsi');
+		let ostype = me.lookup('ostype').getValue();
+		var targetValues = PVE.qemu.OSDefaults.getDefaults(ostype);
+		me.setWidget('pveBusSelector', targetValues.busType);
+	    }
+	},
+    },
+
+    setNodename: function(nodename) {
+	var me = this;
+	me.lookup('isoSelector').setNodename(nodename);
     },
 
     initComponent: function() {
@@ -92,6 +126,34 @@ Ext.define('PVE.qemu.OSTypeInputPanel', {
 	    },
 	];
 
+	if (me.insideWizard) {
+	    me.items.push(
+		{
+		    xtype: 'proxmoxcheckbox',
+		    reference: 'enableSecondCD',
+		    isFormField: false,
+		    hidden: true,
+		    checked: false,
+		    boxLabel: gettext('Add Second CD/DVD Image file (iso)'),
+		    listeners: {
+			change: function(cb, value) {
+			    me.lookup('isoSelector').setDisabled(!value);
+			    me.lookup('isoSelector').setHidden(!value);
+			},
+		    },
+		},
+		{
+		    xtype: 'pveIsoSelector',
+		    reference: 'isoSelector',
+		    name: 'ide0',
+		    nodename: me.nodename,
+		    insideWizard: true,
+		    hidden: true,
+		    disabled: true,
+		},
+	    );
+	}
+
 	me.callParent();
     },
 });
-- 
2.30.2