[pve-devel] [PATCH common] Add mac-addr standard option for MAC address verification
Christian Ebner
c.ebner at proxmox.com
Mon Jan 21 12:35:40 CET 2019
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
src/PVE/JSONSchema.pm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index fb58ad3..0408c5d 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -113,6 +113,11 @@ register_standard_option('pve-output-format', {
default => 'text',
});
+register_standard_option('mac-addr', {
+ description => "Mac address.",
+ type => 'string', format => 'mac-addr',
+});
+
my $format_list = {};
sub register_format {
@@ -204,6 +209,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