[pve-devel] [PATCH manager v4 2/2] Introduce check to disable quota usage for unprivileged containers

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Sep 11 15:41:11 CEST 2017


On Fri, Aug 25, 2017 at 11:50:02AM +0200, Philip Abernethy wrote:
> Disables the quota checkbox for unprivileged containers in the creation wizard,
> as well as when editing or adding mountpoints.
> ---
> I figured I should actually fix *all* instances accordingly.
>  www/manager6/lxc/CreateWizard.js | 10 ++++++++++
>  www/manager6/lxc/ResourceEdit.js |  8 +++++++-
>  www/manager6/lxc/Resources.js    |  5 +++++
>  3 files changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/www/manager6/lxc/CreateWizard.js b/www/manager6/lxc/CreateWizard.js
> index 86e710ee..a4745fd7 100644
> --- a/www/manager6/lxc/CreateWizard.js
> +++ b/www/manager6/lxc/CreateWizard.js
> @@ -60,6 +60,7 @@ Ext.define('PVE.lxc.CreateWizard', {
>  	    insideWizard: true,
>  	    isCreate: true,
>  	    unused: false,
> +	    unprivileged: false,
>  	    confid: 'rootfs'
>  	});
>  
> @@ -218,6 +219,15 @@ Ext.define('PVE.lxc.CreateWizard', {
>  			    xtype: 'pvecheckbox',
>  			    name: 'unprivileged',
>  			    value: '',
> +			    listeners: {
> +				change: function(f, value) {
> +				    if (value) {
> +					rootfspanel.down('field[name=quota]').setValue(false);
> +				    }
> +				    rootfspanel.unprivileged = value;
> +				    rootfspanel.down('field[name=quota]').setDisabled(value);

The 'disabled' value in this field also depends on the storage, which
this line ignores, so if you go through the CT creation wizard to up to
the rootfs tab, select ZFS there, then switch back to the first tab and
check and immediately uncheck the 'unprivileged' checkbox before going
back to the rootfs tab, you'll have an enabled quota checkbox.

This would work:
-+    rootfspanel.down('field[name=quota]').setDisabled(value);
++   var hdsel = rootfspanel.hdstoragesel;
++   hdsel.fireEvent('change', hdsel, hdsel.getValue());

> +				}
> +			    },
>  			    fieldLabel: gettext('Unprivileged container')
>  			}
>  		    ],
> diff --git a/www/manager6/lxc/ResourceEdit.js b/www/manager6/lxc/ResourceEdit.js
> index 9efb5116..26d65319 100644
> --- a/www/manager6/lxc/ResourceEdit.js
> +++ b/www/manager6/lxc/ResourceEdit.js
> @@ -39,6 +39,8 @@ Ext.define('PVE.lxc.CPUEdit', {
>  Ext.define('PVE.lxc.MountPointEdit', {
>      extend: 'PVE.window.Edit',
>  
> +    unprivileged: false,
> +
>      initComponent : function() {
>  	var me = this;
>  
> @@ -55,6 +57,7 @@ Ext.define('PVE.lxc.MountPointEdit', {
>  	    confid: me.confid,
>  	    nodename: nodename,
>  	    unused: unused,
> +	    unprivileged: me.unprivileged,
>  	    isCreate: me.isCreate
>  	});
>  
> @@ -221,6 +224,8 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
>  
>      unused: false, // ADD usused disk imaged
>  
> +    unprivileged: false,
> +
>      vmconfig: {}, // used to select usused disks
>  
>      onGetValues: function(values) {
> @@ -405,7 +410,7 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
>  		        rec.data.type === 'zfspool')) {
>  			me.quota.setDisabled(true);
>  			me.quota.setValue(false);
> -		    } else {
> +		    } else if (!me.unprivileged) {
>  			me.quota.setDisabled(false);

I'd rather not remove the else branch this way otherwise there may be
ways to skip a state change there?

Maybe just:
    } else {
        me.quota.setDisabled(me.unprivileged);
    }
?

>  		    }
>  		    if (me.unused || !me.isCreate) {
> @@ -502,6 +507,7 @@ Ext.define('PVE.lxc.MountPointInputPanel', {
>  	me.quota = Ext.createWidget('pvecheckbox', {
>  	    name: 'quota',
>  	    defaultValue: 0,
> +	    disabled: me.unprivileged,
>  	    fieldLabel: gettext('Enable quota')
>  	});
>  
> diff --git a/www/manager6/lxc/Resources.js b/www/manager6/lxc/Resources.js
> index c54c7001..3359e37e 100644
> --- a/www/manager6/lxc/Resources.js
> +++ b/www/manager6/lxc/Resources.js
> @@ -94,6 +94,9 @@ Ext.define('PVE.lxc.RessourceView', {
>  		defaultValue: PVE.Utils.noneText,
>  		editor: mpeditor,
>  		tdCls: 'pve-itype-icon-storage'
> +	    },
> +	    unprivileged: {
> +		visible: false
>  	    }
>  	};
>  
> @@ -141,6 +144,7 @@ Ext.define('PVE.lxc.RessourceView', {
>  	    var win = Ext.create(editor, {
>  		pveSelNode: me.pveSelNode,
>  		confid: rec.data.key,
> +		unprivileged: me.getObjectValue('unprivileged'),
>  		url: '/api2/extjs/' + baseurl
>  	    });
>  
> @@ -266,6 +270,7 @@ Ext.define('PVE.lxc.RessourceView', {
>  				handler: function() {
>  				    var win = Ext.create('PVE.lxc.MountPointEdit', {
>  					url: '/api2/extjs/' + baseurl,
> +					unprivileged: me.getObjectValue('unprivileged'),
>  					pveSelNode: me.pveSelNode
>  				    });
>  				    win.on('destroy', reload);
> -- 
> 2.11.0




More information about the pve-devel mailing list