[pve-devel] [PATCH common] Add mac-addr standard option for MAC address verification

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jan 21 18:24:23 CET 2019


On 1/21/19 12:35 PM, Christian Ebner wrote:
> 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) = @_;
> 

as the description and "optional" is different on all three cases where we
currently have a MAC in a JSONSchema backed config I'd just register the
format and omit the standard option, as IMO it does not helps too much if
all cases need to adapt the option anyway, but no strong feelings here... :)




More information about the pve-devel mailing list