2013-03-18 01:06:52 +04:00
#
# List of OS Specific data
#
2013-10-28 00:59:46 +04:00
# Copyright 2006-2008, 2013 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
# Jeremy Katz <katzj@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2013-10-28 00:59:47 +04:00
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2013-03-18 01:06:52 +04:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2013-08-11 02:48:43 +04:00
_SENTINEL = - 1234
_allvariants = { }
2014-02-17 19:40:00 +04:00
from datetime import datetime
from gi . repository import Libosinfo as libosinfo
2013-08-11 02:48:43 +04:00
def lookup_os ( key ) :
ret = _allvariants . get ( key )
if ret is None :
return ret
return ret
2013-04-13 22:34:52 +04:00
2013-08-11 22:52:30 +04:00
def _sort ( tosort , sortpref = None ) :
2013-03-18 01:06:52 +04:00
sortby_mappings = { }
distro_mappings = { }
retlist = [ ]
sortpref = sortpref or [ ]
# Make sure we are sorting by 'sortby' if specified, and group distros
# by their 'distro' tag first and foremost
for key , osinfo in tosort . items ( ) :
2013-08-11 22:52:30 +04:00
sortby = osinfo . sortby or key
2014-02-17 19:40:00 +04:00
# Hack to allow "sortby" duplicates. Remove when this never happens
# with libosinfo
while sortby_mappings . get ( sortby ) :
sortby = sortby + " .1 "
2013-03-18 01:06:52 +04:00
sortby_mappings [ sortby ] = key
2013-09-27 01:44:30 +04:00
distro = osinfo . urldistro or " zzzzzzz "
2013-03-18 01:06:52 +04: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
for distro_list in distro_mappings . values ( ) :
distro_list . sort ( )
distro_list . reverse ( )
sorted_distro_list = distro_mappings . keys ( )
sorted_distro_list . sort ( )
sortpref . reverse ( )
for prefer in sortpref :
if not prefer in sorted_distro_list :
continue
sorted_distro_list . remove ( prefer )
sorted_distro_list . insert ( 0 , prefer )
for distro in sorted_distro_list :
distro_list = distro_mappings [ distro ]
for key in distro_list :
orig_key = sortby_mappings [ key ]
2013-08-11 22:52:30 +04:00
retlist . append ( tosort [ orig_key ] )
2013-03-18 01:06:52 +04:00
return retlist
2013-04-13 22:34:52 +04:00
2013-08-11 22:52:30 +04:00
def list_os ( list_types = False , typename = None ,
filtervars = None , only_supported = False ,
* * kwargs ) :
sortmap = { }
filtervars = filtervars or [ ]
for key , osinfo in _allvariants . items ( ) :
if list_types and not osinfo . is_type :
continue
if not list_types and osinfo . is_type :
continue
if typename and typename != osinfo . typename :
continue
if filtervars and osinfo . name not in filtervars :
continue
if only_supported and not osinfo . supported :
continue
sortmap [ key ] = osinfo
return _sort ( sortmap , * * kwargs )
2013-08-18 01:53:17 +04:00
def lookup_osdict_key ( variant , key , default ) :
val = _SENTINEL
2013-08-11 23:29:31 +04:00
if variant is not None :
2013-10-06 17:19:59 +04:00
if not hasattr ( _allvariants [ variant ] , key ) :
raise ValueError ( " Unknown osdict property ' %s ' " % key )
2013-08-11 23:29:31 +04:00
val = getattr ( _allvariants [ variant ] , key )
if val == _SENTINEL :
val = default
return val
2013-03-18 01:06:52 +04:00
2013-08-10 02:14:42 +04:00
class _OSVariant ( object ) :
2013-08-11 23:29:31 +04:00
"""
Object tracking guest OS specific configuration bits .
@name : name of the object . This must be lowercase . This becomes part of
the virt - install command line API so we cannot remove any existing
name ( we could probably add aliases though )
@label : Pretty printed label . This is used in the virt - manager UI .
We can tweak this .
@is_type : virt - install historically had a distinction between an
os ' type ' ( windows , linux , etc ) , and an os ' variant ' ( fedora18 ,
winxp , etc ) . Back in 2009 we actually required the user to
specify - - os - type if specifying an - - os - variant even though we
could figure it out easily . This distinction isn ' t needed any
more , though it ' s still baked into the virt-manager UI where
it is still pretty useful , so we fake it here . New types should
not be added often .
@parent : Name of a pre - created variant that we want to extend . So
fedoraFOO would have parent fedoraFOO - 1. It ' s used for inheiriting
values .
2014-02-17 19:39:59 +04:00
@typename : The family of the OS , e . g . " linux " , " windows " , " unix " .
2013-08-11 23:29:31 +04:00
@sortby : A different key to use for sorting the distro list . By default
it ' s ' name ' , so this doesn ' t need to be specified .
2013-09-27 01:44:30 +04:00
@urldistro : This is a distro class . It ' s wired up in urlfetcher to give
2013-08-11 23:29:31 +04:00
us a shortcut when detecting OS type from a URL .
@supported : If this distro is supported by it ' s owning organization,
like is it still receiving updates . We use this to limit the
distros we show in virt - manager by default , so old distros aren ' t
squeezing out current ones .
@three_stage_install : If True , this VM has a 3 stage install , AKA windows .
2013-08-18 01:53:17 +04:00
@virtionet : If True , this OS supports virtionet out of the box
@virtiodisk : If True , this OS supports virtiodisk out of the box
2013-08-18 16:59:19 +04:00
@virtiommio : If True , this OS supports virtio - mmio out of the box ,
which provides virtio for certain ARM configurations
2013-10-06 16:53:05 +04:00
@virtioconsole : If True , this OS supports virtio - console out of the box ,
and we should use it as the default console .
@xen_disable_acpi : If True , disable acpi / apic for this OS if on old xen .
2014-02-11 01:14:39 +04:00
This corresponds with the SUPPORT_CONN_CAN_DEFAULT_ACPI check
2013-10-06 17:19:59 +04:00
@qemu_ga : If True , this distro has qemu_ga available by default
2013-08-11 23:29:31 +04:00
The rest of the parameters are about setting device / guest defaults
based on the OS . They should be self explanatory . See guest . py for
their usage .
"""
2013-08-11 02:48:43 +04:00
def __init__ ( self , name , label , is_type = False ,
2014-02-17 19:39:59 +04:00
sortby = None , parent = _SENTINEL , typename = _SENTINEL ,
2013-09-27 01:44:30 +04:00
urldistro = _SENTINEL , supported = _SENTINEL ,
2013-08-11 23:29:31 +04:00
three_stage_install = _SENTINEL ,
acpi = _SENTINEL , apic = _SENTINEL , clock = _SENTINEL ,
netmodel = _SENTINEL , diskbus = _SENTINEL ,
inputtype = _SENTINEL , inputbus = _SENTINEL ,
2013-08-18 01:53:17 +04:00
videomodel = _SENTINEL , virtionet = _SENTINEL ,
2013-08-18 16:59:19 +04:00
virtiodisk = _SENTINEL , virtiommio = _SENTINEL ,
2013-10-06 17:19:59 +04:00
virtioconsole = _SENTINEL , xen_disable_acpi = _SENTINEL ,
qemu_ga = _SENTINEL ) :
2013-08-11 23:29:31 +04:00
if is_type :
if parent != _SENTINEL :
raise RuntimeError ( " OS types must not specify parent " )
parent = None
elif parent == _SENTINEL :
2013-08-10 22:44:20 +04:00
raise RuntimeError ( " Must specify explicit parent " )
2013-08-11 02:48:43 +04:00
else :
2013-08-10 22:44:20 +04:00
parent = _allvariants [ parent ]
2013-08-11 23:29:31 +04:00
def _get_default ( name , val , default = _SENTINEL ) :
2013-08-10 22:44:20 +04:00
if val == _SENTINEL :
2013-08-11 23:29:31 +04:00
if not parent :
return default
return getattr ( parent , name )
2013-08-10 22:44:20 +04:00
return val
2013-08-11 23:29:31 +04:00
if name != name . lower ( ) :
raise RuntimeError ( " OS dictionary wants lowercase name, not "
" ' %s ' " % name )
self . name = name
2013-08-10 02:14:42 +04:00
self . label = label
self . sortby = sortby
2013-08-11 02:48:43 +04:00
self . is_type = bool ( is_type )
2014-02-17 19:39:59 +04:00
self . typename = typename
if typename == _SENTINEL :
self . typename = _get_default ( " typename " ,
2013-08-11 23:29:31 +04:00
self . is_type and self . name or _SENTINEL )
2013-08-11 02:48:43 +04:00
2013-08-11 23:29:31 +04:00
# 'types' should rarely be altered, this check will make
# doubly sure that a new type isn't accidentally added
_approved_types = [ " linux " , " windows " , " unix " ,
" solaris " , " other " ]
2013-08-11 02:48:43 +04:00
if self . typename not in _approved_types :
raise RuntimeError ( " type ' %s ' for variant ' %s ' not in list "
" of approved distro types %s " %
( self . typename , self . name , _approved_types ) )
2013-09-27 01:44:30 +04:00
self . urldistro = _get_default ( " urldistro " , urldistro , None )
2013-08-11 23:29:31 +04:00
self . supported = _get_default ( " supported " , supported , False )
self . three_stage_install = _get_default ( " three_stage_install " ,
three_stage_install )
2013-08-10 02:14:42 +04:00
2013-08-11 23:29:31 +04:00
self . acpi = _get_default ( " acpi " , acpi )
self . apic = _get_default ( " apic " , apic )
self . clock = _get_default ( " clock " , clock )
2013-08-11 22:52:30 +04:00
2013-08-11 23:29:31 +04:00
self . netmodel = _get_default ( " netmodel " , netmodel )
self . videomodel = _get_default ( " videomodel " , videomodel )
self . diskbus = _get_default ( " diskbus " , diskbus )
self . inputtype = _get_default ( " inputtype " , inputtype )
self . inputbus = _get_default ( " inputbus " , inputbus )
2013-08-11 22:52:30 +04:00
2013-08-18 01:53:17 +04:00
self . xen_disable_acpi = _get_default ( " xen_disable_acpi " ,
xen_disable_acpi )
self . virtiodisk = _get_default ( " virtiodisk " , virtiodisk )
self . virtionet = _get_default ( " virtionet " , virtionet )
2013-08-18 16:59:19 +04:00
self . virtiommio = _get_default ( " virtiommio " , virtiommio )
2013-10-06 16:53:05 +04:00
self . virtioconsole = _get_default ( " virtioconsole " , virtioconsole )
2013-10-06 17:19:59 +04:00
self . qemu_ga = _get_default ( " qemu_ga " , qemu_ga )
2013-08-18 01:53:17 +04:00
2013-08-11 22:52:30 +04:00
def _add_type ( * args , * * kwargs ) :
kwargs [ " is_type " ] = True
_t = _OSVariant ( * args , * * kwargs )
_allvariants [ _t . name ] = _t
def _add_var ( * args , * * kwargs ) :
v = _OSVariant ( * args , * * kwargs )
_allvariants [ v . name ] = v
2014-02-17 19:40:00 +04:00
class _OsVariantOsInfo ( _OSVariant ) :
@staticmethod
def is_windows ( o ) :
return o . get_family ( ) in [ ' win9x ' , ' winnt ' , ' win16 ' ]
def _is_three_stage_install ( self ) :
if _OsVariantOsInfo . is_windows ( self . _os ) :
return True
return _SENTINEL
def _get_clock ( self ) :
if _OsVariantOsInfo . is_windows ( self . _os ) or \
self . _os . get_family ( ) in [ ' solaris ' ] :
return " localtime "
return _SENTINEL
def _is_acpi ( self ) :
if self . _os . get_family ( ) in [ ' msdos ' ] :
return False
return _SENTINEL
def _is_apic ( self ) :
if self . _os . get_family ( ) in [ ' msdos ' ] :
return False
return _SENTINEL
def _get_netmodel ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " net " )
devs = self . _os . get_all_devices ( fltr )
if devs . get_length ( ) :
return devs . get_nth ( 0 ) . get_name ( )
return _SENTINEL
def _get_videomodel ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " video " )
devs = self . _os . get_all_devices ( fltr )
if devs . get_length ( ) :
return devs . get_nth ( 0 ) . get_name ( )
return _SENTINEL
def _get_inputtype ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " input " )
devs = self . _os . get_all_devices ( fltr )
if devs . get_length ( ) :
return devs . get_nth ( 0 ) . get_name ( )
return _SENTINEL
def get_inputbus ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " input " )
devs = self . _os . get_all_devices ( fltr )
if devs . get_length ( ) :
return devs . get_nth ( 0 ) . get_bus_type ( )
return _SENTINEL
def _get_diskbus ( self ) :
return _SENTINEL
@staticmethod
def is_os_related_to ( o , related_os_list ) :
if o . get_short_id ( ) in related_os_list :
return True
related = o . get_related ( libosinfo . ProductRelationship . DERIVES_FROM )
clones = o . get_related ( libosinfo . ProductRelationship . CLONES )
for r in related . get_elements ( ) + clones . get_elements ( ) :
if r . get_short_id ( ) in related_os_list or \
_OsVariantOsInfo . is_os_related_to ( r , related_os_list ) :
return True
return False
def _get_xen_disable_acpi ( self ) :
if _OsVariantOsInfo . is_os_related_to ( self . _os , [ " winxp " , " win2k " ] ) :
return True
return _SENTINEL
def _is_virtiodisk ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " block " )
devs = self . _os . get_all_devices ( fltr )
for dev in range ( devs . get_length ( ) ) :
d = devs . get_nth ( dev )
if d . get_name ( ) == " virtio-block " :
return True
return _SENTINEL
def _is_virtionet ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " net " )
devs = self . _os . get_all_devices ( fltr )
for dev in range ( devs . get_length ( ) ) :
d = devs . get_nth ( dev )
if d . get_name ( ) == " virtio-net " :
return True
return _SENTINEL
def _is_virtioconsole ( self ) :
fltr = libosinfo . Filter ( )
fltr . add_constraint ( " class " , " console " )
devs = self . _os . get_all_devices ( fltr )
for dev in range ( devs . get_length ( ) ) :
d = devs . get_nth ( dev )
if d . get_name ( ) == " virtio-console " :
return True
return _SENTINEL
def _is_virtiommio ( self ) :
if _OsVariantOsInfo . is_os_related_to ( self . _os , [ " fedora19 " ] ) :
return True
return _SENTINEL
def _is_qemu_ga ( self ) :
if _OsVariantOsInfo . is_os_related_to ( self . _os , [ " fedora18 " ] ) :
return True
return _SENTINEL
def _get_typename ( self ) :
if self . _os . get_family ( ) in [ ' linux ' ] :
return " linux "
if self . _os . get_family ( ) in [ ' win9x ' , ' winnt ' , ' win16 ' ] :
return " windows "
if self . _os . get_family ( ) in [ ' solaris ' ] :
return " solaris "
if self . _os . get_family ( ) in [ ' openbsd ' , ' freebsd ' , ' netbsd ' ] :
return " unix "
return " other "
def _get_sortby ( self ) :
version = self . _os . get_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 :
pass
distro = self . _os . get_distro ( )
return " %s - %s " % ( distro , version )
def _get_supported ( self ) :
d = self . _os . get_eol_date_string ( )
return d is None or datetime . strptime ( d , " % Y- % m- %d " ) > datetime . now ( )
def _get_urldistro ( self ) :
urldistro = self . _os . get_distro ( )
return urldistro
def _get_name ( self ) :
name = self . _os . get_short_id ( )
return name
def get_label ( self ) :
return self . _os . get_name ( )
def __init__ ( self , o ) :
self . _os = o
name = self . _get_name ( )
label = self . get_label ( )
sortby = self . _get_sortby ( )
is_type = False
typename = self . _get_typename ( )
urldistro = self . _get_urldistro ( )
supported = self . _get_supported ( )
three_stage_install = self . _is_three_stage_install ( )
acpi = self . _is_acpi ( )
apic = self . _is_apic ( )
clock = self . _get_clock ( )
netmodel = self . _get_netmodel ( )
videomodel = self . _get_videomodel ( )
diskbus = self . _get_diskbus ( )
inputtype = self . _get_inputtype ( )
inputbus = self . get_inputbus ( )
xen_disable_acpi = self . _get_xen_disable_acpi ( )
virtiodisk = self . _is_virtiodisk ( )
virtionet = self . _is_virtionet ( )
virtiommio = self . _is_virtiommio ( )
virtioconsole = self . _is_virtioconsole ( )
qemu_ga = self . _is_qemu_ga ( )
_OSVariant . __init__ ( self , name = name , label = label , is_type = is_type ,
typename = typename , sortby = sortby , parent = " generic " ,
urldistro = urldistro , supported = supported ,
three_stage_install = three_stage_install , acpi = acpi , apic = apic ,
clock = clock , netmodel = netmodel , diskbus = diskbus ,
inputtype = inputtype , inputbus = inputbus , videomodel = videomodel ,
virtionet = virtionet , virtiodisk = virtiodisk ,
virtiommio = virtiommio , virtioconsole = virtioconsole ,
xen_disable_acpi = xen_disable_acpi , qemu_ga = qemu_ga )
2013-08-11 22:52:30 +04:00
2014-02-17 19:40:00 +04:00
_add_type ( " linux " , " Linux " )
2013-08-11 23:29:31 +04:00
_add_type ( " windows " , " Windows " , clock = " localtime " , three_stage_install = True , inputtype = " tablet " , inputbus = " usb " , videomodel = " vga " )
_add_type ( " solaris " , " Solaris " , clock = " localtime " )
_add_type ( " unix " , " UNIX " )
_add_type ( " other " , " Other " )
2013-08-11 22:52:30 +04:00
_add_var ( " generic " , " Generic " , supported = True , parent = " other " )
2014-02-17 19:40:00 +04:00
loader = libosinfo . Loader ( )
loader . process_default_path ( )
db = loader . get_db ( )
oslist = db . get_os_list ( )
for os in range ( oslist . get_length ( ) ) :
osi = _OsVariantOsInfo ( oslist . get_nth ( os ) )
_allvariants [ osi . name ] = osi