Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: start integrating with libosinfo for URLs #247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions oz/Debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Debian: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "debian%s" % update
6 changes: 6 additions & 0 deletions oz/Fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Fedora: " + ", ".join(sorted(version_to_config.keys(), key=int))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "fedora%s" % update
6 changes: 6 additions & 0 deletions oz/FedoraCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Fedora Core: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "fedora%s" % update
6 changes: 6 additions & 0 deletions oz/FreeBSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "FreeBSD: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "freebsd%s" % update
18 changes: 18 additions & 0 deletions oz/GuestFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,21 @@ def distrolist():

strings.sort()
print('\n'.join(strings))

def get_osinfo(distro, update):
"""
Function to return the appropriate libosinfo short ID for the specified
distribution, if possible (hence None can be returned as well).
The arguments are:

distro - The distribution name.
update - The version of the specified distribution.
"""

importname = os_dict.get(distro, None)
if importname:
# we found the matching module; import and call the get_osinfo method
module = __import__('oz.' + importname)
return getattr(module, importname).get_osinfo(distro, update)

return None
6 changes: 6 additions & 0 deletions oz/Mageia.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Mageia: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "mageia%s" % update
6 changes: 6 additions & 0 deletions oz/Mandrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Mandrake: " + ", ".join(sorted(version_to_config.keys(), key=float))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "mandrake%s" % update
6 changes: 6 additions & 0 deletions oz/Mandriva.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Mandriva: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "mandriva%s" % update
6 changes: 6 additions & 0 deletions oz/OpenSUSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "OpenSUSE: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "opensuse%s" % update
10 changes: 10 additions & 0 deletions oz/RHEL_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL 2.1: " + ", ".join(versions)

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if update == 'GOLD':
return "rhel2.1"
if update[0] == 'U':
return "rhel2.1.%s" % update[1:]
return None
11 changes: 11 additions & 0 deletions oz/RHEL_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,14 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL/CentOS 3: " + ", ".join(versions)

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if distro == "RHEL-3":
if update == 'GOLD':
return "rhel3"
if update[0] == 'U':
return "rhel3.%s" % update[1:]
return None
11 changes: 11 additions & 0 deletions oz/RHEL_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,14 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL/CentOS/Scientific Linux 4: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if distro == "RHEL-4":
if update == 'GOLD':
return "rhel4.0"
if update[0] == 'U':
return "rhel4.%s" % update[1:]
return None
11 changes: 11 additions & 0 deletions oz/RHEL_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,14 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL/OL/CentOS/Scientific Linux{,CERN} 5: " + ", ".join(sorted(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if distro == "RHEL-5":
if update == 'GOLD':
return "rhel5.0"
if update[0] == 'U':
return "rhel5.%s" % update[1:]
return None
14 changes: 14 additions & 0 deletions oz/RHEL_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL/OL/CentOS/Scientific Linux{,CERN} 6"

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if update.isdigit():
verstring = "6.%s" % update
else:
verstring = "6.0"
if distro == "RHEL-6":
return "rhel%s" % verstring
if distro == "CentOS-6":
return "centos%s" % verstring
return None
14 changes: 14 additions & 0 deletions oz/RHEL_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHEL 7"

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if distro == "RHEL-7":
if update.isdigit():
verstring = "7.%s" % update
else:
verstring = "7.0"
return "rhel%s" % verstring
if distro == "CentOS-7":
return "centos7.0"
return None
10 changes: 10 additions & 0 deletions oz/RHL.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,13 @@ def get_supported_string():
Return supported versions as a string.
"""
return "RHL: 7.0, 7.1, 7.2, 7.3, 8, 9"

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
if update == "8":
return "rhl8.0"
if update == "7.0":
return "rhl7"
return "rhl%s" % update
84 changes: 82 additions & 2 deletions oz/TDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
import StringIO
except ImportError:
from io import StringIO
try:
import gi
gi.require_version('Libosinfo', '1.0')
from gi.repository import Libosinfo as libosinfo
libosinfo_available = True
except ImportError:
libosinfo_available = False

import lxml.etree

Expand Down Expand Up @@ -96,6 +103,27 @@ def data_from_type(name, contenttype, content):

return out

def _osinfo_os_from_short_id(short_id):
"""
Function to get the libosinfo OS from the short ID specified as argument.
The list of available libosinfo OSes is cached.
"""
if not _osinfo_os_from_short_id.oses:
loader = libosinfo.Loader()
loader.process_default_path()
db = loader.get_db()
_osinfo_os_from_short_id.oses = db.get_os_list()
f = libosinfo.Filter()
f.add_constraint("short-id", short_id)
elems = _osinfo_os_from_short_id.oses.new_filtered(f).get_elements()
num_elems = len(elems)
if num_elems == 0:
raise oz.OzException.OzException("osinfo OS for short ID '%s' not found" % (short_id))
elif num_elems > 1:
raise oz.OzException.OzException("More than 1 osinfo OS for short ID '%s' found (%d found)" % (short_id, num_elems))
return elems[0]
_osinfo_os_from_short_id.oses = None

class Repository(object):
"""
Class that represents a single repository to be used for installing
Expand Down Expand Up @@ -213,6 +241,14 @@ def __init__(self, xmlstring, rootpw_required=False):
optional=True)
# key is not required, so it is not fatal if it is None

