public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Fabian Ebner <f.ebner@proxmox.com>
Subject: Re: [pve-devel] [PATCH v2 manager 2/3] ui: restore: allow override of some settings
Date: Sat, 23 Apr 2022 12:07:47 +0200	[thread overview]
Message-ID: <c4515f35-7be3-86cd-2001-85b5532eca02@proxmox.com> (raw)
In-Reply-To: <20220421112659.74011-13-f.ebner@proxmox.com>

On 21.04.22 13:26, Fabian Ebner wrote:
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
> 
> New in v2.
> 
> Dependency bump for qemu-server needed
> 
>  www/manager6/window/Restore.js | 77 +++++++++++++++++++++++++++++++++-
>  1 file changed, 75 insertions(+), 2 deletions(-)
> 
> diff --git a/www/manager6/window/Restore.js b/www/manager6/window/Restore.js
> index 25babf89..23c244f3 100644
> --- a/www/manager6/window/Restore.js
> +++ b/www/manager6/window/Restore.js
> @@ -21,6 +21,7 @@ Ext.define('PVE.window.Restore', {
>  
>  	    Proxmox.Utils.API2Request({
>  		url: `/nodes/${view.nodename}/vzdump/extractconfig`,
> +		waitMsgTarget: view,
>  		method: 'GET',
>  		params: {
>  		    volume: view.volid,
> @@ -38,6 +39,28 @@ Ext.define('PVE.window.Restore', {
>  				`storage/${view.nodename}/${match[3]}`,
>  			    );
>  			    storagesAvailable = storagesAvailable && currentAvailable;
> +			} else {

hmm, ok you reuse the forEach, so the every of the previous patch review may not work, but I'd 
still do some changes, see below.

> +			    match = line.match(/^([^:]+):\s*(\S+)\s*$/);

can be: 

let [_, key, value] = line.match(/^([^:]+):\s*(\S+)\s*$/) ?? [];

if (!key) {
    return;
}

...

And then this could be move out of this if and handled like:

if (key === #qmdump#map) {
     // ...
} else if (key === 'name' || 'hostname') {
     view.lookupReference('nameField').setEmptyText(value);
) else if (key === 'memory') {
   // ...
} ...

Alternatively a single else and an object to map from key to xField would be also an option, but the
switch is almost never too verbose and often, and that's probably just my opinion, slightly consufing
to parse when skimming over code quickly.

> +			    if (match) {
> +				let [_, key, value] = match;
> +				switch (key) {
> +				    case 'name':
> +				    case 'hostname':
> +					view.lookupReference('nameField').setEmptyText(value);
> +					break;
> +				    case 'memory':
> +					view.lookupReference('memoryField').setEmptyText(value);
> +					break;
> +				    case 'cores':
> +					view.lookupReference('coresField').setEmptyText(value);
> +					break;
> +				    case 'sockets':
> +					view.lookupReference('socketsField').setEmptyText(value);
> +					break;
> +				    default:
> +					break;
> +				}
> +			    }
>  			}
>  		    });
>  
> @@ -207,6 +230,49 @@ Ext.define('PVE.window.Restore', {
>  	    });
>  	}
>  
> +	items.push(
> +	    {
> +		xtype: 'displayfield',
> +		value: `${gettext('Override Settings')}:`,

I'd maybe even use a 'fieldset' widget here for grouping this nicely.

> +	    },
> +	    {
> +		xtype: 'textfield',
> +		fieldLabel: gettext('Name'),
> +		name: 'name',
> +		reference: 'nameField',
> +		allowBlank: true,
> +	    },
> +	    {
> +		xtype: 'pveMemoryField',
> +		fieldLabel: gettext('Memory'),
> +		name: 'memory',
> +		reference: 'memoryField',
> +		value: '',
> +		allowBlank: true,
> +	    },
> +	    {
> +		xtype: 'proxmoxintegerfield',
> +		fieldLabel: gettext('Cores'),
> +		name: 'cores',
> +		reference: 'coresField',
> +		minValue: 1,
> +		maxValue: 128,
> +		allowBlank: true,
> +	    },
> +	);
> +
> +	if (me.vmtype === 'qemu') {
> +	    items.push({
> +		xtype: 'proxmoxintegerfield',
> +		fieldLabel: gettext('Sockets'),
> +		name: 'sockets',
> +		reference: 'socketsField',
> +		minValue: 1,
> +		maxValue: 4,
> +		allowBlank: true,
> +	    });
> +	}
> +
>  	me.formPanel = Ext.create('Ext.form.Panel', {
>  	    bodyPadding: 10,
>  	    border: false,
> @@ -254,8 +320,15 @@ Ext.define('PVE.window.Restore', {
>  		if (values['live-restore']) { params['live-restore'] = 1; }
>  		if (values.storage) { params.storage = values.storage; }
>  
> -		if (values.bwlimit !== undefined) {
> -		    params.bwlimit = values.bwlimit;
> +		['bwlimit', 'cores', 'name', 'memory', 'sockets'].forEach(function(opt) {
> +		    if (values[opt] !== undefined && values[opt] !== null && values[opt] !== '') {

should be collapsible via:

if ((values[opt] ?? '') !== '') 

at which point we could move it into a filter combinator, like:

['bwlimit', 'cores', 'name', 'memory', 'sockets']
    .filter(opt => (values[opt] ?? '') !== '')
    .forEach(opt => param[opt] = values[opt]);

> +			params[opt] = values[opt];
> +		    }
> +		});
> +
> +		if (params.name && me.vmtype === 'lxc') {
> +		    params.hostname = params.name;
> +		    delete params.name;
>  		}
>  
>  		var url;





  reply	other threads:[~2022-04-23 10:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21 11:26 [pve-devel] [PATCH-SERIES v2 qemu/qemu-server/widget-toolkit/manager] more flexible restore Fabian Ebner
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu 1/2] vma: restore: call blk_unref for all opened block devices Fabian Ebner
2022-04-25  6:37   ` Wolfgang Bumiller
2022-04-25 16:10   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu 2/2] vma: allow partial restore Fabian Ebner
2022-04-25  6:40   ` Wolfgang Bumiller
2022-04-25 16:10   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 1/7] restore: cleanup oldconf: also clean up snapshots from kept volumes Fabian Ebner
2022-04-25 16:20   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 2/7] restore destroy volumes: remove check for absolute path Fabian Ebner
2022-04-25 16:20   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 3/7] restore deactivate volumes: never die Fabian Ebner
2022-04-23  9:18   ` Thomas Lamprecht
2022-04-25  6:45     ` Fabian Ebner
2022-04-25 16:21   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 4/7] restore: also deactivate/destroy cloud-init disk upon error Fabian Ebner
2022-04-25 16:21   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 5/7] api: create: refactor parameter check logic Fabian Ebner
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 6/7] api: create: allow overriding non-disk options during restore Fabian Ebner
2022-04-21 11:26 ` [pve-devel] [PATCH v2 qemu-server 7/7] restore: allow preserving drives " Fabian Ebner
2022-04-21 11:26 ` [pve-devel] [PATCH v2 widget-toolkit 1/1] css: add proxmox-good-row class Fabian Ebner
2022-04-23  8:32   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-21 11:26 ` [pve-devel] [PATCH v2 manager 1/3] ui: restore: disallow empty storage selection if it wouldn't work Fabian Ebner
2022-04-23  9:38   ` Thomas Lamprecht
2022-04-25  7:28     ` Fabian Ebner
2022-04-27  7:05       ` Thomas Lamprecht
2022-04-27  8:21         ` Fabian Ebner
2022-04-21 11:26 ` [pve-devel] [PATCH v2 manager 2/3] ui: restore: allow override of some settings Fabian Ebner
2022-04-23 10:07   ` Thomas Lamprecht [this message]
2022-04-21 11:26 ` [pve-devel] [PATCH v2 manager 3/3] ui: restore: allow preserving disks Fabian Ebner

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=c4515f35-7be3-86cd-2001-85b5532eca02@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=f.ebner@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