Blob Blame History Raw
From ed2c483cc98a4efc75a5f928ff16d51937337591 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Fri, 12 Sep 2014 10:44:08 +0200
Subject: [PATCH] osdict, libosinfo: use "minimum" resources when "recommended"
 is missing

Some OS entries in libosinfo miss the "recommended" resources block.
In this case use the "minimum" resources when available.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1055588

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
(cherry picked from commit 21319c4232e05dc93815e03ca13e5882b0a88581)
---
 virtinst/osdict.py | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 4277578..f792012 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -505,18 +505,28 @@ class _OsVariantOsInfo(_OSVariant):
 
     def get_recommended_resources(self, arch):
         ret = {}
-        def read_resource(resources, arch):
+        def read_resource(resources, minimum, arch):
+            # If we are reading the "minimum" block, allocate more
+            # resources.
+            ram_scale = minimum and 2 or 1
+            n_cpus_scale = minimum and 2 or 1
+            storage_scale = minimum and 2 or 1
             for i in range(resources.get_length()):
                 r = resources.get_nth(i)
                 if r.get_architecture() == arch:
-                    ret["ram"] = r.get_ram()
+                    ret["ram"] = r.get_ram() * ram_scale
                     ret["cpu"] = r.get_cpu()
-                    ret["n-cpus"] = r.get_n_cpus()
-                    ret["storage"] = r.get_storage()
+                    ret["n-cpus"] = r.get_n_cpus() * n_cpus_scale
+                    ret["storage"] = r.get_storage() * storage_scale
                     break
 
-        read_resource(self._os.get_recommended_resources(), "all")
-        read_resource(self._os.get_recommended_resources(), arch)
+        # libosinfo may miss the recommended resources block for some OS,
+        # in this case read first the minimum resources (if present)
+        # and use them.
+        read_resource(self._os.get_minimum_resources(), True, "all")
+        read_resource(self._os.get_minimum_resources(), True, arch)
+        read_resource(self._os.get_recommended_resources(), False, "all")
+        read_resource(self._os.get_recommended_resources(), False, arch)
 
         return ret
 
-- 
1.9.3