mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
cli: Parameterize --os-variant
For now it just takes a single name= parameter that maps to the current behavior
This commit is contained in:
parent
1ad1c2acd1
commit
4a2ff83b51
@ -1099,6 +1099,8 @@ _add_argcomplete_cmd("virt-install --disk a", "address.base")
|
||||
_add_argcomplete_cmd("virt-install --disk address.u", "address.unit")
|
||||
_add_argcomplete_cmd("virt-install --disk address.unit=foo,sg", "sgio")
|
||||
_add_argcomplete_cmd("virt-install --check d", "disk_size")
|
||||
_add_argcomplete_cmd("virt-install --location k", "kernel")
|
||||
_add_argcomplete_cmd("virt-install --os-variant nam", "name")
|
||||
_add_argcomplete_cmd("virt-install --test-stub", None,
|
||||
nogrep="--test-stub-command")
|
||||
_add_argcomplete_cmd("virt-clone --preserve", "--preserve-data")
|
||||
|
15
virt-install
15
virt-install
@ -167,7 +167,7 @@ def convert_old_os_options(options):
|
||||
elif options.old_os_type:
|
||||
distkey = options.old_os_type
|
||||
|
||||
options.os_variant = distkey
|
||||
options.os_variant = cli.parse_os_variant(distkey)
|
||||
del(options.old_os_type)
|
||||
|
||||
|
||||
@ -420,7 +420,8 @@ def show_warnings(options, guest, installer):
|
||||
# Limit it to hvm x86 guests which presently our defaults
|
||||
# only really matter for
|
||||
if (guest.osinfo.name == "generic" and
|
||||
options.os_variant not in ["none", "generic"] and
|
||||
not options.os_variant.is_none and
|
||||
not options.os_variant.name == "generic" and
|
||||
guest.os.is_x86() and guest.os.is_hvm()):
|
||||
logging.warning(_("No operating system detected, VM performance may "
|
||||
"suffer. Specify an OS with --os-variant for optimal results."))
|
||||
@ -479,7 +480,7 @@ def build_installer(options, guest):
|
||||
try:
|
||||
# This also validates the install location
|
||||
autodistro = installer.detect_distro(guest)
|
||||
if options.os_variant == "auto":
|
||||
if options.os_variant.is_auto:
|
||||
distro = autodistro
|
||||
except ValueError as e:
|
||||
fail(_("Error validating install location: %s") % str(e))
|
||||
@ -519,10 +520,10 @@ def build_guest_instance(conn, options):
|
||||
guest.os.arch = options.arch
|
||||
if options.machine:
|
||||
guest.os.machine = options.machine
|
||||
if options.os_variant not in ["auto", "none"]:
|
||||
# If explicit os-variant requested, set it early since it will
|
||||
# provide more defaults in the future
|
||||
guest.set_os_name(options.os_variant)
|
||||
|
||||
# If explicit os-variant requested, set it early since it will
|
||||
# provide more defaults in the future
|
||||
options.os_variant.set_os_name(guest)
|
||||
|
||||
cli.parse_option_strings(options, guest, None)
|
||||
|
||||
|
3
virt-xml
3
virt-xml
@ -59,7 +59,8 @@ def set_os_variant(options, guest):
|
||||
if options.os_variant is None:
|
||||
return
|
||||
|
||||
guest.set_os_name(options.os_variant)
|
||||
osdata = cli.parse_os_variant(options.os_variant)
|
||||
osdata.set_os_name(guest)
|
||||
|
||||
|
||||
def get_domain_and_guest(conn, domstr):
|
||||
|
@ -462,7 +462,7 @@ def get_meter():
|
||||
###########################
|
||||
|
||||
def _get_completer_parsers():
|
||||
return VIRT_PARSERS + [ParseCLICheck, ParserLocation]
|
||||
return VIRT_PARSERS + [ParseCLICheck, ParserLocation, ParserOSVariant]
|
||||
|
||||
|
||||
def _virtparser_completer(prefix, **kwargs):
|
||||
@ -1482,6 +1482,50 @@ def parse_location(optstr):
|
||||
return location, kernel, initrd
|
||||
|
||||
|
||||
########################
|
||||
# --os-variant parsing #
|
||||
########################
|
||||
|
||||
class OSVariantData(object):
|
||||
def __init__(self):
|
||||
self._name = None
|
||||
self.is_none = False
|
||||
self.is_auto = False
|
||||
|
||||
def _set_name(self, val):
|
||||
if val == "auto":
|
||||
self.is_auto = True
|
||||
elif val == "none":
|
||||
self.is_none = True
|
||||
else:
|
||||
self._name = val
|
||||
def _get_name(self):
|
||||
return self._name
|
||||
name = property(_get_name, _set_name)
|
||||
|
||||
def set_os_name(self, guest):
|
||||
if self.name:
|
||||
guest.set_os_name(self.name)
|
||||
|
||||
|
||||
class ParserOSVariant(VirtCLIParser):
|
||||
cli_arg_name = "os_variant"
|
||||
remove_first = "name"
|
||||
|
||||
@classmethod
|
||||
def __init_class__(cls, **kwargs):
|
||||
VirtCLIParser.__init_class__(**kwargs)
|
||||
cls.add_arg("name", "name")
|
||||
|
||||
|
||||
def parse_os_variant(optstr):
|
||||
parsedata = OSVariantData()
|
||||
if optstr:
|
||||
parser = ParserOSVariant(None, optstr)
|
||||
parser.parse(parsedata)
|
||||
return parsedata
|
||||
|
||||
|
||||
######################
|
||||
# --metadata parsing #
|
||||
######################
|
||||
|
Loading…
Reference in New Issue
Block a user