[virt-tools-list] [virt-manager PATCH v2 1/4] guest: Default to libosinfo recommended resources

Fabiano Fidêncio fidencio at redhat.com
Mon Dec 10 09:36:14 UTC 2018


Let's create a new method that defaults to libosinfo's recommended
resources (when they're available) for memory and vcpus.

It'll help us to avoid erroring out whenever virt-install is called
without specifying the memory amount, as the recommended amount of
memory would come from libosinfo.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/guest.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/virtinst/guest.py b/virtinst/guest.py
index eeb40cb6..bd8d6310 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -475,11 +475,10 @@ class Guest(XMLBuilder):
     def set_defaults(self, _guest):
         if not self.uuid:
             self.uuid = util.generate_uuid(self.conn)
-        if not self.vcpus:
-            self.vcpus = 1
 
         self.set_capabilities_defaults()
 
+        self._set_default_resources()
         self._set_default_machine()
         self._set_default_uefi()
 
@@ -510,6 +509,16 @@ class Guest(XMLBuilder):
     # Private xml routines #
     ########################
 
+    def _set_default_resources(self):
+        res = self.osinfo.get_recommended_resources(self)
+
+        if not self.memory and res and res.get('ram') > 0:
+            self.memory = res['ram'] // 1024
+
+        if not self.vcpus:
+            self.vcpus = res.get('n-cpus') if res and res.get('n-cpus') > 0 else 1
+
+
     def _set_default_machine(self):
         if self.os.machine:
             return
-- 
2.19.1




More information about the virt-tools-list mailing list