Skip to content
Snippets Groups Projects
Commit 43cf3240 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add OS version numbers in SORTORDER computation

The SORTORDER is computed like this: ODDHHLL
O: OS type
D: Distribution
H: Version high
L: Version low
parent 953da9dd
No related branches found
No related tags found
No related merge requests found
......@@ -27,44 +27,6 @@ import hashlib
from sendfile import sendfile
OSTYPE_ORDER = {
"windows": 8000,
"linux": 7000,
"freebsd": 6000,
"netbsd": 5000,
"openbsd": 4000,
"hurd": 3000,
"dos": 2000,
"minix": 1000,
"unknown": 0
}
DISTRO_ORDER = {
"rhel": 590,
"sles": 580,
"oraclelinux": 570,
"scientificlinux": 560,
"linuxmint": 490,
"ubuntu": 480,
"debian": 470,
"fedora": 460,
"centos": 450,
"opensuse": 440,
"archlinux": 430,
"gentoo": 420,
"mageia": 410,
"slackware": 400,
"mandriva": 390,
"cirros": 200,
"pardus": 190,
"redhat-based": 180,
"suse-based": 170,
"meego": 160,
"buildroot": 150,
"ttylinux": 140,
}
class Image(object):
"""The instances of this class can create images out of block devices."""
......@@ -146,12 +108,6 @@ class Image(object):
'found a(n) %s system' %
self.ostype if self.distro == "unknown" else self.distro)
self.meta['SORTORDER'] = OSTYPE_ORDER[self.ostype]
try:
self.meta['SORTORDER'] += DISTRO_ORDER[self.distro]
except KeyError:
pass
# Inspect the OS
self.os.inspect()
......
......@@ -26,6 +26,17 @@ import re
from collections import namedtuple
from functools import wraps
OSTYPE_ORDER = {
"windows": 8,
"linux": 7,
"freebsd": 6,
"netbsd": 5,
"openbsd": 4,
"hurd": 3,
"dos": 2,
"minix": 1
}
def os_cls(distro, osfamily):
"""Given the distro name and the osfamily, return the appropriate OSBase
......@@ -570,12 +581,17 @@ class OSBase(object):
self.out.warn("Unable to identify the partition number from root "
"partition: %s" % self.root)
self.meta['OSFAMILY'] = self.image.g.inspect_get_type(self.root)
self.meta['OS'] = self.image.g.inspect_get_distro(self.root)
if self.meta['OS'] == "unknown":
self.meta['OS'] = self.meta['OSFAMILY']
self.meta['DESCRIPTION'] = \
self.image.g.inspect_get_product_name(self.root)
osfamily = self.image.g.inspect_get_type(self.root)
distro = self.image.g.inspect_get_distro(self.root)
name = self.image.g.inspect_get_product_name(self.root)
self.meta['OSFAMILY'] = osfamily
self.meta['OS'] = distro if distro != "unknown" else osfamily
self.meta['DESCRIPTION'] = name
try:
self.meta['SORTORDER'] = 1000000 * OSTYPE_ORDER[osfamily]
except KeyError:
self.meta['SORTORDER'] = 0
def _do_mount(self, readonly):
"""helper method for mount"""
......
......@@ -36,6 +36,26 @@ X2GO_DESKTOPSESSIONS = {
X2GO_EXECUTABLE = "x2goruncommand"
DISTRO_ORDER = {
"ubuntu": 80,
"linuxmint": 75,
"debian": 70,
"rhel": 60,
"fedora": 58,
"centos": 55,
"scientificlinux": 50,
"sles": 45,
"opensuse": 44,
"archlinux": 40,
"gentoo": 35,
"slackware": 30,
"oraclelinux": 28,
"mageia": 20,
"mandriva": 19,
"cirros": 15,
"pardus": 10
}
class Linux(Unix):
"""OS class for Linux"""
......@@ -331,6 +351,19 @@ class Linux(Unix):
kernels.sort(key=lambda x: pkg_resources.parse_version(x))
self.meta['KERNEL'] = kernels[-1]
distro = self.image.g.inspect_get_distro(self.root)
major = self.image.g.inspect_get_major_version(self.root)
if major > 99:
major = 99
minor = self.image.g.inspect_get_minor_version(self.root)
if minor > 99:
minor = 99
try:
self.meta['SORTORDER'] += \
10000 * DISTRO_ORDER[distro] + 100 * major + minor
except KeyError:
pass
if self.is_enabled('sshd'):
ssh = []
opts = self.ssh_connection_options(users)
......
......@@ -718,9 +718,11 @@ class Windows(OSBase):
else:
self.meta['REMOTE_CONNECTION'] += "rdp:port=%d" % port
self.meta["KERNEL"] = "Windows NT %d.%d" % \
(guestfs.inspect_get_major_version(self.root),
guestfs.inspect_get_minor_version(self.root))
major = self.image.g.inspect_get_major_version(self.root)
minor = self.image.g.inspect_get_minor_version(self.root)
self.meta["KERNEL"] = "Windows NT %d.%d" % (major, minor)
self.meta['SORTORDER'] += (100 * major + minor) * 100
def _check_connectivity(self):
"""Check if winexe works on the Windows VM"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment