[virt-tools-list] [virt-manager PATCH 1/2] guest: Default to libosinfo recommended resources
Fabiano Fidêncio
fidencio at redhat.com
Wed Dec 5 08:15:18 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 | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/virtinst/guest.py b/virtinst/guest.py
index eeb40cb6..ced8f259 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -475,11 +475,11 @@ 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 +510,18 @@ class Guest(XMLBuilder):
# Private xml routines #
########################
+ def _set_default_resources(self):
+ res = self.osinfo.get_recommended_resources(self)
+ if not res:
+ return
+
+ if not self.memory and res.get('ram') > 0:
+ self.memory = res['ram'] // 1024
+
+ if not self.vcpus:
+ self.vcpus = res.get('n-cpus') if 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