cli: Parameterize --os-variant

For now it just takes a single name= parameter that maps to
the current behavior
This commit is contained in:
Cole Robinson 2019-02-07 16:26:04 -05:00
parent 1ad1c2acd1
commit 4a2ff83b51
4 changed files with 57 additions and 9 deletions

View File

@ -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.u", "address.unit")
_add_argcomplete_cmd("virt-install --disk address.unit=foo,sg", "sgio") _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 --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, _add_argcomplete_cmd("virt-install --test-stub", None,
nogrep="--test-stub-command") nogrep="--test-stub-command")
_add_argcomplete_cmd("virt-clone --preserve", "--preserve-data") _add_argcomplete_cmd("virt-clone --preserve", "--preserve-data")

View File

@ -167,7 +167,7 @@ def convert_old_os_options(options):
elif options.old_os_type: elif options.old_os_type:
distkey = 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) 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 # Limit it to hvm x86 guests which presently our defaults
# only really matter for # only really matter for
if (guest.osinfo.name == "generic" and 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()): guest.os.is_x86() and guest.os.is_hvm()):
logging.warning(_("No operating system detected, VM performance may " logging.warning(_("No operating system detected, VM performance may "
"suffer. Specify an OS with --os-variant for optimal results.")) "suffer. Specify an OS with --os-variant for optimal results."))
@ -479,7 +480,7 @@ def build_installer(options, guest):
try: try:
# This also validates the install location # This also validates the install location
autodistro = installer.detect_distro(guest) autodistro = installer.detect_distro(guest)
if options.os_variant == "auto": if options.os_variant.is_auto:
distro = autodistro distro = autodistro
except ValueError as e: except ValueError as e:
fail(_("Error validating install location: %s") % str(e)) fail(_("Error validating install location: %s") % str(e))
@ -519,10 +520,10 @@ def build_guest_instance(conn, options):
guest.os.arch = options.arch guest.os.arch = options.arch
if options.machine: if options.machine:
guest.os.machine = 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 # If explicit os-variant requested, set it early since it will
# provide more defaults in the future # provide more defaults in the future
guest.set_os_name(options.os_variant) options.os_variant.set_os_name(guest)
cli.parse_option_strings(options, guest, None) cli.parse_option_strings(options, guest, None)

View File

@ -59,7 +59,8 @@ def set_os_variant(options, guest):
if options.os_variant is None: if options.os_variant is None:
return 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): def get_domain_and_guest(conn, domstr):

View File

@ -462,7 +462,7 @@ def get_meter():
########################### ###########################
def _get_completer_parsers(): def _get_completer_parsers():
return VIRT_PARSERS + [ParseCLICheck, ParserLocation] return VIRT_PARSERS + [ParseCLICheck, ParserLocation, ParserOSVariant]
def _virtparser_completer(prefix, **kwargs): def _virtparser_completer(prefix, **kwargs):
@ -1482,6 +1482,50 @@ def parse_location(optstr):
return location, kernel, initrd 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 # # --metadata parsing #
###################### ######################