Translate CLI/SLS input into the format the API expects. The ``translator``
    argument must be a module containing translation functions, within
    salt.utils.docker.translate. A ``skip_translate`` kwarg can be passed to
    control which arguments are translated. It can be either a comma-separated
    list or an iterable containing strings (e.g. a list or tuple), and members
    of that tuple will have their translation skipped. Optionally,
    skip_translate can be set to True to skip *all* translation.

def translate_input(translator,
                    skip_translate=None,
                    ignore_collisions=False,
                    validate_ip_addrs=True,
                    **kwargs):
    '''
    Translate CLI/SLS input into the format the API expects. The ``translator``
    argument must be a module containing translation functions, within
    salt.utils.docker.translate. A ``skip_translate`` kwarg can be passed to
    control which arguments are translated. It can be either a comma-separated
    list or an iterable containing strings (e.g. a list or tuple), and members
    of that tuple will have their translation skipped. Optionally,
    skip_translate can be set to True to skip *all* translation.
    '''
    kwargs = copy.deepcopy(salt.utils.args.clean_kwargs(**kwargs))
    invalid = {}
    collisions = []

    if skip_translate is True:
        # Skip all translation
        return kwargs
    else:
        if not skip_translate:
            skip_translate = ()
        else:
            try:
                skip_translate = _split(skip_translate)
            except AttributeError:
                pass
            if not hasattr(skip_translate, '__iter__'):
                log.error('skip_translate is not an iterable, ignoring')
                skip_translate = ()

    try:
        # Using list(kwargs) here because if there are any invalid arguments we
        # will be popping them from the kwargs.
        for key in list(kwargs):
            real_key = translator.ALIASES.get(key, key)
            if real_key in skip_translate:
                continue

            # ipam_pools is designed to be passed as a list of actual
            # dictionaries, but if each of the dictionaries passed has a single
            # element, it will be incorrectly repacked.
            if key != 'ipam_pools' and salt.utils.data.is_dictlist(kwargs[key]):
                kwargs[key] = salt.utils.data.repack_dictlist(kwargs[key])

            try:
                kwargs[key] = getattr(translator, real_key)(
                    kwargs[key],
                    validate_ip_addrs=validate_ip_addrs,
                    skip_translate=skip_translate)
            except AttributeError:
                log.debug('No translation function for argument \'%s\'', key)
                continue
            except SaltInvocationError as exc:
                kwargs.pop(key)
                invalid[key] = exc.strerror

        try:
            translator._merge_keys(kwargs)
        except AttributeError:
            pass

        # Convert CLI versions of commands to their docker-py counterparts
        for key in translator.ALIASES:
            if key in kwargs:
                new_key = translator.ALIASES[key]
                value = kwargs.pop(key)
                if new_key in kwargs:
                    collisions.append(new_key)
                else:
                    kwargs[new_key] = value

        try:
            translator._post_processing(kwargs, skip_translate, invalid)
        except AttributeError:
            pass

    except Exception as exc:
        error_message = exc.__str__()
        log.error(
            'Error translating input: \'%s\'', error_message, exc_info=True)
    else:
        error_message = None

    error_data = {}
    if error_message is not None:
        error_data['error_message'] = error_message
    if invalid:
        error_data['invalid'] = invalid
    if collisions and not ignore_collisions:
        for item in collisions:
            error_data.setdefault('collisions', []).append(
                '\'{0}\' is an alias for \'{1}\', they cannot both be used'
                .format(translator.ALIASES_REVMAP[item], item)
            )
    if error_data:
        raise CommandExecutionError(
            'Failed to translate input', info=error_data)

    return kwargs