[pve-devel] [PATCH qemu-server 1/1] config: implement method to calculate derived properties from a config

Fiona Ebner f.ebner at proxmox.com
Tue Feb 28 11:54:09 CET 2023


See the corresponding commit in guest-common for more information.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 PVE/QemuConfig.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 051382cd..10e69299 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -540,6 +540,22 @@ sub load_current_config {
     return $conf;
 }
 
+sub get_derived_property {
+    my ($class, $conf, $name) = @_;
+
+    my $defaults = PVE::QemuServer::load_defaults();
+
+    if ($name eq 'max-cpu') {
+	my $cpus =
+	    ($conf->{sockets} || $defaults->{sockets}) * ($conf->{cores} || $defaults->{cores});
+	return $conf->{vcpus} || $cpus;
+    } elsif ($name eq 'max-memory') {
+	return ($conf->{memory} || $defaults->{memory}) * 1024 * 1024;
+    } else {
+	die "unknown derived property - $name\n";
+    }
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
-- 
2.30.2






More information about the pve-devel mailing list