summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/xmlconfig.py14
-rw-r--r--virtinst/guest.py10
-rw-r--r--virtinst/osdict.py6
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
index a7e73b13..047e9603 100644
--- a/tests/xmlconfig.py
+++ b/tests/xmlconfig.py
@@ -225,6 +225,20 @@ class TestXMLMisc(unittest.TestCase):
xml2 = g.get_xml()
self.assertEqual(xml1, xml2)
+ def test_guest_osinfo_metadata(self):
+ g = _make_guest()
+ self.assertEqual(g.osinfo.name, "generic")
+ g.set_os_name("fedora17")
+ self.assertEqual(g.osinfo.name, "fedora17")
+
+ g = _make_guest()
+ g._metadata.libosinfo.os_id = "http://fedoraproject.org/fedora/20" # pylint: disable=protected-access
+ self.assertEqual(g.osinfo.name, "fedora20")
+
+ g = _make_guest()
+ g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
+ self.assertEqual(g.osinfo.name, "generic")
+
def test_dir_searchable(self):
# Normally the dir searchable test is skipped in the unittest,
# but let's contrive an example that should trigger all the code
diff --git a/virtinst/guest.py b/virtinst/guest.py
index 65cc7df0..ee509542 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -241,6 +241,16 @@ class Guest(XMLBuilder):
##############################
def _get_osinfo(self):
+ if self.__osinfo:
+ return self.__osinfo
+
+ os_id = self._metadata.libosinfo.os_id
+ if os_id:
+ self.__osinfo = OSDB.lookup_os_by_full_id(os_id)
+ if not self.__osinfo:
+ logging.debug("XML had libosinfo os id=%s but we didn't "
+ "find any libosinfo object matching that", os_id)
+
if not self.__osinfo:
self.set_os_name("generic")
return self.__osinfo
diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 5ccb1164..a1717a15 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -159,6 +159,11 @@ class _OSDB(object):
# Public APIs #
###############
+ def lookup_os_by_full_id(self, full_id):
+ for osobj in self._all_variants.values():
+ if osobj.full_id == full_id:
+ return osobj
+
def lookup_os(self, key):
key = self._aliases.get(key) or key
return self._all_variants.get(key)
@@ -211,6 +216,7 @@ class _OsVariant(object):
self._os = o
self._family = self._os and self._os.get_family() or None
+ self.full_id = self._os and self._os.get_id() or None
self.name = self._os and self._os.get_short_id() or "generic"
self.label = self._os and self._os.get_name() or "Generic"
self.codename = self._os and self._os.get_codename() or ""