From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C61596032E for ; Tue, 11 Aug 2020 19:09:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C45A1A507 for ; Tue, 11 Aug 2020 19:09:30 +0200 (CEST) Received: from mx.giftfish.de (mx.giftfish.de [176.9.239.230]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4879FA4F4 for ; Tue, 11 Aug 2020 19:09:29 +0200 (CEST) Received: by mx.giftfish.de (OpenSMTPD) with ESMTPSA id 811119ac (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Tue, 11 Aug 2020 19:02:48 +0200 (CEST) From: Marius Schellenberger To: pve-devel@lists.proxmox.com Date: Tue, 11 Aug 2020 21:02:03 +0200 Message-Id: <20200811190203.10151-3-proxmox@giftfish.de> In-Reply-To: <20200811190203.10151-1-proxmox@giftfish.de> References: <20200811190203.10151-1-proxmox@giftfish.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH] ui: added cloud-init mtu and userdata options X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Aug 2020 17:09:30 -0000 Added options to configure the cloud-init MTU and userdata fields via the Web-UI. Signed-off-by: Marius Schellenberger --- www/manager6/Makefile | 1 + www/manager6/Parser.js | 6 ++ www/manager6/Utils.js | 8 +++ www/manager6/qemu/CloudInit.js | 10 ++++ www/manager6/qemu/IPConfigEdit.js | 6 ++ www/manager6/qemu/UserDataEdit.js | 94 +++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 www/manager6/qemu/UserDataEdit.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 4288acdd..096454fd 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -201,6 +201,7 @@ JSSRC= \ qemu/Smbios1Edit.js \ qemu/SystemEdit.js \ qemu/USBEdit.js \ + qemu/UserDataEdit.js \ sdn/Browser.js \ sdn/ControllerView.js \ sdn/Status.js \ diff --git a/www/manager6/Parser.js b/www/manager6/Parser.js index b793a28e..580ed2ec 100644 --- a/www/manager6/Parser.js +++ b/www/manager6/Parser.js @@ -275,6 +275,8 @@ Ext.define('PVE.Parser', { statics: { res.ip6 = match_res[1]; } else if ((match_res = p.match(/^gw6=(\S+)$/)) !== null) { res.gw6 = match_res[1]; + } else if ((match_res = p.match(/^mtu=(\S+)$/)) !== null) { + res.mtu = match_res[1]; } else { errors = true; return false; // break @@ -307,6 +309,10 @@ Ext.define('PVE.Parser', { statics: { str += c + "gw6=" + cfg.gw6; c = ","; } + if (cfg.mtu) { + str += c + "mtu=" + cfg.mtu; + c = ","; + } return str; }, diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index bf9ceda9..7b3ffec3 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -1351,6 +1351,14 @@ Ext.define('PVE.Utils', { utilities: { reader.readAsText(file); }, + loadUserDataFromFile: function(file, callback) { + var reader = new FileReader(); + reader.onload = function(evt) { + callback(evt.target.result); + }; + reader.readAsText(file); + }, + diskControllerMaxIDs: { ide: 4, sata: 6, diff --git a/www/manager6/qemu/CloudInit.js b/www/manager6/qemu/CloudInit.js index a588f09b..ac960672 100644 --- a/www/manager6/qemu/CloudInit.js +++ b/www/manager6/qemu/CloudInit.js @@ -253,6 +253,16 @@ Ext.define('PVE.qemu.CloudInit', { never_delete: true, defaultValue: gettext('use host settings') }, + ciuserdata: { + header: 'User-Data', + iconCls: 'fa fa-code', + editor: caps.vms['VM.Config.Network'] ? 'PVE.qemu.UserDataEdit' : undefined, + never_delete: true, + defaultValue: '', + renderer: function(value) { + return value || Proxmox.Utils.noneText; + } + }, sshkeys: { header: gettext('SSH public key'), iconCls: 'fa fa-key', diff --git a/www/manager6/qemu/IPConfigEdit.js b/www/manager6/qemu/IPConfigEdit.js index 934a86be..f1e2fc92 100644 --- a/www/manager6/qemu/IPConfigEdit.js +++ b/www/manager6/qemu/IPConfigEdit.js @@ -66,6 +66,12 @@ Ext.define('PVE.qemu.IPConfigPanel', { fieldLabel: gettext('Network Device'), value: me.netid }, + { + xtype: 'textfield', + name: 'mtu', + value: me.ipconfig.mtu, + fieldLabel: 'MTU' + }, { layout: { type: 'hbox', diff --git a/www/manager6/qemu/UserDataEdit.js b/www/manager6/qemu/UserDataEdit.js new file mode 100644 index 00000000..465f5b8f --- /dev/null +++ b/www/manager6/qemu/UserDataEdit.js @@ -0,0 +1,94 @@ +Ext.define('PVE.qemu.UserDataInputPanel', { + extend: 'Proxmox.panel.InputPanel', + xtype: 'pveQemuUserDataInputPanel', + + insideWizard: false, + + onGetValues: function(values) { + var me = this; + if (!values.ciuserdata.length) { + values = {}; + values['delete'] = 'ciuserdata'; + return values; + } else { + var fileheader = "#cloud-config" + var data = values.ciuserdata.split('\n'); + if (data[0] != fileheader) { + values.ciuserdata = fileheader + '\n' + values.ciuserdata; + } + values.ciuserdata = encodeURIComponent(btoa(values.ciuserdata)); + } + return values; + }, + + items: [ + { + xtype: 'textarea', + itemId: 'ciuserdata', + name: 'ciuserdata', + height: 250 + }, + { + xtype: 'filebutton', + itemId: 'filebutton', + name: 'file', + text: gettext('Load User-Data File'), + fieldLabel: 'test', + listeners: { + change: function(btn, e, value) { + var me = this.up('inputpanel'); + e = e.event; + Ext.Array.each(e.target.files, function(file) { + PVE.Utils.loadUserDataFromFile(file, function(res) { + var dataField = me.down('#ciuserdata'); + var old = dataField.getValue(); + dataField.setValue(old + '\n' + res); + }); + }); + btn.reset(); + } + } + } + ], + + initComponent: function() { + var me = this; + + me.callParent(); + if (!window.FileReader) { + me.down('#filebutton').setVisible(false); + } + + } +}); + +Ext.define('PVE.qemu.UserDataEdit', { + extend: 'Proxmox.window.Edit', + + width: 800, + + initComponent : function() { + var me = this; + + var ipanel = Ext.create('PVE.qemu.UserDataInputPanel'); + + Ext.apply(me, { + subject: 'User-Data', + items: [ ipanel ] + }); + + me.callParent(); + + if (!me.create) { + me.load({ + success: function(response, options) { + var data = response.result.data; + if (data.ciuserdata) { + data.ciuserdata = atob(decodeURIComponent(data.ciuserdata)); + ipanel.setValues(data); + } + } + }); + } + } +}); -- 2.27.0