[pve-devel] [PATCH manager] ui: storage: pbs: allow to set port

Stoiko Ivanov s.ivanov at proxmox.com
Wed Feb 3 11:59:55 CET 2021


This patch allows to set a custom port to a PBS storage, by appending
it to the Server field (e.g. pbs.proxmox.com:443). The code was
taken from the RemoteEdit widget in the proxmox-backup repository.

While the storage config stores the port as separate line, the current
approach seems a bit more concise and does not mess up the balanced
layout.

Quickly tested on my setup.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
Thanks to Dominik for pointing me to the RemoteEdit.js!

 www/manager6/storage/PBSEdit.js | 57 +++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/www/manager6/storage/PBSEdit.js b/www/manager6/storage/PBSEdit.js
index 2479304a..45f35c76 100644
--- a/www/manager6/storage/PBSEdit.js
+++ b/www/manager6/storage/PBSEdit.js
@@ -463,11 +463,49 @@ Ext.define('PVE.storage.PBSInputPanel', {
 	me.column1 = [
 	    {
 		xtype: me.isCreate ? 'textfield' : 'displayfield',
-		name: 'server',
+		name: 'serverport',
 		value: '',
-		vtype: 'DnsOrIp',
+		vtype: 'HostPort',
+		submitValue: false,
 		fieldLabel: gettext('Server'),
 		allowBlank: false,
+		listeners: {
+		    change: function(field, newvalue) {
+			let server = newvalue;
+			let port;
+
+			let match = Proxmox.Utils.HostPort_match.exec(newvalue);
+			if (match === null) {
+			    match = Proxmox.Utils.HostPortBrackets_match.exec(newvalue);
+			    if (match === null) {
+				match = Proxmox.Utils.IP6_dotnotation_match.exec(newvalue);
+			    }
+			}
+
+			if (match !== null) {
+			    server = match[1];
+			    if (match[2] !== undefined) {
+				port = match[2];
+			    }
+			}
+
+			field.up('inputpanel').down('field[name=server]').setValue(server);
+			field.up('inputpanel').down('field[name=port]').setValue(port);
+		    },
+		},
+	    },
+	    {
+		xtype: 'proxmoxtextfield',
+		hidden: true,
+		name: 'server',
+	    },
+	    {
+		xtype: 'proxmoxtextfield',
+		hidden: true,
+		cbind: {
+		    deleteEmpty: '{!isCreate}',
+		},
+		name: 'port',
 	    },
 	    {
 		xtype: me.isCreate ? 'textfield' : 'displayfield',
@@ -522,4 +560,19 @@ Ext.define('PVE.storage.PBSInputPanel', {
 
 	me.callParent();
     },
+
+    setValues: function(values) {
+	let me = this;
+
+	let server = values.server;
+	if (values.port !== undefined) {
+	    if (Proxmox.Utils.IP6_match.test(server)) {
+		server = `[${server}]`;
+	    }
+	    server += `:${values.port}`;
+	}
+	values.serverport = server;
+
+	return me.callParent([values]);
+    },
 });
-- 
2.20.1






More information about the pve-devel mailing list