[pve-devel] [RFC manager] add Default Button to lxc and qemu options

Dominik Csapak d.csapak at proxmox.com
Wed May 25 14:10:57 CEST 2016


this patch adds an "Default" button to the lxc and
qemu options

clicking on this simply deletes the selected key from the config
the purpose of this is for instance if you want to reset the hotplug
selection but you don't know what is default

with this it would be possible to remove the default values from the
comboboxes (and thus eliminating duplicate entries there)

this includes a blacklist for lxc and qemu which contains,
the values which should probably not be deleted (name and smbios for qemu,
ostype and arch for lxc)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/lxc/Options.js  | 40 +++++++++++++++++++++++++++++++++++++++-
 www/manager6/qemu/Options.js | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/www/manager6/lxc/Options.js b/www/manager6/lxc/Options.js
index d757540..e3e27f4 100644
--- a/www/manager6/lxc/Options.js
+++ b/www/manager6/lxc/Options.js
@@ -188,10 +188,48 @@ Ext.define('PVE.lxc.Options', {
 	    handler: run_editor
 	});
 
+	var defaultBlacklist = ['ostype', 'arch'];
+
+	var default_btn = Ext.create('PVE.button.Button', {
+	    text: gettext('Default'),
+	    disabled: true,
+	    selModel: sm,
+	    enableFn: function(rec) {
+		// if selected is not part of the blacklist
+		return (defaultBlacklist.indexOf(rec.data.key) === -1);
+	    },
+            handler: function() {
+		var sm = me.getSelectionModel();
+		var rec = sm.getSelection()[0];
+		if (!rec || defaultBlacklist.indexOf(rec.data.key) !== -1) {
+		    return;
+		}
+
+		var rowdef = me.rows[rec.data.key] || {};
+		var keys = rowdef.multiKey ||  [ rec.data.key ];
+		var todelete = keys.join(',');
+
+                PVE.Utils.API2Request({
+                    url: '/api2/extjs/' + baseurl,
+                    waitMsgTarget: me,
+                    method: 'PUT',
+                    params: {
+                        'delete': todelete
+                    },
+                    callback: function() {
+                        reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert('Error',response.htmlStatus);
+                    }
+                });
+            }
+	});
+
 	Ext.apply(me, {
 	    url: "/api2/json/nodes/" + nodename + "/lxc/" + vmid + "/config",
 	    selModel: sm,
-	    tbar: [ edit_btn ],
+	    tbar: [ edit_btn, default_btn ],
 	    rows: rows,
 	    listeners: {
 		itemdblclick: run_editor,
diff --git a/www/manager6/qemu/Options.js b/www/manager6/qemu/Options.js
index 95d6eb1..56dcac0 100644
--- a/www/manager6/qemu/Options.js
+++ b/www/manager6/qemu/Options.js
@@ -358,6 +358,44 @@ Ext.define('PVE.qemu.Options', {
             }
         });
 
+	var defaultBlacklist = ['name', 'smbios1'];
+
+	var default_btn = Ext.create('PVE.button.Button', {
+	    text: gettext('Default'),
+	    disabled: true,
+            handler: function() {
+		var sm = me.getSelectionModel();
+		var rec = sm.getSelection()[0];
+		if (!rec || defaultBlacklist.indexOf(rec.data.key) !== -1) {
+		    return;
+		}
+
+		var rowdef = me.rows[rec.data.key] || {};
+		var keys = rowdef.multiKey ||  [ rec.data.key ];
+		var todelete = keys.join(',');
+
+		// special case, do not delete bootdisk
+		if (rec.data.key == 'boot') {
+		    todelete = 'boot';
+		}
+
+                PVE.Utils.API2Request({
+                    url: '/api2/extjs/' + baseurl,
+                    waitMsgTarget: me,
+                    method: 'PUT',
+                    params: {
+                        'delete': todelete
+                    },
+                    callback: function() {
+                        reload();
+                    },
+                    failure: function (response, opts) {
+                        Ext.Msg.alert('Error',response.htmlStatus);
+                    }
+                });
+            }
+	});
+
 	var set_button_status = function() {
 	    var sm = me.getSelectionModel();
 	    var rec = sm.getSelection()[0];
@@ -373,13 +411,14 @@ Ext.define('PVE.qemu.Options', {
 
 	    edit_btn.setDisabled(!rowdef.editor);
 	    revert_btn.setDisabled(!pending);
+	    default_btn.setDisabled((defaultBlacklist.indexOf(key) !== -1));
 	};
 
 	Ext.apply(me, {
 	    url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/pending",
 	    interval: 5000,
 	    cwidth1: 250,
-	    tbar: [ edit_btn, revert_btn ],
+	    tbar: [ edit_btn, revert_btn, default_btn ],
 	    rows: rows,
 	    listeners: {
 		itemdblclick: run_editor,
-- 
2.1.4





More information about the pve-devel mailing list