[virt-tools-list] [PATCH virt-install 2/4] osdict: add get_location()

Fabiano Fidêncio fidencio at redhat.com
Fri Feb 8 15:23:56 UTC 2019


get_location() is a new method that returns the osinfo-db tree URL of an
OS, according to the passed architecture.

This method will need some improvement later on once we start having a
specific set of definitions on osinfo-db about what's the type of the OS
we're dealing with (like Server, Desktop, ...).

For now, the new method returns the first URL found without taking into
the consideration the types speficied above.

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

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 72edc4a6..913eacb6 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -477,5 +477,30 @@ class _OsVariant(object):
 
         return None
 
+    def get_location(self, arch):
+        if not self._os:
+            return None
+
+        treefilter = libosinfo.Filter()
+        treefilter.add_constraint(libosinfo.TREE_PROP_ARCHITECTURE, arch)
+
+        treelist = self._os.get_tree_list()
+        if treelist.get_length() < 1:
+            logging.error(
+                _("%s does not have a URL location"), self.name)
+            return None
+
+        filtered_treelist = treelist.new_filtered(treefilter)
+        if filtered_treelist.get_length() < 1:
+            logging.error(
+                _("%s does not have a URL location for the %s architecture"),
+                  self.name, arch)
+            return None
+
+        # Some distros have more than one URL for a specific architecture,
+        # which is the case for Fedora and different variants (Server,
+        # Workstation). Later on, we'll have to differentiate that and return
+        # the right one.
+        return filtered_treelist.get_nth(0).get_url()
 
 OSDB = _OSDB()
-- 
2.20.1




More information about the virt-tools-list mailing list