[pve-devel] [PATCH v10 manager 19/19] ui: qemu: wizard: add import from OVF functionality

Fabian Ebner f.ebner at proxmox.com
Wed Apr 6 10:04:16 CEST 2022


From: Dominic Jäger <d.jaeger at proxmox.com>

Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
[FE: Split out preparatory work, and re-use existing classes
     Show message upon successfull readovf API call
     Simplify a few things]
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 www/manager6/qemu/CreateWizard.js | 61 +++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/www/manager6/qemu/CreateWizard.js b/www/manager6/qemu/CreateWizard.js
index a785a882..d522c09b 100644
--- a/www/manager6/qemu/CreateWizard.js
+++ b/www/manager6/qemu/CreateWizard.js
@@ -22,6 +22,7 @@ Ext.define('PVE.qemu.CreateWizard', {
 	{
 	    xtype: 'inputpanel',
 	    title: gettext('General'),
+	    itemId: 'generalPanel',
 	    onlineHelp: 'qm_general_settings',
 	    column1: [
 		{
@@ -63,6 +64,63 @@ Ext.define('PVE.qemu.CreateWizard', {
 		    value: '',
 		    allowBlank: true,
 		},
+		{
+		    xtype: 'textfield',
+		    name: 'ovfTextfield',
+		    emptyText: '/path/to/manifest.ovf',
+		    fieldLabel: gettext('Import from OVF'),
+		    hidden: Proxmox.UserName !== 'root at pam',
+		},
+		{
+		    xtype: 'proxmoxButton',
+		    text: gettext('Load .ovf'),
+		    hidden: Proxmox.UserName !== 'root at pam',
+		    handler: function() {
+			const inputpanel = this.up('#generalPanel');
+			const nodename = inputpanel.down('pveNodeSelector').getValue();
+			const ovfTextfieldValue = inputpanel.down('textfield[name=ovfTextfield]').getValue();
+			const wizard = this.up('window');
+
+			Proxmox.Utils.API2Request({
+			    url: `/nodes/${nodename}/readovf`,
+			    method: 'GET',
+			    params: {
+				manifest: ovfTextfieldValue,
+			    },
+			    success: function(response) {
+				const ovfData = response.result.data;
+
+				wizard.down('textfield[name=name]').setValue(ovfData.name);
+				wizard.down('#cpuPanel').getViewModel().set('coreCount', ovfData.cores);
+				wizard.down('#memoryPanel').setMemory(ovfData.memory);
+
+				delete ovfData.cores;
+				delete ovfData.name;
+				delete ovfData.memory;
+
+				let multiDiskPanel = wizard.down('pveMultiHDPanel');
+				multiDiskPanel.removeAllDisks();
+				Object.keys(ovfData).sort().forEach(function(drive) {
+				    multiDiskPanel.addDisk(drive, { 'importPath': ovfData[drive] });
+				});
+
+				wizard.down('radiofield[inputValue=none]').setValue(true);
+				// Need to manually uncheck when not yet rendered.
+				wizard.down('radiofield[inputValue=iso]').setValue(false);
+
+				Ext.Msg.show({
+				    title: gettext('Success'),
+				    icon: Ext.Msg.INFO,
+				    msg: gettext('VM settings updated'),
+				    buttons: Ext.Msg.OK,
+				});
+			    },
+			    failure: function(response) {
+				Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+			    },
+			});
+		    },
+		},
 	    ],
 	    advancedColumn1: [
 		{
@@ -120,6 +178,7 @@ Ext.define('PVE.qemu.CreateWizard', {
 		delete values.order;
 		delete values.up;
 		delete values.down;
+		delete values.ovfTextfield;
 
 		return values;
 	    },
@@ -162,11 +221,13 @@ Ext.define('PVE.qemu.CreateWizard', {
 	},
 	{
 	    xtype: 'pveQemuProcessorPanel',
+	    itemId: 'cpuPanel',
 	    insideWizard: true,
 	    title: gettext('CPU'),
 	},
 	{
 	    xtype: 'pveQemuMemoryPanel',
+	    itemId: 'memoryPanel',
 	    insideWizard: true,
 	    title: gettext('Memory'),
 	},
-- 
2.30.2






More information about the pve-devel mailing list