mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-03-09 08:58:27 +03:00
urldetect: Add a class for libosinfo detection
If an ISO path is used for --location, prioritize asking libosinfo for the os_variant and kernel/initrd paths. This fixes some instances that we lost when GenericDistro was dropped, like using various netinst/boot.isos around Example: https://github.com/virt-manager/virt-manager/pull/39
This commit is contained in:
parent
2b4e1cadf3
commit
665607fdc2
@ -30,6 +30,9 @@ class _DistroCache(object):
|
||||
self.checked_for_suse_content = False
|
||||
self.debian_media_type = None
|
||||
|
||||
self.libosinfo_os_variant = None
|
||||
self.libosinfo_mediaobj = None
|
||||
|
||||
def acquire_file_content(self, path):
|
||||
if path not in self._filecache:
|
||||
try:
|
||||
@ -136,6 +139,23 @@ class _DistroCache(object):
|
||||
def fetcher_is_iso(self):
|
||||
return self._fetcher.is_iso()
|
||||
|
||||
def guess_os_from_iso(self):
|
||||
ret = OSDB.guess_os_by_iso(self._fetcher.location)
|
||||
if not ret:
|
||||
return False
|
||||
|
||||
self.libosinfo_os_variant, self.libosinfo_mediaobj = ret
|
||||
if (not self.libosinfo_mediaobj.get_kernel_path() or
|
||||
not self.libosinfo_mediaobj.get_initrd_path()):
|
||||
# This can happen if the media is live media, or just
|
||||
# with incomplete libosinfo data
|
||||
logging.debug("libosinfo didn't report any media kernel/initrd "
|
||||
"path for detected os_variant=%s",
|
||||
self.libosinfo_mediaobj)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class _SUSEContent(object):
|
||||
"""
|
||||
@ -312,9 +332,14 @@ class _DistroTree(object):
|
||||
self.uri = fetcher.location
|
||||
self.cache = cache
|
||||
|
||||
if self.cache.libosinfo_os_variant:
|
||||
self._os_variant = self.cache.libosinfo_os_variant
|
||||
else:
|
||||
self._os_variant = self._detect_version()
|
||||
|
||||
if self._os_variant and not OSDB.lookup_os(self._os_variant):
|
||||
logging.debug("Detected os_variant as %s, which is not in osdict.",
|
||||
logging.debug("Detected os_variant as %s, which is not "
|
||||
"in osdict.",
|
||||
self._os_variant)
|
||||
self._os_variant = None
|
||||
|
||||
@ -831,6 +856,26 @@ class _GenericTreeinfoDistro(_DistroTree):
|
||||
return False
|
||||
|
||||
|
||||
class _LibosinfoDistro(_DistroTree):
|
||||
"""
|
||||
For ISO media detection that was fully handled by libosinfo
|
||||
"""
|
||||
PRETTY_NAME = "Libosinfo detected"
|
||||
matching_distros = []
|
||||
|
||||
@classmethod
|
||||
def is_valid(cls, cache):
|
||||
if cache.fetcher_is_iso():
|
||||
return cache.guess_os_from_iso()
|
||||
return False
|
||||
|
||||
def _set_manual_kernel_paths(self):
|
||||
self._kernel_paths += [
|
||||
(self.cache.libosinfo_mediaobj.get_kernel_path(),
|
||||
self.cache.libosinfo_mediaobj.get_initrd_path())
|
||||
]
|
||||
|
||||
|
||||
# Build list of all *Distro classes
|
||||
def _build_distro_list():
|
||||
allstores = []
|
||||
@ -840,6 +885,10 @@ def _build_distro_list():
|
||||
obj.PRETTY_NAME):
|
||||
allstores.append(obj)
|
||||
|
||||
# Always stick Libosinfo first, it takes priority
|
||||
allstores.remove(_LibosinfoDistro)
|
||||
allstores.insert(0, _LibosinfoDistro)
|
||||
|
||||
# Always stick GenericDistro at the end, since it's a catchall
|
||||
allstores.remove(_GenericTreeinfoDistro)
|
||||
allstores.append(_GenericTreeinfoDistro)
|
||||
|
Loading…
x
Reference in New Issue
Block a user