[pve-devel] [PATCH qemu-server 2/2] check_type: compare value to defined enum

Stoiko Ivanov s.ivanov at proxmox.com
Tue Dec 4 20:52:47 CET 2018


check_type is invoked while writing the configuration to the cfs, to validate
the config. This patch adds a check, that the value is in the enum for the
key, if such an enum is defined.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PVE/QemuServer.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1832b71..8db4e7e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2438,6 +2438,15 @@ sub check_type {
 	die "property contains a line feed\n";
     }
 
+    if (my $enum_array = $confdesc->{$key}->{enum}) {
+	foreach my $enum_value (@$enum_array) {
+	    if ($value eq $enum_value) {
+		return $value;
+	    }
+	}
+	die "type check ('enum') failed - '$value' is not in the enumeration for $key\n";
+    }
+
     if ($type eq 'boolean') {
 	return 1 if ($value eq '1') || ($value =~ m/^(on|yes|true)$/i);
 	return 0 if ($value eq '0') || ($value =~ m/^(off|no|false)$/i);
-- 
2.11.0





More information about the pve-devel mailing list