mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-07-05 05:33:18 +00:00
check type: require schema as an argument
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> Link: https://lore.proxmox.com/20250127112923.31703-13-f.ebner@proxmox.com
This commit is contained in:
parent
68eabc42c1
commit
6eb92d31ba
@ -2081,11 +2081,13 @@ sub cloudinit_pending_properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub check_type {
|
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)) {
|
if (!defined($value)) {
|
||||||
die "got undefined value\n";
|
die "got undefined value\n";
|
||||||
@ -2106,7 +2108,7 @@ sub check_type {
|
|||||||
return $value if $value =~ m/^(\d+)(\.\d+)?$/;
|
return $value if $value =~ m/^(\d+)(\.\d+)?$/;
|
||||||
die "type check ('number') failed - got '$value'\n";
|
die "type check ('number') failed - got '$value'\n";
|
||||||
} elsif ($type eq 'string') {
|
} elsif ($type eq 'string') {
|
||||||
if (my $fmt = $confdesc->{$key}->{format}) {
|
if (my $fmt = $schema->{$key}->{format}) {
|
||||||
PVE::JSONSchema::check_format($fmt, $value);
|
PVE::JSONSchema::check_format($fmt, $value);
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
@ -2301,7 +2303,7 @@ sub parse_vm_config {
|
|||||||
$conf->{$key} = $value;
|
$conf->{$key} = $value;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
eval { $value = check_type($key, $value); };
|
eval { $value = check_type($key, $value, $confdesc); };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$handle_error->("vm $vmid - unable to parse value of '$key' - $@");
|
$handle_error->("vm $vmid - unable to parse value of '$key' - $@");
|
||||||
} else {
|
} else {
|
||||||
@ -2368,7 +2370,7 @@ sub write_vm_config {
|
|||||||
# fixme: check syntax?
|
# fixme: check syntax?
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
eval { $value = check_type($key, $value); };
|
eval { $value = check_type($key, $value, $confdesc); };
|
||||||
die "unable to parse value of '$key' - $@" if $@;
|
die "unable to parse value of '$key' - $@" if $@;
|
||||||
|
|
||||||
$cref->{$key} = $value;
|
$cref->{$key} = $value;
|
||||||
|
Loading…
Reference in New Issue
Block a user