]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
fix #3593: add CpuSet type to js
authorDaniel Bowder <daniel@bowdernet.com>
Fri, 1 Jul 2022 00:09:47 +0000 (17:09 -0700)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 10 Nov 2022 08:40:00 +0000 (09:40 +0100)
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
src/Utils.js

index c7303747d18fefe1f45b13528c943379c5008d56..9a13ba5ddc516e0d4320af98ba120707c775af61 100644 (file)
@@ -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);
     },
index 6a03057a704943539b90ed58dfb3d0b05ecf7883..87afbea62cb3d596ef6b0348f341d6f6f065cdff 100644 (file)
@@ -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+))?$");