]> git.proxmox.com Git - qemu-server.git/commitdiff
config: implement method to calculate derived properties from a config
authorFiona Ebner <f.ebner@proxmox.com>
Tue, 28 Feb 2023 10:54:09 +0000 (11:54 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 8 Jun 2023 15:47:53 +0000 (17:47 +0200)
See the corresponding commit in guest-common for more information.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/QemuConfig.pm

index 051382cd593e52eab2b102b1c0697bf53fab54e6..10e692998e9cdb089273f77a0ce69b262e179c5c 100644 (file)
@@ -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 {