public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Bowder <daniel@bowdernet.com>
To: pve-devel@lists.proxmox.com
Cc: Daniel Bowder <daniel@bowdernet.com>
Subject: [pve-devel] [PATCH v2 proxmox-widget-toolkit 3/4] fix #3593: add CpuSet type to js
Date: Thu, 30 Jun 2022 17:09:47 -0700	[thread overview]
Message-ID: <20220701000948.148496-4-daniel@bowdernet.com> (raw)
In-Reply-To: <20220701000948.148496-1-daniel@bowdernet.com>

Regex parses a cpuset via 2 matches. Find number(s) or range(s) folowed
by a comma, then, find a single number or a single range not followed
by a comma. E.g., 0-1,4-5,6,7,10,11,14-15
CpuSet function first checks regex, then ensures left num <= right num

Signed-off-by: Daniel Bowder <daniel@bowdernet.com>
---
 src/Toolkit.js | 20 ++++++++++++++++++++
 src/Utils.js   |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/src/Toolkit.js b/src/Toolkit.js
index a1d291e..ebdc545 100644
--- a/src/Toolkit.js
+++ b/src/Toolkit.js
@@ -121,6 +121,26 @@ Ext.apply(Ext.form.field.VTypes, {
     },
     HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
 
+    CpuSet: function(v) {
+	if (!Proxmox.Utils.CpuSet_match.test(v)) {
+	    return false;
+	}
+	let groups = v.split(",");
+	for (let i = 0; i < groups.length; i++) {
+	    if (!groups[i].includes("-")) {
+		continue;
+	    }
+	    let values = groups[i].split("-");
+	    let left = parseInt(values[0], 10);
+	    let right = parseInt(values[1], 10);
+	    if (left > right) {
+		return false;
+	    }
+	}
+	return true;
+    },
+    CpuSetText: gettext('This is not a valid CpuSet'),
+
     DnsName: function(v) {
 	return Proxmox.Utils.DnsName_match.test(v);
     },
diff --git a/src/Utils.js b/src/Utils.js
index 6a03057..87afbea 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -1315,6 +1315,8 @@ utilities: {
 	me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
 	me.DnsName_or_Wildcard_match = new RegExp("^(?:\\*\\.)?" + DnsName_REGEXP + "$");
 
+	me.CpuSet_match = /^(?:(?:[0-9]+,)|(?:[0-9]+-[0-9]+,))*(?:(?:[0-9]+)$|(?:[0-9]+-[0-9]+)$)/;
+
 	me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(?::(\\d+))?$");
 	me.HostPortBrackets_match = new RegExp("^\\[(" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](?::(\\d+))?$");
 	me.IP6_dotnotation_match = new RegExp("^(" + IPV6_REGEXP + ")(?:\\.(\\d+))?$");
-- 
2.36.1




  parent reply	other threads:[~2022-07-01  0:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01  0:09 [pve-devel] [PATCH SERIES v2 manager/docs/widget-toolkit/qemu-server 0/4] fix #3593 Daniel Bowder
2022-07-01  0:09 ` [pve-devel] [PATCH v2 qemu-server 1/4] fix #3593: add affinity to qemu Daniel Bowder
2022-07-01  0:09 ` [pve-devel] [PATCH v2 pve-docs 2/4] fix #3593: add affinity to docs Daniel Bowder
2022-07-01  0:09 ` Daniel Bowder [this message]
2022-07-01  0:09 ` [pve-devel] [PATCH v2 pve-manager 4/4] fix #3593: add js input for affinity Daniel Bowder
2022-11-10  9:57 ` [pve-devel] applied-series: [PATCH SERIES v2 manager/docs/widget-toolkit/qemu-server 0/4] fix #3593 Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220701000948.148496-4-daniel@bowdernet.com \
    --to=daniel@bowdernet.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal