[pve-devel] [PATCH] added renderer for hd strings in hardware overview

Stefan Priebe s.priebe at profihost.ag
Thu Aug 23 22:51:21 CEST 2012


Hello Alexandre,

Am 22.08.2012 17:02, schrieb Dietmar Maurer:
> @alexandre: or can we add that inside QemuServer.pm - we also use such code
> for the new 'size' parameter, so maybe we can reuse that?

what's your opinion?

Stefan


>> -----Original Message-----
>> From: pve-devel-bounces at pve.proxmox.com [mailto:pve-devel-
>> bounces at pve.proxmox.com] On Behalf Of tgrodzinski
>> Sent: Mittwoch, 22. August 2012 16:10
>> To: pve-devel at pve.proxmox.com
>> Subject: [pve-devel] [PATCH] added renderer for hd strings in hardware
>> overview
>>
>>
>> Signed-off-by: tgrodzinski <t.grodzinski at profihost.ag>
>> ---
>>   www/manager/qemu/HardwareView.js |  108 +++++++++++++++++++++++--
>> -------------
>>   1 file changed, 67 insertions(+), 41 deletions(-)
>>
>> diff --git a/www/manager/qemu/HardwareView.js
>> b/www/manager/qemu/HardwareView.js
>> index 4d27b84..8de6038 100644
>> --- a/www/manager/qemu/HardwareView.js
>> +++ b/www/manager/qemu/HardwareView.js
>> @@ -94,56 +94,82 @@ Ext.define('PVE.qemu.HardwareView', {
>>   	    }
>>   	};
>>
>> +	var renderer_hd = function (value) {
>> +		if (typeof value === 'string') {
>> +			var units = ['', 'K', 'M', 'G', 'T'];
>> +			var parts = value.split( ',' );
>> +			var formattedValue = '';
>> +			for (i = 0; i < parts.length; i++) {
>> +				var bpsMatch = parts[i].match(
>> /^bps_..=(\d+)/ );
>> +				if (bpsMatch) {
>> +					var bps = bpsMatch[1];
>> +					var pow = Math.floor( Math.log( bps )
>> / Math.log( 1024 ) );
>> +					pow = Math.min( pow, units.length - 1
>> );
>> +					var bpsNew = Math.round( bps /
>> Math.pow( 1024, pow ) * 100 ) / 100;
>> +					formattedValue += parts[i].replace(
>> bps, bpsNew + units[pow] );
>> +				} else {
>> +					formattedValue += parts[i];
>> +				}
>> +				if (i != parts.length - 1) formattedValue += ', ';
>> +			}
>> +			return formattedValue;
>> +		}
>> +		return value;
>> +	};
>> +
>>   	for (i = 0; i < 4; i++) {
>> -	    confid = "ide" + i;
>> -	    rows[confid] = {
>> -		group: 1,
>> -		tdCls: 'pve-itype-icon-storage',
>> -		editor: 'PVE.qemu.HDEdit',
>> -		never_delete: caps.vms['VM.Config.Disk'] ? false : true,
>> -		header: gettext('Hard Disk') + ' (' + confid +')',
>> -		cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
>> -	    };
>> +		confid = "ide" + i;
>> +		rows[confid] = {
>> +			group: 1,
>> +			tdCls: 'pve-itype-icon-storage',
>> +			editor: 'PVE.qemu.HDEdit',
>> +			never_delete: caps.vms['VM.Config.Disk'] ? false :
>> true,
>> +			header: gettext('Hard Disk') + ' (' + confid +')',
>> +			cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
>> +			renderer: renderer_hd
>> +		};
>>   	}
>>   	for (i = 0; i < 16; i++) {
>> -	    confid = "scsi" + i;
>> -	    rows[confid] = {
>> -		group: 1,
>> -		tdCls: 'pve-itype-icon-storage',
>> -		editor: 'PVE.qemu.HDEdit',
>> -		never_delete: caps.vms['VM.Config.Disk'] ? false : true,
>> -		header: gettext('Hard Disk') + ' (' + confid +')',
>> -		cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
>> -	    };
>> +		confid = "scsi" + i;
>> +		rows[confid] = {
>> +			group: 1,
>> +			tdCls: 'pve-itype-icon-storage',
>> +			editor: 'PVE.qemu.HDEdit',
>> +			never_delete: caps.vms['VM.Config.Disk'] ? false :
>> true,
>> +			header: gettext('Hard Disk') + ' (' + confid +')',
>> +			cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
>> +			renderer: renderer_hd
>> +		};
>>   	}
>>   	for (i = 0; i < 16; i++) {
>> -	    confid = "virtio" + i;
>> -	    rows[confid] = {
>> -		group: 1,
>> -		tdCls: 'pve-itype-icon-storage',
>> -		editor: 'PVE.qemu.HDEdit',
>> -		never_delete: caps.vms['VM.Config.Disk'] ? false : true,
>> -		header: gettext('Hard Disk') + ' (' + confid +')',
>> -		cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
>> -	    };
>> +		confid = "virtio" + i;
>> +		rows[confid] = {
>> +			group: 1,
>> +			tdCls: 'pve-itype-icon-storage',
>> +			editor: 'PVE.qemu.HDEdit',
>> +			never_delete: caps.vms['VM.Config.Disk'] ? false :
>> true,
>> +			header: gettext('Hard Disk') + ' (' + confid +')',
>> +			cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
>> +			renderer: renderer_hd
>> +		};
>>   	}
>>   	for (i = 0; i < 32; i++) {
>> -	    confid = "net" + i;
>> -	    rows[confid] = {
>> -		group: 2,
>> -		tdCls: 'pve-itype-icon-network',
>> -		editor: caps.vms['VM.Config.Network'] ?
>> 'PVE.qemu.NetworkEdit' : undefined,
>> -		never_delete: caps.vms['VM.Config.Network'] ? false : true,
>> -		header: gettext('Network Device') + ' (' + confid +')'
>> -	    };
>> +		confid = "net" + i;
>> +		rows[confid] = {
>> +			group: 2,
>> +			tdCls: 'pve-itype-icon-network',
>> +			editor: caps.vms['VM.Config.Network'] ?
>> 'PVE.qemu.NetworkEdit' : undefined,
>> +			never_delete: caps.vms['VM.Config.Network'] ? false :
>> true,
>> +			header: gettext('Network Device') + ' (' + confid +')'
>> +		};
>>   	}
>>   	for (i = 0; i < 8; i++) {
>> -	    rows["unused" + i] = {
>> -		group: 3,
>> -		tdCls: 'pve-itype-icon-storage',
>> -		editor: caps.vms['VM.Config.Disk'] ? 'PVE.qemu.HDEdit' :
>> undefined,
>> -		header: gettext('Unused Disk') + ' ' + i
>> -	    };
>> +		rows["unused" + i] = {
>> +			group: 3,
>> +			tdCls: 'pve-itype-icon-storage',
>> +			editor: caps.vms['VM.Config.Disk'] ?
>> 'PVE.qemu.HDEdit' : undefined,
>> +			header: gettext('Unused Disk') + ' ' + i
>> +		};
>>   	}
>>
>>   	var sorterFn = function(rec1, rec2) {
>> --
>> 1.7.9.5
>>
>> _______________________________________________
>> pve-devel mailing list
>> pve-devel at pve.proxmox.com
>> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>
> _______________________________________________
> 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