mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
guest: Replace os_variant with set_os_name
And have callers directly access osinfo.name if they need it
This commit is contained in:
parent
2549e60698
commit
6063538750
@ -155,11 +155,11 @@ def _testURL(fetcher, testdata):
|
||||
hvmguest.os.arch = arch
|
||||
xenguest.os.arch = arch
|
||||
if testdata.testshortcircuit:
|
||||
hvmguest.os_variant = detectdistro
|
||||
xenguest.os_variant = detectdistro
|
||||
hvmguest.set_os_name(detectdistro)
|
||||
xenguest.set_os_name(detectdistro)
|
||||
else:
|
||||
hvmguest.os_variant = None
|
||||
xenguest.os_variant = None
|
||||
hvmguest.set_os_name("generic")
|
||||
xenguest.set_os_name("generic")
|
||||
|
||||
try:
|
||||
hvmstore = _storeForDistro(fetcher, hvmguest)
|
||||
|
@ -36,7 +36,7 @@ def _make_guest(conn=None, os_variant=None):
|
||||
g.os.os_type = "hvm"
|
||||
|
||||
if os_variant:
|
||||
g.os_variant = os_variant
|
||||
g.set_os_name(os_variant)
|
||||
|
||||
# Floppy disk
|
||||
path = "/dev/default-pool/testvol1.img"
|
||||
@ -217,8 +217,7 @@ class TestXMLMisc(unittest.TestCase):
|
||||
"""
|
||||
Check that a common config has idempotent set_defaults
|
||||
"""
|
||||
g = _make_guest(conn=utils.URIs.open_kvm())
|
||||
g.os_variant = "fedora-unknown"
|
||||
g = _make_guest(conn=utils.URIs.open_kvm(), os_variant="fedora-unknown")
|
||||
|
||||
g.set_defaults(None)
|
||||
xml1 = g.get_xml()
|
||||
|
21
virt-install
21
virt-install
@ -305,13 +305,16 @@ def convert_old_features(options):
|
||||
|
||||
def set_distro_variant(options, guest, installer):
|
||||
try:
|
||||
if options.distro_variant not in ["auto", "none"]:
|
||||
guest.os_variant = options.distro_variant
|
||||
|
||||
installer.check_location(guest)
|
||||
|
||||
distro = None
|
||||
if options.distro_variant == "auto":
|
||||
guest.os_variant = installer.detect_distro(guest)
|
||||
distro = installer.detect_distro(guest)
|
||||
elif options.distro_variant != "none":
|
||||
distro = options.distro_variant
|
||||
|
||||
if distro:
|
||||
guest.set_os_name(distro)
|
||||
except ValueError as e:
|
||||
fail(_("Error validating install location: %s") % str(e))
|
||||
|
||||
@ -451,7 +454,7 @@ def show_warnings(options, guest, installer):
|
||||
logging.warning(_("The guest's network configuration does not support "
|
||||
"PXE"))
|
||||
|
||||
if (guest.os_variant == "generic" and
|
||||
if (guest.osinfo.name == "generic" and
|
||||
options.distro_variant not in ["none", "generic"]):
|
||||
logging.warning(_("No operating system detected, VM performance may "
|
||||
"suffer. Specify an OS with --os-variant for optimal results."))
|
||||
@ -529,13 +532,15 @@ def build_guest_instance(conn, options):
|
||||
for disk in guest.devices.disk:
|
||||
cli.validate_disk(disk)
|
||||
|
||||
# Do this a bit early so we can do arch/os_type checks up ahead
|
||||
# Do this a bit early so we have os_type/arch checks for installer
|
||||
# building, and distro variant detection
|
||||
guest.set_capabilities_defaults()
|
||||
|
||||
installer = build_installer(options, guest)
|
||||
validate_required_options(options, guest, installer)
|
||||
set_distro_variant(options, guest, installer)
|
||||
if installer:
|
||||
set_distro_variant(options, guest, installer)
|
||||
|
||||
validate_required_options(options, guest, installer)
|
||||
check_option_collisions(options, guest, installer)
|
||||
show_warnings(options, guest, installer)
|
||||
|
||||
|
@ -1567,10 +1567,10 @@ class vmmCreate(vmmGObjectUI):
|
||||
if machine:
|
||||
guest.os.machine = machine
|
||||
|
||||
# OS distro/variant validation
|
||||
# Validation catches user manually typing an invalid value
|
||||
try:
|
||||
if variant:
|
||||
guest.os_variant = variant
|
||||
guest.set_os_name(variant)
|
||||
except ValueError as e:
|
||||
self.err.val_err(_("Error setting OS information."), str(e))
|
||||
return None
|
||||
|
@ -238,29 +238,19 @@ class Guest(XMLBuilder):
|
||||
# osinfo related definitions #
|
||||
##############################
|
||||
|
||||
def _set_osinfo(self, variant):
|
||||
obj = OSDB.lookup_os(variant)
|
||||
if not obj:
|
||||
obj = OSDB.lookup_os("generic")
|
||||
self.__osinfo = obj
|
||||
def _get_osinfo(self):
|
||||
if not self.__osinfo:
|
||||
self._set_osinfo(None)
|
||||
self.set_os_name("generic")
|
||||
return self.__osinfo
|
||||
osinfo = property(_get_osinfo)
|
||||
|
||||
def _get_os_variant(self):
|
||||
return self.osinfo.name
|
||||
def _set_os_variant(self, val):
|
||||
if val:
|
||||
val = val.lower()
|
||||
if OSDB.lookup_os(val) is None:
|
||||
raise ValueError(
|
||||
_("Distro '%s' does not exist in our dictionary") % val)
|
||||
|
||||
logging.debug("Setting Guest.os_variant to '%s'", val)
|
||||
self._set_osinfo(val)
|
||||
os_variant = property(_get_os_variant, _set_os_variant)
|
||||
def set_os_name(self, name):
|
||||
obj = OSDB.lookup_os(name)
|
||||
if obj is None:
|
||||
raise ValueError(
|
||||
_("Distro '%s' does not exist in our dictionary") % name)
|
||||
logging.debug("Setting Guest os_name=%s", name)
|
||||
self.__osinfo = obj
|
||||
|
||||
def _supports_virtio(self, os_support):
|
||||
if not self.conn.is_qemu():
|
||||
|
@ -252,7 +252,7 @@ def getDistroStore(guest, fetcher):
|
||||
|
||||
arch = guest.os.arch
|
||||
_type = guest.os.os_type
|
||||
osobj = OSDB.lookup_os(guest.os_variant)
|
||||
osobj = guest.osinfo
|
||||
stores = _allstores[:]
|
||||
cache = _DistroCache(fetcher)
|
||||
|
||||
@ -261,7 +261,7 @@ def getDistroStore(guest, fetcher):
|
||||
if osobj.distro:
|
||||
logging.debug("variant=%s has distro=%s, looking for matching "
|
||||
"distro store to prioritize",
|
||||
guest.os_variant, osobj.distro)
|
||||
osobj.name, osobj.distro)
|
||||
found_store = None
|
||||
for store in stores:
|
||||
if osobj.distro in store.matching_distros:
|
||||
|
Loading…
Reference in New Issue
Block a user