Commit 02a6b50a authored by Michele Tartara's avatar Michele Tartara

Improve backwards compatibility of Issue 649 fix

Commit e6e4ff4c fixed Issue 649 by switching the
separator for usb_devices from comma to space. That solved the problem with
the command line, but RAPI was able to work with commas too, so, for backwards
compatibility we need to keep supporting that as well.

Also, in order to avoid changing the format of the config file, the default
internal representation is brought back to being comma-based, and it is changed
at the interface level (CLI or RAPI) before being passed on.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent d7f27a3e
......@@ -284,6 +284,7 @@ __all__ = [
"OPT_COMPL_ONE_OS",
"OPT_COMPL_ONE_EXTSTORAGE",
"cli_option",
"FixHvParams",
"SplitNodeOption",
"CalculateOSNames",
"ParseFields",
......@@ -2581,6 +2582,21 @@ def ParseNicOption(optvalue):
return nics
def FixHvParams(hvparams):
# In Ganeti 2.8.4 the separator for the usb_devices hvparam was changed from
# comma to space because commas cannot be accepted on the command line
# (they already act as the separator between different hvparams). Still,
# RAPI should be able to accept commas for backwards compatibility.
# Therefore, we convert spaces into commas here, and we keep the old
# parsing logic everywhere else.
try:
new_usb_devices = hvparams[constants.HV_USB_DEVICES].replace(" ", ",")
hvparams[constants.HV_USB_DEVICES] = new_usb_devices
except KeyError:
#No usb_devices, no modification required
pass
def GenericInstanceCreate(mode, opts, args):
"""Add an instance to the cluster via either creation or import.
......@@ -2670,6 +2686,7 @@ def GenericInstanceCreate(mode, opts, args):
utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_COMPAT)
utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)
FixHvParams(hvparams)
if mode == constants.INSTANCE_CREATE:
start = opts.start
......
......@@ -1311,6 +1311,7 @@ def SetInstanceParams(opts, args):
utils.ForceDictType(opts.hvparams, constants.HVS_PARAMETER_TYPES,
allowed_values=[constants.VALUE_DEFAULT])
FixHvParams(opts.hvparams)
nics = _ConvertNicDiskModifications(opts.nics)
disks = _ParseDiskSizes(_ConvertNicDiskModifications(opts.disks))
......
......@@ -1384,7 +1384,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
# Various types of usb devices, comma separated
if hvp[constants.HV_USB_DEVICES]:
for dev in hvp[constants.HV_USB_DEVICES].split(" "):
for dev in hvp[constants.HV_USB_DEVICES].split(","):
kvm_cmd.extend(["-usbdevice", dev])
if hvp[constants.HV_KVM_EXTRA]:
......
......@@ -885,6 +885,27 @@ class R_2_groups_name_assign_nodes(baserlib.OpcodeResource):
})
def _ConvertUsbDevices(data):
"""Convert in place the usb_devices string to the proper format.
In Ganeti 2.8.4 the separator for the usb_devices hvparam was changed from
comma to space because commas cannot be accepted on the command line
(they already act as the separator between different hvparams). RAPI
should be able to accept commas for backwards compatibility, but we want
it to also accept the new space separator. Therefore, we convert
spaces into commas here and keep the old parsing logic elsewhere.
"""
try:
hvparams = data["hvparams"]
usb_devices = hvparams[constants.HV_USB_DEVICES]
hvparams[constants.HV_USB_DEVICES] = usb_devices.replace(" ", ",")
data["hvparams"] = hvparams
except KeyError:
#No usb_devices, no modification required
pass
class R_2_instances(baserlib.OpcodeResource):
"""/2/instances resource.
......@@ -934,6 +955,8 @@ class R_2_instances(baserlib.OpcodeResource):
# Remove "__version__"
data.pop(_REQ_DATA_VERSION, None)
_ConvertUsbDevices(data)
return (data, {
"dry_run": self.dryRun(),
})
......@@ -1327,7 +1350,10 @@ class R_2_instances_name_modify(baserlib.OpcodeResource):
"""Changes parameters of an instance.
"""
return (self.request_body, {
data = self.request_body.copy()
_ConvertUsbDevices(data)
return (data, {
"instance_name": self.items[0],
})
......
......@@ -728,7 +728,8 @@ usb\_devices
``-usbdevice`` option. See the **qemu**\(1) manpage for the syntax
of the possible components. Note that values set with this
parameter are split on a space character and currently don't support
quoting.
quoting. For backwards compatibility reasons, the RAPI interface keeps
accepting comma separated lists too.
vga
Valid for the KVM hypervisor.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment