[pve-devel] [PATCH manager 1/1] ui/qemu: Extend Qemu Guest agent

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jul 5 19:42:36 CEST 2018


Change to Qemu Guest Agent now being a property_string, and including
fstrim_cloned_disks.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 www/manager6/Makefile                     |  1 +
 www/manager6/Utils.js                     | 10 +++++
 www/manager6/form/AgentFeatureSelector.js | 65 +++++++++++++++++++++++++++++++
 www/manager6/qemu/Options.js              | 10 ++---
 4 files changed, 80 insertions(+), 6 deletions(-)
 create mode 100644 www/manager6/form/AgentFeatureSelector.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 3cc6990f..28d21fa7 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -49,6 +49,7 @@ JSSRC= 				                 	\
 	form/SnapshotSelector.js			\
 	form/ContentTypeSelector.js			\
 	form/HotplugFeatureSelector.js			\
+	form/AgentFeatureSelector.js			\
 	form/iScsiProviderSelector.js			\
 	form/DayOfWeekSelector.js			\
 	form/BackupModeSelector.js			\
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index ad5a0a61..58f92788 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -175,6 +175,16 @@ Ext.define('PVE.Utils', { utilities: {
 	return fa.join(', ');
     },
 
+    render_qga_features: function(value) {
+	if (!value) {
+	    return Proxmox.Utils.defaultText + ' (' + gettext('Disabled')  + ')';
+	} else if (value === '0') {
+	    return gettext('Disabled');
+	} else {
+	    return value;
+	}
+    },
+
     render_qemu_bios: function(value) {
 	if (!value) {
 	    return Proxmox.Utils.defaultText + ' (SeaBIOS)';
diff --git a/www/manager6/form/AgentFeatureSelector.js b/www/manager6/form/AgentFeatureSelector.js
new file mode 100644
index 00000000..cd74721b
--- /dev/null
+++ b/www/manager6/form/AgentFeatureSelector.js
@@ -0,0 +1,65 @@
+Ext.define('PVE.form.AgentFeatureSelector', {
+    extend: 'Ext.form.CheckboxGroup',
+    alias: 'widget.pveAgentFeatureSelector',
+
+    columns: 1,
+    vertical: true,
+    items: [
+	{ boxLabel: gettext('Enable Qemu Agent'),    name: 'agent', inputValue: 'enabled',   submitValue: false },
+	{ boxLabel: gettext('Run guest-trim after clone disk'),    name: 'agent', inputValue: 'fstrim_cloned_disks',   submitValue: false }
+    ],
+
+    setValue: function(value) {
+	var me = this;
+
+	var newVal = [];
+
+	var errors = false;
+	Ext.Array.forEach(value.split(','), function(val){
+	    if (val === '1') {
+		newVal.push('enabled');
+		return;
+	    }
+
+	    var match_res = val.match(/^([a-z_]+)=(\S+)$/);
+	    if (!match_res) {
+		newVal = [];
+		return false;
+	    }
+
+	    var k = match_res[1];
+	    if (match_res[2] == 1) {
+		newVal.push(k);
+	    }
+	});
+
+	if (errors) {
+	    newVal = [];
+	}
+	me.callParent([{ agent: newVal }]);
+    },
+
+    // overide framework function to
+    // assemble the qemu guest agent value
+    getSubmitData: function() {
+	var me = this,
+	boxes = me.getBoxes(),
+	data = [];
+
+	Ext.Array.forEach(boxes, function(box){
+	    if (box.getValue() && box.inputValue == 'enabled') {
+		data.push('1');
+	    } else if (box.getValue()) {
+		data.push(box.inputValue+'=1');
+	    }
+	});
+	/* because agent is an array */
+	/*jslint confusion: true*/
+	if (data.length === 0) {
+	    return { 'agent': '0' };
+	} else {
+	    return { 'agent': data.join(',') };
+	}
+    }
+
+});
diff --git a/www/manager6/qemu/Options.js b/www/manager6/qemu/Options.js
index 6f0b2511..16249fb4 100644
--- a/www/manager6/qemu/Options.js
+++ b/www/manager6/qemu/Options.js
@@ -266,17 +266,15 @@ Ext.define('PVE.qemu.Options', {
 	    agent: {
 		header: gettext('Qemu Agent'),
 		defaultValue: false,
-		renderer: Proxmox.Utils.format_boolean,
+		renderer: PVE.Utils.render_qga_features,
 		editor: caps.vms['VM.Config.Options'] ? {
 		    xtype: 'proxmoxWindowEdit',
 		    subject: gettext('Qemu Agent'),
 		    items: {
-			xtype: 'proxmoxcheckbox',
+			xtype: 'pveAgentFeatureSelector',
 			name: 'agent',
-			uncheckedValue: 0,
-			defaultValue: 0,
-			deleteDefaultValue: true,
-			fieldLabel: gettext('Enabled')
+			value: '',
+			allowBlank: true
 		    }
 		} : undefined
 	    },
-- 
2.11.0





More information about the pve-devel mailing list