From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 321591FF173 for <inbox@lore.proxmox.com>; Mon, 27 Jan 2025 12:30:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9C1EB28A05; Mon, 27 Jan 2025 12:30:02 +0100 (CET) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Mon, 27 Jan 2025 12:29:19 +0100 Message-Id: <20250127112923.31703-13-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250127112923.31703-1-f.ebner@proxmox.com> References: <20250127112923.31703-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.044 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH qemu-server v5 12/16] check type: require schema as an argument X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> In preparation to re-use the helper with a dedicated schema for a 'fleecing' special section. No functional change intended. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- PVE/QemuServer.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 8c26fbc3..7711014d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2081,11 +2081,13 @@ sub cloudinit_pending_properties { } sub check_type { - my ($key, $value) = @_; + my ($key, $value, $schema) = @_; - die "unknown setting '$key'\n" if !$confdesc->{$key}; + die "check_type: no schema defined\n" if !$schema; - my $type = $confdesc->{$key}->{type}; + die "unknown setting '$key'\n" if !$schema->{$key}; + + my $type = $schema->{$key}->{type}; if (!defined($value)) { die "got undefined value\n"; @@ -2106,7 +2108,7 @@ sub check_type { return $value if $value =~ m/^(\d+)(\.\d+)?$/; die "type check ('number') failed - got '$value'\n"; } elsif ($type eq 'string') { - if (my $fmt = $confdesc->{$key}->{format}) { + if (my $fmt = $schema->{$key}->{format}) { PVE::JSONSchema::check_format($fmt, $value); return $value; } @@ -2301,7 +2303,7 @@ sub parse_vm_config { $conf->{$key} = $value; next; } - eval { $value = check_type($key, $value); }; + eval { $value = check_type($key, $value, $confdesc); }; if ($@) { $handle_error->("vm $vmid - unable to parse value of '$key' - $@"); } else { @@ -2368,7 +2370,7 @@ sub write_vm_config { # fixme: check syntax? next; } - eval { $value = check_type($key, $value); }; + eval { $value = check_type($key, $value, $confdesc); }; die "unable to parse value of '$key' - $@" if $@; $cref->{$key} = $value; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel