Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 33b976a

Browse files
committed
virt-install: Add --os-variant 'none' option to disable autodetect
First, add a new method set_os_detect to Guest, so that API users can opt into the behavior, and set the behavior off by default. However, virt-install will continue to do autodetect by default, but now users have a way to opt out via --os-variant none
1 parent e35de46 commit 33b976a

8 files changed

Lines changed: 55 additions & 19 deletions

File tree

man/en/virt-install.pod.in

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,25 @@ an optimal cpu pinning using NUMA data, if available.
123123
Optimize the guest configuration for a type of operating system (ex. 'linux',
124124
'windows'). This will attempt to pick the most suitable ACPI & APIC settings,
125125
optimally supported mouse drivers, virtio, and generally accommodate other
126-
operating system quirks. See C<--os-variant> for valid options.
126+
operating system quirks.
127+
128+
By default, virt-install will attempt to auto detect this value from
129+
the install media (currently only supported for URL installs). Autodetection
130+
can be disabled with the special value 'none'
131+
132+
See C<--os-variant> for valid options.
127133

128134
=item --os-variant=OS_VARIANT
129135

130136
Further optimize the guest configuration for a specific operating system
131137
variant (ex. 'fedora8', 'winxp'). This parameter is optional, and does not
132-
require an C<--os-type> to be specified. Valid values are:
138+
require an C<--os-type> to be specified.
139+
140+
By default, virt-install will attempt to auto detect this value from
141+
the install media (currently only supported for URL installs). Autodetection
142+
can be disabled with the special value 'none'.
143+
144+
Valid values are:
133145

134146
::VARIANT VALUES::
135147

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def _update_manpages(self):
235235
output += osdict.OS_TYPES[t]["variants"][v]["label"] + "\n\n"
236236

237237
output += "=back\n\n"
238+
239+
# Add special 'none' value
240+
output += "=item none\n\n"
241+
output += "No OS version specified (disables autodetect)\n\n"
238242
output += "=back\n\n"
239243

240244
infile = "man/en/virt-install.pod.in"

tests/clitest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@
202202
"--paravirt --location %s" % treedir,
203203
# Using ro path as a cd media
204204
"--hvm --cdrom %(ROIMG)s",
205+
# Paravirt location with --os-variant none
206+
"--paravirt --location %s --os-variant none" % treedir,
207+
# URL install with manual os-variant
208+
"--hvm --location %s --os-variant fedora12" % treedir,
205209
],
206210

207211
"invalid": [
@@ -215,6 +219,8 @@
215219
"--import",
216220
# LiveCD with no media
217221
"--livecd",
222+
# Bogus --os-variant
223+
"--hvm --pxe --os-variant farrrrrrrge"
218224
],
219225
}, # category "install"
220226

@@ -487,6 +493,8 @@
487493
"--boot 1",
488494
# Lots of options
489495
"--name foobar --ram 64 --os-variant winxp",
496+
# OS variant 'none'
497+
"--name foobar --ram 64 --os-variant none",
490498
],
491499

492500
"invalid": [

virt-image

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ def main():
214214
get_graphics(image.domain, options.vnc, options.vncport, options.vnclisten,
215215
options.nographics, options.sdl, options.keymap, guest)
216216

217-
if options.distro_type:
218-
guest.set_os_type(options.distro_type)
219-
if options.distro_variant:
220-
guest.set_os_variant(options.distro_variant)
217+
cli.set_os_variant(guest, options.distro_type, options.distro_variant)
221218

222219
if installer.is_hvm():
223220
if options.noacpi:

virt-install

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,7 @@ def main():
772772
cli.get_hostdevs(options.hostdevs, guest)
773773

774774
guest.extraargs = options.extra
775-
if options.distro_type:
776-
guest.set_os_type(options.distro_type)
777-
if options.distro_variant:
778-
guest.set_os_variant(options.distro_variant)
775+
cli.set_os_variant(guest, options.distro_type, options.distro_variant)
779776

780777
# and now for the full-virt vs paravirt specific questions
781778
get_install_media(options.location, options.cdrom, options.pxe,

virtinst/DistroInstaller.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ def _prepare_kernel_and_initrd(self, guest, distro, meter):
193193
self.location, meter, guest.arch, scratchdir=self.scratchdir,
194194
type=self.os_type, distro=distro)
195195

196-
# Only set OS type if the user didn't explictly pass one
197-
# XXX: Should this be opt in?
198-
if guest.os_type == None and os_type:
199-
logging.debug("Auto detected OS type as: %s" % os_type)
200-
guest.os_type = os_type
201-
if (guest.os_variant == None and os_variant
202-
and guest.os_type == os_type):
203-
logging.debug("Auto detected OS variant as: %s" % os_variant)
204-
guest.os_variant = os_variant
196+
if guest.get_os_autodetect():
197+
if os_type:
198+
logging.debug("Auto detected OS type as: %s" % os_type)
199+
guest.os_type = os_type
200+
201+
if (os_variant and guest.os_type == os_type):
202+
logging.debug("Auto detected OS variant as: %s" %
203+
os_variant)
204+
guest.os_variant = os_variant
205205

206206
self.install["kernel"] = kernelfn
207207
self.install["initrd"] = initrdfn

virtinst/Guest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, type=None, connection=None, hypervisorURI=None,
120120
self._cpuset = None
121121
self._graphics_dev = None
122122
self._consolechild = None
123+
self._os_autodetect = False
123124

124125
self._os_type = None
125126
self._os_variant = None
@@ -291,6 +292,12 @@ def set_os_variant(self, val):
291292
raise ValueError, _("Unknown OS variant '%s'" % val)
292293
os_variant = property(get_os_variant, set_os_variant)
293294

295+
def set_os_autodetect(self, val):
296+
self._os_autodetect = bool(val)
297+
def get_os_autodetect(self):
298+
return self._os_autodetect
299+
os_autodetect = property(get_os_autodetect, set_os_autodetect)
300+
294301
# Get the current variants 'distro' tag: 'rhel', 'fedora', etc.
295302
def get_os_distro(self):
296303
return self._lookup_osdict_key("distro")

virtinst/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,17 @@ def get_network(net_kwargs, guest):
548548
n = VirtualNetworkInterface(**net_kwargs)
549549
guest.nics.append(n)
550550

551+
def set_os_variant(guest, distro_type, distro_variant):
552+
if not distro_type and not distro_variant:
553+
# Default to distro autodetection
554+
guest.set_os_autodetect(True)
555+
else:
556+
if (distro_type and str(distro_type).lower() != "none"):
557+
guest.set_os_type(distro_type)
558+
559+
if (distro_variant and str(distro_variant).lower() != "none"):
560+
guest.set_os_variant(distro_variant)
561+
551562

552563
def parse_optstr(optstr, basedict=None):
553564
"""

0 commit comments

Comments
 (0)