2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# List of OS Specific data
|
|
|
|
#
|
2014-09-09 19:37:20 +08:00
|
|
|
# Copyright 2006-2008, 2013-2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-30 03:22:44 +08:00
|
|
|
import datetime
|
2015-04-14 05:05:25 +08:00
|
|
|
import logging
|
2014-09-23 05:20:07 +08:00
|
|
|
import re
|
|
|
|
|
2019-03-06 01:34:51 +08:00
|
|
|
from gi.repository import Libosinfo
|
2014-09-23 05:20:07 +08:00
|
|
|
|
2013-08-11 06:48:43 +08:00
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
###################
|
|
|
|
# Sorting helpers #
|
|
|
|
###################
|
2014-02-17 23:40:01 +08:00
|
|
|
|
2018-09-30 04:04:05 +08:00
|
|
|
def _sortby(osobj):
|
|
|
|
"""
|
|
|
|
Combines distro+version to make a more sort friendly string. Examples
|
|
|
|
|
|
|
|
fedora25 -> fedora-0025000000000000
|
|
|
|
ubuntu17.04 -> ubuntu-0017000400000000
|
|
|
|
win2k8r2 -> win-0006000100000000
|
|
|
|
"""
|
|
|
|
if osobj.is_generic():
|
|
|
|
# Sort generic at the end of the list
|
|
|
|
return "zzzzzz-000000000000"
|
|
|
|
|
|
|
|
version = osobj.version
|
|
|
|
try:
|
|
|
|
t = version.split(".")
|
|
|
|
t = t[:min(4, len(t))] + [0] * (4 - min(4, len(t)))
|
|
|
|
new_version = ""
|
|
|
|
for n in t:
|
|
|
|
new_version = new_version + ("%.4i" % int(n))
|
|
|
|
version = new_version
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return "%s-%s" % (osobj.distro, version)
|
|
|
|
|
2018-10-01 23:37:28 +08:00
|
|
|
|
2018-05-01 19:51:23 +08:00
|
|
|
def _sort(tosort):
|
2013-03-18 05:06:52 +08:00
|
|
|
sortby_mappings = {}
|
|
|
|
distro_mappings = {}
|
|
|
|
retlist = []
|
|
|
|
|
|
|
|
for key, osinfo in tosort.items():
|
2015-04-05 02:13:13 +08:00
|
|
|
# Libosinfo has some duplicate version numbers here, so append .1
|
|
|
|
# if there's a collision
|
2018-09-30 04:04:05 +08:00
|
|
|
sortby = _sortby(osinfo)
|
2014-02-17 23:40:00 +08:00
|
|
|
while sortby_mappings.get(sortby):
|
|
|
|
sortby = sortby + ".1"
|
2013-03-18 05:06:52 +08:00
|
|
|
sortby_mappings[sortby] = key
|
|
|
|
|
2018-09-01 20:41:22 +08:00
|
|
|
# Group by distro first, so debian is clumped together, fedora, etc.
|
|
|
|
distro = osinfo.distro
|
2018-09-30 04:04:05 +08:00
|
|
|
if osinfo.is_generic():
|
|
|
|
distro = "zzzzzz"
|
2013-03-18 05:06:52 +08:00
|
|
|
if distro not in distro_mappings:
|
|
|
|
distro_mappings[distro] = []
|
|
|
|
distro_mappings[distro].append(sortby)
|
|
|
|
|
|
|
|
# We want returned lists to be sorted descending by 'distro', so we get
|
|
|
|
# debian5, debian4, fedora14, fedora13
|
|
|
|
# rather than
|
|
|
|
# debian4, debian5, fedora13, fedora14
|
2017-10-11 19:35:46 +08:00
|
|
|
for distro_list in list(distro_mappings.values()):
|
2013-03-18 05:06:52 +08:00
|
|
|
distro_list.sort()
|
|
|
|
distro_list.reverse()
|
|
|
|
|
2017-10-11 19:35:46 +08:00
|
|
|
sorted_distro_list = list(distro_mappings.keys())
|
2013-03-18 05:06:52 +08:00
|
|
|
sorted_distro_list.sort()
|
|
|
|
|
2015-04-05 02:13:13 +08:00
|
|
|
# Build the final list of sorted os objects
|
2013-03-18 05:06:52 +08:00
|
|
|
for distro in sorted_distro_list:
|
|
|
|
distro_list = distro_mappings[distro]
|
|
|
|
for key in distro_list:
|
|
|
|
orig_key = sortby_mappings[key]
|
2013-08-12 02:52:30 +08:00
|
|
|
retlist.append(tosort[orig_key])
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return retlist
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2019-03-06 05:10:16 +08:00
|
|
|
class _OsinfoIter:
|
|
|
|
"""
|
|
|
|
Helper to turn osinfo style get_length/get_nth lists into python
|
|
|
|
iterables
|
|
|
|
"""
|
|
|
|
def __init__(self, listobj):
|
|
|
|
self.current = 0
|
|
|
|
self.listobj = listobj
|
|
|
|
self.high = self.listobj.get_length() - 1
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
def __next__(self):
|
|
|
|
if self.current > self.high:
|
|
|
|
raise StopIteration
|
|
|
|
ret = self.listobj.get_nth(self.current)
|
|
|
|
self.current += 1
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
class _OSDB(object):
|
|
|
|
"""
|
|
|
|
Entry point for the public API
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
self.__os_loader = None
|
|
|
|
self.__all_variants = None
|
|
|
|
|
|
|
|
# This is only for back compatibility with pre-libosinfo support.
|
|
|
|
# This should never change.
|
|
|
|
_aliases = {
|
2017-08-05 14:39:32 +08:00
|
|
|
"altlinux": "altlinux1.0",
|
|
|
|
"debianetch": "debian4",
|
|
|
|
"debianlenny": "debian5",
|
|
|
|
"debiansqueeze": "debian6",
|
|
|
|
"debianwheezy": "debian7",
|
|
|
|
"freebsd10": "freebsd10.0",
|
|
|
|
"freebsd6": "freebsd6.0",
|
|
|
|
"freebsd7": "freebsd7.0",
|
|
|
|
"freebsd8": "freebsd8.0",
|
|
|
|
"freebsd9": "freebsd9.0",
|
|
|
|
"mandriva2009": "mandriva2009.0",
|
|
|
|
"mandriva2010": "mandriva2010.0",
|
|
|
|
"mbs1": "mbs1.0",
|
|
|
|
"msdos": "msdos6.22",
|
|
|
|
"openbsd4": "openbsd4.2",
|
|
|
|
"opensolaris": "opensolaris2009.06",
|
|
|
|
"opensuse11": "opensuse11.4",
|
|
|
|
"opensuse12": "opensuse12.3",
|
|
|
|
"rhel4": "rhel4.0",
|
|
|
|
"rhel5": "rhel5.0",
|
|
|
|
"rhel6": "rhel6.0",
|
|
|
|
"rhel7": "rhel7.0",
|
|
|
|
"ubuntuhardy": "ubuntu8.04",
|
|
|
|
"ubuntuintrepid": "ubuntu8.10",
|
|
|
|
"ubuntujaunty": "ubuntu9.04",
|
|
|
|
"ubuntukarmic": "ubuntu9.10",
|
|
|
|
"ubuntulucid": "ubuntu10.04",
|
|
|
|
"ubuntumaverick": "ubuntu10.10",
|
|
|
|
"ubuntunatty": "ubuntu11.04",
|
|
|
|
"ubuntuoneiric": "ubuntu11.10",
|
|
|
|
"ubuntuprecise": "ubuntu12.04",
|
|
|
|
"ubuntuquantal": "ubuntu12.10",
|
|
|
|
"ubunturaring": "ubuntu13.04",
|
|
|
|
"ubuntusaucy": "ubuntu13.10",
|
2015-04-05 00:37:46 +08:00
|
|
|
"virtio26": "fedora10",
|
2017-08-05 14:39:32 +08:00
|
|
|
"vista": "winvista",
|
|
|
|
"winxp64": "winxp",
|
2015-04-05 00:04:11 +08:00
|
|
|
|
2015-04-05 00:37:46 +08:00
|
|
|
# Old --os-type values
|
2017-08-05 14:39:32 +08:00
|
|
|
"linux": "generic",
|
|
|
|
"windows": "winxp",
|
|
|
|
"solaris": "solaris10",
|
2015-08-11 01:01:04 +08:00
|
|
|
"unix": "freebsd9.0",
|
2015-04-05 00:37:46 +08:00
|
|
|
"other": "generic",
|
2015-04-05 00:04:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#################
|
|
|
|
# Internal APIs #
|
|
|
|
#################
|
|
|
|
|
|
|
|
def _make_default_variants(self):
|
|
|
|
ret = {}
|
2013-08-11 02:44:20 +08:00
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
# Generic variant
|
|
|
|
v = _OsVariant(None)
|
|
|
|
ret[v.name] = v
|
|
|
|
return ret
|
2013-08-10 06:14:42 +08:00
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
@property
|
|
|
|
def _os_loader(self):
|
|
|
|
if not self.__os_loader:
|
2019-03-06 01:34:51 +08:00
|
|
|
loader = Libosinfo.Loader()
|
2015-04-05 00:04:11 +08:00
|
|
|
loader.process_default_path()
|
|
|
|
|
|
|
|
self.__os_loader = loader
|
|
|
|
return self.__os_loader
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _all_variants(self):
|
|
|
|
if not self.__all_variants:
|
|
|
|
loader = self._os_loader
|
|
|
|
allvariants = self._make_default_variants()
|
|
|
|
db = loader.get_db()
|
|
|
|
oslist = db.get_os_list()
|
2019-03-06 05:10:16 +08:00
|
|
|
for o in _OsinfoIter(oslist):
|
|
|
|
osi = _OsVariant(o)
|
2015-04-05 00:04:11 +08:00
|
|
|
allvariants[osi.name] = osi
|
2013-08-11 06:48:43 +08:00
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
self.__all_variants = allvariants
|
|
|
|
return self.__all_variants
|
|
|
|
|
|
|
|
|
|
|
|
###############
|
|
|
|
# Public APIs #
|
|
|
|
###############
|
|
|
|
|
2018-09-14 03:03:36 +08:00
|
|
|
def lookup_os_by_full_id(self, full_id):
|
|
|
|
for osobj in self._all_variants.values():
|
|
|
|
if osobj.full_id == full_id:
|
|
|
|
return osobj
|
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
def lookup_os(self, key):
|
2018-10-02 19:53:26 +08:00
|
|
|
if key in self._aliases:
|
|
|
|
alias = self._aliases[key]
|
|
|
|
# Added 2018-10-02. Maybe remove aliases in a year
|
|
|
|
logging.warning(
|
|
|
|
_("OS name '%s' is deprecated, using '%s' instead. "
|
2018-11-14 22:58:43 +08:00
|
|
|
"This alias will be removed in the future."), key, alias)
|
2018-10-02 19:53:26 +08:00
|
|
|
key = alias
|
2015-08-11 01:01:04 +08:00
|
|
|
return self._all_variants.get(key)
|
2015-04-05 00:04:11 +08:00
|
|
|
|
2019-01-31 02:01:19 +08:00
|
|
|
def guess_os_by_iso(self, location):
|
|
|
|
try:
|
2019-03-06 01:34:51 +08:00
|
|
|
media = Libosinfo.Media.create_from_location(location, None)
|
2019-01-31 02:01:19 +08:00
|
|
|
except Exception as e:
|
|
|
|
logging.debug("Error creating libosinfo media object: %s", str(e))
|
2015-04-14 05:05:25 +08:00
|
|
|
return None
|
2019-01-31 02:01:19 +08:00
|
|
|
|
2019-02-06 21:21:30 +08:00
|
|
|
if not self._os_loader.get_db().identify_media(media):
|
2019-01-31 02:01:19 +08:00
|
|
|
return None
|
2019-02-06 21:21:30 +08:00
|
|
|
return media.get_os().get_short_id(), media
|
2015-04-05 00:04:11 +08:00
|
|
|
|
2018-05-01 19:51:23 +08:00
|
|
|
def list_os(self):
|
2015-04-05 02:13:13 +08:00
|
|
|
"""
|
|
|
|
List all OSes in the DB
|
|
|
|
"""
|
2015-04-05 00:04:11 +08:00
|
|
|
sortmap = {}
|
|
|
|
|
2015-04-05 02:13:13 +08:00
|
|
|
for name, osobj in self._all_variants.items():
|
|
|
|
sortmap[name] = osobj
|
2015-04-05 00:04:11 +08:00
|
|
|
|
2018-05-01 19:51:23 +08:00
|
|
|
return _sort(sortmap)
|
2015-04-05 00:04:11 +08:00
|
|
|
|
|
|
|
|
2019-03-06 01:16:49 +08:00
|
|
|
OSDB = _OSDB()
|
|
|
|
|
|
|
|
|
2015-04-05 00:04:11 +08:00
|
|
|
#####################
|
|
|
|
# OsVariant classes #
|
|
|
|
#####################
|
2013-08-18 05:53:17 +08:00
|
|
|
|
2015-04-05 00:37:46 +08:00
|
|
|
class _OsVariant(object):
|
2015-04-04 22:44:54 +08:00
|
|
|
def __init__(self, o):
|
|
|
|
self._os = o
|
2015-04-05 00:37:46 +08:00
|
|
|
self._family = self._os and self._os.get_family() or None
|
2014-09-23 05:33:55 +08:00
|
|
|
|
2018-09-14 03:03:36 +08:00
|
|
|
self.full_id = self._os and self._os.get_id() or None
|
2015-04-05 00:37:46 +08:00
|
|
|
self.name = self._os and self._os.get_short_id() or "generic"
|
2018-09-30 04:04:05 +08:00
|
|
|
self.label = self._os and self._os.get_name() or "Generic default"
|
2015-11-25 10:52:06 +08:00
|
|
|
self.codename = self._os and self._os.get_codename() or ""
|
2017-04-24 22:20:40 +08:00
|
|
|
self.distro = self._os and self._os.get_distro() or ""
|
2018-09-30 04:04:05 +08:00
|
|
|
self.version = self._os and self._os.get_version() or None
|
2014-09-23 05:33:55 +08:00
|
|
|
|
2018-09-01 20:14:33 +08:00
|
|
|
self.eol = self._get_eol()
|
2015-04-05 04:08:00 +08:00
|
|
|
|
2018-09-30 04:13:56 +08:00
|
|
|
def __repr__(self):
|
|
|
|
return "<%s name=%s>" % (self.__class__.__name__, self.name)
|
|
|
|
|
2015-04-05 04:08:00 +08:00
|
|
|
|
|
|
|
########################
|
|
|
|
# Internal helper APIs #
|
|
|
|
########################
|
|
|
|
|
|
|
|
def _is_related_to(self, related_os_list, os=None,
|
2017-09-20 15:36:27 +08:00
|
|
|
check_derives=True, check_upgrades=True, check_clones=True):
|
2015-04-05 04:08:00 +08:00
|
|
|
os = os or self._os
|
|
|
|
if not os:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if os.get_short_id() in related_os_list:
|
|
|
|
return True
|
|
|
|
|
|
|
|
check_list = []
|
|
|
|
def _extend(newl):
|
|
|
|
for obj in newl:
|
|
|
|
if obj not in check_list:
|
|
|
|
check_list.append(obj)
|
|
|
|
|
|
|
|
if check_derives:
|
|
|
|
_extend(os.get_related(
|
2019-03-06 01:34:51 +08:00
|
|
|
Libosinfo.ProductRelationship.DERIVES_FROM).get_elements())
|
2015-04-05 04:08:00 +08:00
|
|
|
if check_clones:
|
|
|
|
_extend(os.get_related(
|
2019-03-06 01:34:51 +08:00
|
|
|
Libosinfo.ProductRelationship.CLONES).get_elements())
|
2015-04-05 04:08:00 +08:00
|
|
|
if check_upgrades:
|
|
|
|
_extend(os.get_related(
|
2019-03-06 01:34:51 +08:00
|
|
|
Libosinfo.ProductRelationship.UPGRADES).get_elements())
|
2015-04-05 04:08:00 +08:00
|
|
|
|
|
|
|
for checkobj in check_list:
|
|
|
|
if (checkobj.get_short_id() in related_os_list or
|
|
|
|
self._is_related_to(related_os_list, os=checkobj,
|
|
|
|
check_upgrades=check_upgrades,
|
|
|
|
check_derives=check_derives,
|
|
|
|
check_clones=check_clones)):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2014-02-17 23:40:00 +08:00
|
|
|
|
2018-09-01 23:13:23 +08:00
|
|
|
def _get_all_devices(self):
|
|
|
|
if not self._os:
|
|
|
|
return []
|
2019-03-06 05:10:16 +08:00
|
|
|
return list(_OsinfoIter(self._os.get_all_devices()))
|
2018-09-01 23:13:23 +08:00
|
|
|
|
2018-10-01 23:24:45 +08:00
|
|
|
def _device_filter(self, devids=None, cls=None):
|
2018-09-01 23:13:23 +08:00
|
|
|
ret = []
|
2018-10-01 23:24:45 +08:00
|
|
|
devids = devids or []
|
2018-09-01 23:13:23 +08:00
|
|
|
for dev in self._get_all_devices():
|
2018-10-01 23:24:45 +08:00
|
|
|
if devids and dev.get_id() not in devids:
|
2018-09-01 23:13:23 +08:00
|
|
|
continue
|
|
|
|
if cls and not re.match(cls, dev.get_class()):
|
|
|
|
continue
|
|
|
|
ret.append(dev.get_name())
|
|
|
|
return ret
|
|
|
|
|
2014-09-10 00:39:53 +08:00
|
|
|
|
2015-04-04 22:44:54 +08:00
|
|
|
###############
|
|
|
|
# Cached APIs #
|
|
|
|
###############
|
2014-07-07 06:46:16 +08:00
|
|
|
|
2018-09-01 20:14:33 +08:00
|
|
|
def _get_eol(self):
|
|
|
|
eol = self._os and self._os.get_eol_date() or None
|
|
|
|
rel = self._os and self._os.get_release_date() or None
|
|
|
|
|
2019-02-15 20:28:58 +08:00
|
|
|
# We can use os.get_release_status() & osinfo.ReleaseStatus.ROLLING
|
|
|
|
# if we require libosinfo >= 1.4.0.
|
|
|
|
release_status = self._os and self._os.get_param_value(
|
2019-03-06 01:34:51 +08:00
|
|
|
Libosinfo.OS_PROP_RELEASE_STATUS) or None
|
2019-02-15 20:28:58 +08:00
|
|
|
|
2018-09-30 03:22:44 +08:00
|
|
|
def _glib_to_datetime(glibdate):
|
|
|
|
date = "%s-%s" % (glibdate.get_year(), glibdate.get_day_of_year())
|
|
|
|
return datetime.datetime.strptime(date, "%Y-%j")
|
|
|
|
|
|
|
|
now = datetime.datetime.today()
|
2018-09-01 20:14:33 +08:00
|
|
|
if eol is not None:
|
2018-09-30 03:22:44 +08:00
|
|
|
return now > _glib_to_datetime(eol)
|
|
|
|
|
2019-02-15 20:28:58 +08:00
|
|
|
# Rolling distributions are never EOL.
|
|
|
|
if release_status == "rolling":
|
|
|
|
return False
|
|
|
|
|
2018-09-30 03:22:44 +08:00
|
|
|
# If no EOL is present, assume EOL if release was > 5 years ago
|
|
|
|
if rel is not None:
|
|
|
|
rel5 = _glib_to_datetime(rel) + datetime.timedelta(days=365 * 5)
|
|
|
|
return now > rel5
|
2018-09-01 20:14:33 +08:00
|
|
|
return False
|
|
|
|
|
2014-09-10 00:39:53 +08:00
|
|
|
|
2015-04-04 22:44:54 +08:00
|
|
|
###############
|
|
|
|
# Public APIs #
|
|
|
|
###############
|
|
|
|
|
2019-03-06 00:53:20 +08:00
|
|
|
def get_handle(self):
|
|
|
|
return self._os
|
|
|
|
|
2018-09-30 04:04:05 +08:00
|
|
|
def is_generic(self):
|
|
|
|
return self._os is None
|
|
|
|
|
2015-04-04 22:44:54 +08:00
|
|
|
def is_windows(self):
|
2018-09-01 19:55:19 +08:00
|
|
|
return self._family in ['win9x', 'winnt', 'win16']
|
2015-04-04 22:44:54 +08:00
|
|
|
|
2015-11-04 00:15:26 +08:00
|
|
|
def broken_x2apic(self):
|
|
|
|
# x2apic breaks networking in solaris10
|
|
|
|
# https://bugs.launchpad.net/bugs/1395217
|
2016-03-24 18:09:13 +08:00
|
|
|
return self.name in ('solaris10', 'solaris11')
|
2015-11-04 00:15:26 +08:00
|
|
|
|
2018-09-05 02:43:24 +08:00
|
|
|
def broken_uefi_with_hyperv(self):
|
|
|
|
# Some windows versions are broken with hyperv enlightenments + UEFI
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1185253
|
|
|
|
# https://bugs.launchpad.net/qemu/+bug/1593605
|
|
|
|
return self.name in ("win2k8r2", "win7")
|
|
|
|
|
2015-04-04 22:44:54 +08:00
|
|
|
def get_clock(self):
|
2015-04-05 00:37:46 +08:00
|
|
|
if self.is_windows() or self._family in ['solaris']:
|
|
|
|
return "localtime"
|
2015-04-04 22:44:54 +08:00
|
|
|
return "utc"
|
|
|
|
|
2018-09-01 23:44:36 +08:00
|
|
|
def supported_netmodels(self):
|
|
|
|
return self._device_filter(cls="net")
|
2015-04-04 22:44:54 +08:00
|
|
|
|
2016-07-30 01:17:36 +08:00
|
|
|
def supports_usbtablet(self):
|
2018-09-30 01:34:48 +08:00
|
|
|
# If no OS specified, still default to tablet
|
|
|
|
if not self._os:
|
|
|
|
return True
|
2018-10-01 23:24:45 +08:00
|
|
|
|
|
|
|
devids = ["http://usb.org/usb/80ee/0021"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
2015-04-04 22:44:54 +08:00
|
|
|
|
|
|
|
def supports_virtiodisk(self):
|
2018-10-01 23:24:45 +08:00
|
|
|
# virtio-block and virtio1.0-block
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1001",
|
|
|
|
"http://pcisig.com/pci/1af4/1042"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
2015-04-04 22:44:54 +08:00
|
|
|
|
2019-03-05 00:11:14 +08:00
|
|
|
def supports_virtioscsi(self):
|
|
|
|
# virtio-scsi and virtio1.0-scsi
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1004",
|
|
|
|
"http://pcisig.com/pci/1af4/1048"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
|
|
|
|
2015-04-04 22:44:54 +08:00
|
|
|
def supports_virtionet(self):
|
2018-10-01 23:24:45 +08:00
|
|
|
# virtio-net and virtio1.0-net
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1000",
|
|
|
|
"http://pcisig.com/pci/1af4/1041"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
2015-04-04 22:44:54 +08:00
|
|
|
|
2017-03-09 05:54:16 +08:00
|
|
|
def supports_virtiorng(self):
|
2018-10-01 23:24:45 +08:00
|
|
|
# virtio-rng and virtio1.0-rng
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1005",
|
|
|
|
"http://pcisig.com/pci/1af4/1044"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
2015-04-04 22:44:54 +08:00
|
|
|
|
2018-09-02 01:18:49 +08:00
|
|
|
def supports_virtioserial(self):
|
2018-10-01 23:24:45 +08:00
|
|
|
devids = ["http://pcisig.com/pci/1af4/1003",
|
|
|
|
"http://pcisig.com/pci/1af4/1043"]
|
|
|
|
if self._device_filter(devids=devids):
|
2018-09-02 01:18:49 +08:00
|
|
|
return True
|
2018-10-01 23:39:58 +08:00
|
|
|
# osinfo data was wrong for RHEL/centos here until Oct 2018
|
|
|
|
# Remove this hack after 6 months or so
|
2018-09-02 01:18:49 +08:00
|
|
|
return self._is_related_to("rhel6.0")
|
|
|
|
|
2019-03-20 23:52:34 +08:00
|
|
|
def supports_virtioinput(self):
|
|
|
|
# virtio1.0-input
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1052"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
|
|
|
|
2018-10-04 06:53:16 +08:00
|
|
|
def supports_usb3(self):
|
|
|
|
# qemu-xhci
|
|
|
|
devids = ["http://pcisig.com/pci/1b36/0004"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
|
|
|
|
2018-10-05 02:59:54 +08:00
|
|
|
def supports_virtio1(self):
|
|
|
|
# Use virtio1.0-net device as a proxy for virtio1.0 as a whole
|
|
|
|
devids = ["http://pcisig.com/pci/1af4/1041"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
|
|
|
|
2018-09-13 02:49:10 +08:00
|
|
|
def supports_chipset_q35(self):
|
2018-10-05 02:59:54 +08:00
|
|
|
# For our purposes, check for the union of q35 + virtio1.0 support
|
|
|
|
if self.supports_virtionet() and not self.supports_virtio1():
|
|
|
|
return False
|
|
|
|
devids = ["http://qemu.org/chipset/x86/q35"]
|
|
|
|
return bool(self._device_filter(devids=devids))
|
2018-09-13 02:49:10 +08:00
|
|
|
|
2014-09-24 05:09:36 +08:00
|
|
|
def get_recommended_resources(self, guest):
|
2014-02-17 23:40:04 +08:00
|
|
|
ret = {}
|
2015-04-05 02:13:13 +08:00
|
|
|
if not self._os:
|
|
|
|
return ret
|
|
|
|
|
2014-09-12 16:44:08 +08:00
|
|
|
def read_resource(resources, minimum, arch):
|
|
|
|
# If we are reading the "minimum" block, allocate more
|
|
|
|
# resources.
|
|
|
|
ram_scale = minimum and 2 or 1
|
|
|
|
n_cpus_scale = minimum and 2 or 1
|
|
|
|
storage_scale = minimum and 2 or 1
|
2019-03-06 05:10:16 +08:00
|
|
|
for r in _OsinfoIter(resources):
|
2014-02-17 23:40:04 +08:00
|
|
|
if r.get_architecture() == arch:
|
2014-09-12 16:44:08 +08:00
|
|
|
ret["ram"] = r.get_ram() * ram_scale
|
2014-02-17 23:40:04 +08:00
|
|
|
ret["cpu"] = r.get_cpu()
|
2014-09-12 16:44:08 +08:00
|
|
|
ret["n-cpus"] = r.get_n_cpus() * n_cpus_scale
|
|
|
|
ret["storage"] = r.get_storage() * storage_scale
|
2014-02-17 23:40:04 +08:00
|
|
|
break
|
|
|
|
|
2014-09-12 16:44:08 +08:00
|
|
|
# libosinfo may miss the recommended resources block for some OS,
|
|
|
|
# in this case read first the minimum resources (if present)
|
|
|
|
# and use them.
|
|
|
|
read_resource(self._os.get_minimum_resources(), True, "all")
|
2014-09-24 05:09:36 +08:00
|
|
|
read_resource(self._os.get_minimum_resources(), True, guest.os.arch)
|
2014-09-12 16:44:08 +08:00
|
|
|
read_resource(self._os.get_recommended_resources(), False, "all")
|
2014-09-24 05:09:36 +08:00
|
|
|
read_resource(self._os.get_recommended_resources(),
|
|
|
|
False, guest.os.arch)
|
|
|
|
|
2015-04-05 02:13:13 +08:00
|
|
|
# QEMU TCG doesn't gain anything by having extra VCPUs
|
|
|
|
if guest.type == "qemu":
|
2014-09-24 05:09:36 +08:00
|
|
|
ret["n-cpus"] = 1
|
2014-02-17 23:40:04 +08:00
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2019-02-01 06:11:39 +08:00
|
|
|
def get_kernel_url_arg(self):
|
|
|
|
"""
|
|
|
|
Kernel argument name the distro's installer uses to reference
|
|
|
|
a network source, possibly bypassing some installer prompts
|
|
|
|
"""
|
|
|
|
if not self._os:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# SUSE distros
|
|
|
|
if self.distro in ["caasp", "sle", "sled", "sles", "opensuse"]:
|
|
|
|
return "install"
|
|
|
|
|
|
|
|
if self.distro not in ["centos", "rhel", "fedora"]:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Red Hat distros
|
|
|
|
if self.name.endswith("-unknown"):
|
|
|
|
return "inst.repo"
|
|
|
|
|
|
|
|
try:
|
|
|
|
version = float(self.version)
|
|
|
|
except Exception:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if self.distro in ["centos", "rhel"]:
|
|
|
|
if version < 7:
|
|
|
|
return "method"
|
|
|
|
return "inst.repo"
|
|
|
|
|
|
|
|
if self.distro in ["fedora"]:
|
|
|
|
if version < 19:
|
|
|
|
return "method"
|
|
|
|
return "inst.repo"
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2019-02-08 23:23:56 +08:00
|
|
|
def get_location(self, arch):
|
2019-03-06 05:10:16 +08:00
|
|
|
treelist = []
|
2019-03-06 02:59:17 +08:00
|
|
|
if self._os:
|
2019-03-06 05:10:16 +08:00
|
|
|
treelist = list(_OsinfoIter(self._os.get_tree_list()))
|
2019-03-06 02:59:17 +08:00
|
|
|
|
2019-03-06 05:10:16 +08:00
|
|
|
if not treelist:
|
2019-03-06 02:59:17 +08:00
|
|
|
raise RuntimeError(
|
2019-03-09 06:26:00 +08:00
|
|
|
_("OS '%s' does not have a URL location") % self.name)
|
2019-02-08 23:23:56 +08:00
|
|
|
|
|
|
|
# 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.
|
2019-03-06 05:10:16 +08:00
|
|
|
for tree in treelist:
|
|
|
|
if tree.get_architecture() == arch:
|
|
|
|
return tree.get_url()
|
|
|
|
|
|
|
|
raise RuntimeError(
|
2019-03-09 06:26:00 +08:00
|
|
|
_("OS '%s' does not have a URL location for the %s architecture") %
|
2019-03-06 05:10:16 +08:00
|
|
|
(self.name, arch))
|
2019-02-01 06:11:39 +08:00
|
|
|
|
2019-03-07 20:52:56 +08:00
|
|
|
def get_install_script(self, profile, media=None):
|
2019-03-07 20:52:55 +08:00
|
|
|
def _get_install_script(script_list):
|
|
|
|
if not script_list:
|
|
|
|
raise RuntimeError(
|
2019-03-09 06:26:00 +08:00
|
|
|
_("OS '%s' does not support unattended installation.") %
|
2019-03-07 20:52:55 +08:00
|
|
|
self.name)
|
|
|
|
|
|
|
|
installscripts = []
|
|
|
|
profile_names = set()
|
|
|
|
for script in script_list:
|
|
|
|
profile_names.add(script.get_profile())
|
|
|
|
if script.get_profile() == profile:
|
|
|
|
installscripts.append(script)
|
|
|
|
|
|
|
|
if not installscripts:
|
|
|
|
raise RuntimeError(
|
2019-03-09 06:26:00 +08:00
|
|
|
_("OS '%s' does not support unattended installation for "
|
|
|
|
"the '%s' profile. Available profiles: %s") %
|
2019-03-07 20:52:55 +08:00
|
|
|
(self.name, profile, ", ".join(list(profile_names))))
|
|
|
|
|
|
|
|
logging.debug("Install script found for profile '%s'", profile)
|
|
|
|
|
|
|
|
# Some OSes (as Windows) have more than one installer script,
|
2019-03-19 00:48:40 +08:00
|
|
|
# depending on the OS version and profile chosen, to be used to
|
2019-03-07 20:52:55 +08:00
|
|
|
# perform the unattended installation. Let's just deal with
|
|
|
|
# multiple installer scripts when its actually needed, though.
|
|
|
|
return installscripts[0]
|
|
|
|
|
2019-03-06 05:19:50 +08:00
|
|
|
script_list = []
|
2019-03-07 20:52:57 +08:00
|
|
|
|
|
|
|
# In case we're dealing with a media installation, let's try to get
|
|
|
|
# the installer scripts from the media, in case any is set.
|
|
|
|
if media:
|
|
|
|
if not media.supports_installer_script():
|
|
|
|
raise RuntimeError(
|
2019-03-09 06:26:00 +08:00
|
|
|
_("OS '%s' media does not support unattended "
|
2019-03-07 20:52:57 +08:00
|
|
|
"installation") % (self.name))
|
|
|
|
|
|
|
|
script_list = list(_OsinfoIter(media.get_install_script_list()))
|
|
|
|
|
|
|
|
# In case some script is set, but not one matching the specified
|
|
|
|
# profile, let's just error out as trying to use the OS' installer
|
|
|
|
# is too much error prone.
|
|
|
|
# However, if no script is found, let's just follow with the
|
|
|
|
# current code path and get the script from the installer, as some
|
|
|
|
# OSes only have the installer scripts set to the Libosinfo.Os
|
|
|
|
# itself.
|
|
|
|
if script_list:
|
|
|
|
installscript = _get_install_script(script_list)
|
|
|
|
return installscript
|
|
|
|
|
2019-03-06 02:59:17 +08:00
|
|
|
if self._os:
|
2019-03-06 05:19:50 +08:00
|
|
|
script_list = list(_OsinfoIter(self._os.get_install_script_list()))
|
2019-02-22 16:40:09 +08:00
|
|
|
|
2019-03-07 20:52:55 +08:00
|
|
|
installscript = _get_install_script(script_list)
|
2019-03-06 00:53:20 +08:00
|
|
|
return installscript
|