[pve-devel] [PATCH v2 pve-common] JSONSchema: Add format for MAC address verification
Christian Ebner
c.ebner at proxmox.com
Tue Jan 22 11:01:39 CET 2019
Adds a format to verify MAC addresses to JSONSchema.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
Version 2:
* Droped standard option as discussed on mailing list
* Changed regex to be more strict
src/PVE/JSONSchema.pm | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index fb58ad3..36fa994 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -204,6 +204,17 @@ sub pve_verify_node_name {
return $node;
}
+register_format('mac-addr', \&pve_verify_mac_addr);
+sub pve_verify_mac_addr {
+ my ($mac_addr, $noerr) = @_;
+
+ if ($mac_addr !~ m/^[0-9a-f]{2}(:[0-9a-f]{2}){5}$/i) {
+ return undef if $noerr;
+ die "value does not look like a valid MAC address\n";
+ }
+ return $mac_addr;
+}
+
register_format('ipv4', \&pve_verify_ipv4);
sub pve_verify_ipv4 {
my ($ipv4, $noerr) = @_;
--
2.11.0
More information about the pve-devel
mailing list