From 920750982b5792c184d11b9deb6ec9dd816a39d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 13 Apr 2021 14:16:29 +0200 Subject: [PATCH] schema: pull out abstract 'id-pair' verifier MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit we'll need another one for guest bridge IDs Signed-off-by: Fabian Grünbichler --- src/PVE/JSONSchema.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 4864549..f2ddb50 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -273,20 +273,26 @@ sub parse_idmap { return $map; } -register_format('storagepair', \&verify_storagepair); -sub verify_storagepair { - my ($storagepair, $noerr) = @_; +my $verify_idpair = sub { + my ($input, $noerr, $format) = @_; - # note: this only checks a single list entry - # when using a storagepair-list map, you need to pass the full - # parameter to parse_idmap - eval { parse_idmap($storagepair, 'pve-storage-id') }; + eval { parse_idmap($input, $format) }; if ($@) { return undef if $noerr; die "$@\n"; } - return $storagepair; + return $input; +}; + +# note: this only checks a single list entry +# when using a storagepair-list map, you need to pass the full parameter to +# parse_idmap +register_format('storagepair', \&verify_storagepair); +sub verify_storagepair { + my ($storagepair, $noerr) = @_; + return $verify_idpair->($storagepair, $noerr, 'pve-storage-id'); +} } register_format('mac-addr', \&pve_verify_mac_addr); -- 2.39.2