self.osinfo_id = _xml_get_value(self.doc, '/template/os/osinfo',
'osinfo-db short ID', optional=True)
self.osinfo_variant = _xml_get_value(self.doc, '/template/os/variant',
'osinfo-db variant', optional=True)
if not self.osinfo_id:
self.osinfo_id = oz.GuestFactory.get_osinfo(self.distro, self.update)
# osinfo and variant are not required, so it is not fatal if they are None

self.description = _xml_get_value(self.doc, '/template/description',
'description', optional=True)
# description is not required, so it is not fatal if it is None
Expand All @@ -235,10 +271,33 @@ def __init__(self, xmlstring, rootpw_required=False):

if self.installtype == "url":
self.url = _xml_get_value(self.doc, '/template/os/install/url',
'OS install URL')
'OS install URL',
optional=libosinfo_available)
# if self.url is none, it means libosinfo is available
if not self.url:
if not self.osinfo_id:
raise oz.OzException.OzException("Missing <osinfo>")
osos = _osinfo_os_from_short_id(self.osinfo_id)
osfilter = libosinfo.Filter()
osfilter.add_constraint('architecture', self.arch)
if self.osinfo_variant:
osfilter.add_constraint('variant', self.osinfo_variant)
tree_list = osos.get_tree_list()
trees = tree_list.new_filtered(osfilter).get_elements()
num_trees = len(trees)
if num_trees == 0:
raise oz.OzException.OzException("osinfo OS '%s' has no install tree" % (self.osinfo_id))
elif num_trees > 1:
raise oz.OzException.OzException("More than 1 install tree for osinfo OS '%s' found (%d found)" % (self.osinfo_id, num_trees))
tree = trees[0]
url = tree.get_url()
if not url:
raise oz.OzException.OzException("osinfo OS '%s' has no URL for the install tree" % (self.osinfo_id))
self.url = url
elif self.installtype == "iso":
self.iso = _xml_get_value(self.doc, '/template/os/install/iso',
'OS install ISO')
'OS install ISO',
optional=libosinfo_available)
self.iso_md5_url = _xml_get_value(self.doc,
'/template/os/install/md5sum',
'OS install ISO MD5SUM',
Expand All @@ -255,6 +314,27 @@ def __init__(self, xmlstring, rootpw_required=False):
# if multiple are
if (self.iso_md5_url and self.iso_sha1_url) or (self.iso_md5_url and self.iso_sha256_url) or (self.iso_sha1_url and self.iso_sha256_url):
raise oz.OzException.OzException("Only one of <md5sum>, <sha1sum>, and <sha256sum> can be specified")
# if self.iso is none, it means libosinfo is available
if not self.iso:
if not self.osinfo_id:
raise oz.OzException.OzException("Missing <osinfo>")
osos = _osinfo_os_from_short_id(self.osinfo_id)
osfilter = libosinfo.Filter()
osfilter.add_constraint('architecture', self.arch)
if self.osinfo_variant:
osfilter.add_constraint('variant', self.osinfo_variant)
media_list = osos.get_media_list()
media = media_list.new_filtered(osfilter).get_elements()
num_media = len(media)
if num_media == 0:
raise oz.OzException.OzException("osinfo OS '%s' has no install media" % (self.osinfo_id))
elif num_media > 1:
raise oz.OzException.OzException("More than 1 install media for osinfo OS '%s' found (%d found)" % (self.osinfo_id, num_media))
medium = media[0]
url = medium.get_url()
if not url:
raise oz.OzException.OzException("osinfo OS '%s' has no URL for the install media" % (self.osinfo_id))
self.iso = url
else:
raise oz.OzException.OzException("Unknown install type " + self.installtype + " in TDL")

Expand Down
6 changes: 6 additions & 0 deletions oz/Ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,3 +1231,9 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Ubuntu: " + ", ".join(reversed(version_to_config.keys()))

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
return "ubuntu%s" % '.'.join(update.split('.')[:2])
18 changes: 18 additions & 0 deletions oz/Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,21 @@ def get_supported_string():
Return supported versions as a string.
"""
return "Windows: 2000, XP, 2003, 7, 2008, 2012, 8, 8.1, 2016, 10"

def get_osinfo(distro, update):
"""
Return the libosinfo short ID.
"""
winids = {
"2000": "win2k",
"XP": "winxp",
"2003": "win2k3",
"2008": "win2k8",
"7": "win7",
"2012": "win2k12",
"8": "win8",
"8.1": "win8.1",
"2016": "win2k16",
"10": "win10",
}
return winids.get(update)
Loading