[pve-devel] [PATCH] split iothrottle form

Dietmar Maurer dietmar at proxmox.com
Tue Jan 14 11:48:10 CET 2014


applied.

But I simply use a normal button instead of the split button.
Turned out to be easier to use. We can still optimize that in future.

> -----Original Message-----
> From: pve-devel-bounces at pve.proxmox.com [mailto:pve-devel-
> bounces at pve.proxmox.com] On Behalf Of Alexandre Derumier
> Sent: Montag, 23. Dezember 2013 11:27
> To: pve-devel at pve.proxmox.com
> Subject: [pve-devel] [PATCH] split iothrottle form
> 
> //fixme : enable/disable splitbutton
> 
> Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
> ---
>  www/manager/Makefile             |    1 +
>  www/manager/qemu/HDEdit.js       |  107 -------------------
>  www/manager/qemu/HDThrottle.js   |  211
> ++++++++++++++++++++++++++++++++++++++
>  www/manager/qemu/HardwareView.js |   46 ++++++++-
>  4 files changed, 254 insertions(+), 111 deletions(-)  create mode 100644
> www/manager/qemu/HDThrottle.js
> 
> diff --git a/www/manager/Makefile b/www/manager/Makefile index
> 46c8a32..bd6c338 100644
> --- a/www/manager/Makefile
> +++ b/www/manager/Makefile
> @@ -99,6 +99,7 @@ JSSRC= 				                 	\
>  	qemu/HDEdit.js					\
>  	qemu/HDResize.js				\
>  	qemu/HDMove.js					\
> +	qemu/HDThrottle.js				\
>  	qemu/DisplayEdit.js				\
>  	qemu/KeyboardEdit.js				\
>  	qemu/HardwareView.js				\
> diff --git a/www/manager/qemu/HDEdit.js b/www/manager/qemu/HDEdit.js
> index eb75e4e..a09ec66 100644
> --- a/www/manager/qemu/HDEdit.js
> +++ b/www/manager/qemu/HDEdit.js
> @@ -39,21 +39,6 @@ Ext.define('PVE.qemu.HDInputPanel', {
>  	    delete me.drive.cache;
>  	}
> 
> -	var names = ['mbps_rd', 'mbps_wr', 'iops_rd', 'iops_wr'];
> -	Ext.Array.each(names, function(name) {
> -	    if (values[name]) {
> -		me.drive[name] = values[name];
> -	    } else {
> -		delete me.drive[name];
> -	    }
> -	    var burst_name = name + '_max';
> -	    if (values[burst_name] && values[name]) {
> -		me.drive[burst_name] = values[burst_name];
> -	    } else {
> -		delete me.drive[burst_name];
> -	    }
> -	});
> -
>  	var params = {};
> 
>  	params[confid] = PVE.Parser.printQemuDrive(me.drive);
> @@ -96,14 +81,6 @@ Ext.define('PVE.qemu.HDInputPanel', {
>  	values.nobackup = (drive.backup === 'no');
>  	values.diskformat = drive.format || 'raw';
>  	values.cache = drive.cache || '';
> -	values.mbps_rd = drive.mbps_rd;
> -	values.mbps_wr = drive.mbps_wr;
> -	values.iops_rd = drive.iops_rd;
> -	values.iops_wr = drive.iops_wr;
> -	values.mbps_rd_max = drive.mbps_rd_max;
> -	values.mbps_wr_max = drive.mbps_wr_max;
> -	values.iops_rd_max = drive.iops_rd_max;
> -	values.iops_wr_max = drive.iops_wr_max;
> 
>  	me.setValues(values);
>      },
> @@ -120,7 +97,6 @@ Ext.define('PVE.qemu.HDInputPanel', {
>  	me.drive = {};
> 
>  	me.column1 = [];
> -	me.column2 = [];
> 
>  	if (!me.confid || me.unused) {
>  	    me.bussel = Ext.createWidget('PVE.form.ControllerSelector', { @@ -
> 238,89 +214,6 @@ Ext.define('PVE.qemu.HDInputPanel', {
>  	    });
>  	}
> 
> -	var width2 = 140;
> -
> -        me.mbps_rd = Ext.widget('numberfield', {
> -            name: 'mbps_rd',
> -            minValue: 1,
> -	    step: 1,
> -            fieldLabel: gettext('Read limit') + ' (MB/s)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('unlimited')
> -        });
> -        me.column2.push(me.mbps_rd);
> -
> -        me.mbps_rd_max = Ext.widget('numberfield', {
> -            name: 'mbps_rd_max',
> -            minValue: 1,
> -	    step: 1,
> -            fieldLabel: gettext('Read max burst') + ' (MB)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('default')
> -        });
> -        me.column2.push(me.mbps_rd_max);
> -
> -
> -        me.mbps_wr = Ext.widget('numberfield', {
> -            name: 'mbps_wr',
> -            minValue: 1,
> -	    step: 1,
> -            fieldLabel: gettext('Write limit') + ' (MB/s)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('unlimited')
> -        });
> -        me.column2.push(me.mbps_wr);
> -
> -        me.mbps_wr_max = Ext.widget('numberfield', {
> -            name: 'mbps_wr_max',
> -            minValue: 1,
> -	    step: 1,
> -            fieldLabel: gettext('Write max burst') + ' (MB)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('default')
> -        });
> -        me.column2.push(me.mbps_wr_max);
> -
> -        me.iops_rd = Ext.widget('numberfield', {
> -            name: 'iops_rd',
> -            minValue: 10,
> -	    step: 10,
> -            fieldLabel: gettext('Read limit') + ' (ops/s)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('unlimited')
> -        });
> -        me.column2.push(me.iops_rd);
> -
> -        me.iops_rd_max = Ext.widget('numberfield', {
> -            name: 'iops_rd_max',
> -            minValue: 10,
> -	    step: 10,
> -            fieldLabel: gettext('Read max burst') + ' (ops)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('default')
> -        });
> -        me.column2.push(me.iops_rd_max);
> -
> -        me.iops_wr = Ext.widget('numberfield', {
> -            name: 'iops_wr',
> -            minValue: 10,
> -	    step: 10,
> -            fieldLabel: gettext('Write limit') + ' (ops/s)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('unlimited')
> -        });
> -        me.column2.push(me.iops_wr);
> -
> -        me.iops_wr_max = Ext.widget('numberfield', {
> -            name: 'iops_wr_max',
> -            minValue: 10,
> -	    step: 10,
> -            fieldLabel: gettext('Write max burst') + ' (ops)',
> -	    labelWidth: width2,
> -	    emptyText: gettext('default')
> -        });
> -        me.column2.push(me.iops_wr_max);
> -
>  	me.callParent();
>      }
>  });
> diff --git a/www/manager/qemu/HDThrottle.js
> b/www/manager/qemu/HDThrottle.js new file mode 100644 index
> 0000000..8e7026c
> --- /dev/null
> +++ b/www/manager/qemu/HDThrottle.js
> @@ -0,0 +1,211 @@
> +// fixme: howto avoid jslint type confusion?
> +/*jslint confusion: true */
> +Ext.define('PVE.qemu.HDThrottleInputPanel', {
> +    extend: 'PVE.panel.InputPanel',
> +    alias: 'widget.PVE.qemu.HDThrottleInputPanel',
> +
> +    insideWizard: false,
> +
> +    unused: false, // ADD usused disk imaged
> +
> +    vmconfig: {}, // used to select usused disks
> +
> +    onGetValues: function(values) {
> +	var me = this;
> +
> +	var confid = me.confid;
> +
> +        var names = ['mbps_rd', 'mbps_wr', 'iops_rd', 'iops_wr'];
> +        Ext.Array.each(names, function(name) {
> +            if (values[name]) {
> +                me.drive[name] = values[name];
> +            } else {
> +                delete me.drive[name];
> +            }
> +            var burst_name = name + '_max';
> +            if (values[burst_name] && values[name]) {
> +                me.drive[burst_name] = values[burst_name];
> +            } else {
> +                delete me.drive[burst_name];
> +            }
> +        });
> +
> +	var params = {};
> +
> +	params[confid] = PVE.Parser.printQemuDrive(me.drive);
> +
> +	return params;
> +    },
> +
> +    setDrive: function(drive) {
> +	var me = this;
> +
> +	me.drive = drive;
> +
> +	var values = {};
> +
> +	values.mbps_rd = drive.mbps_rd;
> +	values.mbps_wr = drive.mbps_wr;
> +	values.iops_rd = drive.iops_rd;
> +	values.iops_wr = drive.iops_wr;
> +	values.mbps_rd_max = drive.mbps_rd_max;
> +	values.mbps_wr_max = drive.mbps_wr_max;
> +	values.iops_rd_max = drive.iops_rd_max;
> +	values.iops_wr_max = drive.iops_wr_max;
> +
> +	me.setValues(values);
> +    },
> +
> +    initComponent : function() {
> +	var me = this;
> +
> +	me.drive = {};
> +
> +	me.column1 = [];
> +	me.column2 = [];
> +
> +	var width2 = 140;
> +
> +        me.mbps_rd = Ext.widget('numberfield', {
> +            name: 'mbps_rd',
> +            minValue: 1,
> +            step: 1,
> +            fieldLabel: gettext('Read limit') + ' (MB/s)',
> +            labelWidth: width2,
> +            emptyText: gettext('unlimited')
> +         });
> +
> +        me.column1.push(me.mbps_rd);
> +
> +        me.mbps_rd_max = Ext.widget('numberfield', {
> +            name: 'mbps_rd_max',
> +            minValue: 1,
> +            step: 1,
> +            fieldLabel: gettext('Read max burst') + ' (MB)',
> +            labelWidth: width2,
> +            emptyText: gettext('default')
> +        });
> +
> +        me.column2.push(me.mbps_rd_max);
> +
> +
> +        me.mbps_wr = Ext.widget('numberfield', {
> +            name: 'mbps_wr',
> +            minValue: 1,
> +            step: 1,
> +            fieldLabel: gettext('Write limit') + ' (MB/s)',
> +            labelWidth: width2,
> +            emptyText: gettext('unlimited')
> +        });
> +
> +        me.column1.push(me.mbps_wr);
> +
> +        me.mbps_wr_max = Ext.widget('numberfield', {
> +            name: 'mbps_wr_max',
> +            minValue: 1,
> +            step: 1,
> +            fieldLabel: gettext('Write max burst') + ' (MB)',
> +            labelWidth: width2,
> +            emptyText: gettext('default')
> +        });
> +
> +        me.column2.push(me.mbps_wr_max);
> +
> +        me.iops_rd = Ext.widget('numberfield', {
> +            name: 'iops_rd',
> +            minValue: 10,
> +            step: 10,
> +            fieldLabel: gettext('Read limit') + ' (ops/s)',
> +            labelWidth: width2,
> +            emptyText: gettext('unlimited')
> +        });
> +
> +        me.column1.push(me.iops_rd);
> +
> +        me.iops_rd_max = Ext.widget('numberfield', {
> +            name: 'iops_rd_max',
> +            minValue: 10,
> +            step: 10,
> +            fieldLabel: gettext('Read max burst') + ' (ops)',
> +            labelWidth: width2,
> +            emptyText: gettext('default')
> +        });
> +
> +        me.column2.push(me.iops_rd_max);
> +
> +        me.iops_wr = Ext.widget('numberfield', {
> +            name: 'iops_wr',
> +            minValue: 10,
> +            step: 10,
> +            fieldLabel: gettext('Write limit') + ' (ops/s)',
> +            labelWidth: width2,
> +            emptyText: gettext('unlimited')
> +        });
> +
> +        me.column1.push(me.iops_wr);
> +
> +        me.iops_wr_max = Ext.widget('numberfield', {
> +            name: 'iops_wr_max',
> +            minValue: 10,
> +            step: 10,
> +            fieldLabel: gettext('Write max burst') + ' (ops)',
> +            labelWidth: width2,
> +            emptyText: gettext('default')
> +        });
> +
> +        me.column2.push(me.iops_wr_max);
> +
> +	me.callParent();
> +    }
> +});
> +
> +Ext.define('PVE.qemu.HDThrottle', {
> +    extend: 'PVE.window.Edit',
> +
> +    isAdd: true,
> +
> +    initComponent : function() {
> +	var me = this;
> +
> +	var nodename = me.pveSelNode.data.node;
> +	if (!nodename) {
> +	    throw "no node name specified";
> +	}
> +
> +	var unused = me.confid && me.confid.match(/^unused\d+$/);
> +
> +	me.create = me.confid ? unused : true;
> +
> +	var ipanel = Ext.create('PVE.qemu.HDThrottleInputPanel', {
> +	    confid: me.confid,
> +	    nodename: nodename,
> +	});
> +
> +	var subject;
> +	if (unused) {
> +	    me.subject = gettext('Unused Disk');
> +	} else {
> +           me.subject = gettext('Hard Disk') + ' (' + me.confid + ')';
> +	}
> +
> +	me.items = [ ipanel ];
> +
> +	me.callParent();
> +
> +	me.load({
> +	    success: function(response, options) {
> +		if (me.confid) {
> +		    var value = response.result.data[me.confid];
> +		    var drive = PVE.Parser.parseQemuDrive(me.confid, value);
> +		    if (!drive) {
> +			Ext.Msg.alert(gettext('Error'), gettext('Unable to parse
> drive options'));
> +			me.close();
> +			return;
> +		    }
> +		    ipanel.setDrive(drive);
> +		    me.isValid(); // trigger validation
> +		}
> +	    }
> +	});
> +    }
> +});
> diff --git a/www/manager/qemu/HardwareView.js
> b/www/manager/qemu/HardwareView.js
> index b3dea91..c1c6d1d 100644
> --- a/www/manager/qemu/HardwareView.js
> +++ b/www/manager/qemu/HardwareView.js
> @@ -212,6 +212,28 @@ Ext.define('PVE.qemu.HardwareView', {
>  	    win.on('destroy', reload);
>  	};
> 
> +	var run_diskthrottle = function() {
> +	    var rec = sm.getSelection()[0];
> +	    if (!rec) {
> +		return;
> +	    }
> +
> +	    var rowdef = rows[rec.data.key];
> +	    if (!rowdef.editor) {
> +		return;
> +	    }
> +
> +	    var editor = rowdef.editor;
> +            var win = Ext.create('PVE.qemu.HDThrottle', {
> +		pveSelNode: me.pveSelNode,
> +		confid: rec.data.key,
> +		url: '/api2/extjs/' + baseurl
> +	    });
> +
> +	    win.show();
> +	    win.on('destroy', reload);
> +	};
> +
>  	var run_resize = function() {
>  	    var rec = sm.getSelection()[0];
>  	    if (!rec) {
> @@ -256,10 +278,15 @@ Ext.define('PVE.qemu.HardwareView', {
>  	    win.on('destroy', reload);
>  	};
> 
> -	var edit_btn = new PVE.button.Button({
> +        var diskthrottleMenu = Ext.create('Ext.menu.Item', {
> +           text: 'Disk Throttle',
> +           handler: run_diskthrottle
> +        });
> +
> +        var edit_btn = Ext.create('Ext.button.Split', {
>  	    text: gettext('Edit'),
>  	    selModel: sm,
> -	    disabled: true,
> +//	    disabled: true,
>  	    enableFn: function(rec) {
>  		if (!rec) {
>  		    return false;
> @@ -267,8 +294,19 @@ Ext.define('PVE.qemu.HardwareView', {
>  		var rowdef = rows[rec.data.key];
>  		return !!rowdef.editor;
>  	    },
> -	    handler: run_editor
> -	});
> +	    handler: run_editor,
> +
> +            menu: new Ext.menu.Menu({
> +                items: [
> +                    {
> +			text: gettext('Edit'),
> +
> +		        handler: run_editor,
> +                    },
> +                    diskthrottleMenu
> +                ]
> +            })
> +        });
> 
>  	var resize_btn = new PVE.button.Button({
>  	    text: gettext('Resize disk'),
> --
> 1.7.10.4
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel





More information about the pve-devel mailing list