[virt-tools-list] [PATCH virt-install 2/4] osdict: add get_location()
Cole Robinson
crobinso at redhat.com
Mon Feb 18 17:47:41 UTC 2019
On 2/8/19 10:23 AM, Fabiano Fidêncio wrote:
> 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()
>
Since this is part of the library portion of the code, it's better to
throw an exception rather than log an error so callers (virt-install,
but later virt-manager) can handle it how they choose. I'll add a follow
up patch that makes this change.
Thanks,
Cole
More information about the virt-tools-list
mailing list