Blame SOURCES/virt-manager-osdict-libosinfo-use-minimum-resources-when-recommen.patch

e2df08
From ed2c483cc98a4efc75a5f928ff16d51937337591 Mon Sep 17 00:00:00 2001
e2df08
From: Giuseppe Scrivano <gscrivan@redhat.com>
e2df08
Date: Fri, 12 Sep 2014 10:44:08 +0200
e2df08
Subject: [PATCH] osdict, libosinfo: use "minimum" resources when "recommended"
e2df08
 is missing
e2df08
e2df08
Some OS entries in libosinfo miss the "recommended" resources block.
e2df08
In this case use the "minimum" resources when available.
e2df08
e2df08
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1055588
e2df08
e2df08
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
e2df08
(cherry picked from commit 21319c4232e05dc93815e03ca13e5882b0a88581)
e2df08
---
e2df08
 virtinst/osdict.py | 22 ++++++++++++++++------
e2df08
 1 file changed, 16 insertions(+), 6 deletions(-)
e2df08
e2df08
diff --git a/virtinst/osdict.py b/virtinst/osdict.py
e2df08
index 4277578..f792012 100644
e2df08
--- a/virtinst/osdict.py
e2df08
+++ b/virtinst/osdict.py
e2df08
@@ -505,18 +505,28 @@ class _OsVariantOsInfo(_OSVariant):
e2df08
 
e2df08
     def get_recommended_resources(self, arch):
e2df08
         ret = {}
e2df08
-        def read_resource(resources, arch):
e2df08
+        def read_resource(resources, minimum, arch):
e2df08
+            # If we are reading the "minimum" block, allocate more
e2df08
+            # resources.
e2df08
+            ram_scale = minimum and 2 or 1
e2df08
+            n_cpus_scale = minimum and 2 or 1
e2df08
+            storage_scale = minimum and 2 or 1
e2df08
             for i in range(resources.get_length()):
e2df08
                 r = resources.get_nth(i)
e2df08
                 if r.get_architecture() == arch:
e2df08
-                    ret["ram"] = r.get_ram()
e2df08
+                    ret["ram"] = r.get_ram() * ram_scale
e2df08
                     ret["cpu"] = r.get_cpu()
e2df08
-                    ret["n-cpus"] = r.get_n_cpus()
e2df08
-                    ret["storage"] = r.get_storage()
e2df08
+                    ret["n-cpus"] = r.get_n_cpus() * n_cpus_scale
e2df08
+                    ret["storage"] = r.get_storage() * storage_scale
e2df08
                     break
e2df08
 
e2df08
-        read_resource(self._os.get_recommended_resources(), "all")
e2df08
-        read_resource(self._os.get_recommended_resources(), arch)
e2df08
+        # libosinfo may miss the recommended resources block for some OS,
e2df08
+        # in this case read first the minimum resources (if present)
e2df08
+        # and use them.
e2df08
+        read_resource(self._os.get_minimum_resources(), True, "all")
e2df08
+        read_resource(self._os.get_minimum_resources(), True, arch)
e2df08
+        read_resource(self._os.get_recommended_resources(), False, "all")
e2df08
+        read_resource(self._os.get_recommended_resources(), False, arch)
e2df08
 
e2df08
         return ret
e2df08
 
e2df08
-- 
e2df08
1.9.3
e2df08