Example #1
0
def _parse_bond_options(opts):
    if not opts:
        return {}

    opts = dict((pair.split('=', 1) for pair in opts.split()))

    # force a numeric bonding mode
    mode = opts.get('mode',
                    bonding.getAllDefaultBondingOptions()['0']['mode'][-1])
    if mode in bonding.BONDING_MODES_NUMBER_TO_NAME:
        numeric_mode = mode
    else:
        numeric_mode = bonding.BONDING_MODES_NAME_TO_NUMBER[mode]
        opts['mode'] = numeric_mode

    # Force a numeric value for an option
    for opname, opval in opts.items():
        numeric_val = bonding.get_bonding_option_numeric_val(numeric_mode,
                                                             opname, opval)
        if numeric_val is not None:
            opts[opname] = numeric_val

    defaults = bonding.getDefaultBondingOptions(numeric_mode)
    return dict(
        (k, v) for k, v in opts.iteritems() if v != defaults.get(k))
Example #2
0
    def validateOptions(cls, bondingOptions):
        'Example: BONDING_OPTS="mode=802.3ad miimon=150"'
        mode = 'balance-rr'
        try:
            for option in bondingOptions.split():
                key, value = option.split('=', 1)
                if key == 'mode':
                    mode = value
        except ValueError:
            raise ConfigNetworkError(
                ne.ERR_BAD_BONDING,
                'Error parsing '
                'bonding options: %r' % bondingOptions,
            )

        mode = bonding.numerize_bond_mode(mode)
        defaults = bonding.getDefaultBondingOptions(mode)

        for option in bondingOptions.split():
            key, _ = option.split('=', 1)
            if key not in defaults:
                raise ConfigNetworkError(
                    ne.ERR_BAD_BONDING,
                    '%r is not a '
                    'valid bonding option' % key,
                )
Example #3
0
def _parse_bond_options(opts):
    if not opts:
        return {}

    opts = dict((pair.split('=', 1) for pair in opts.split()))

    # force a numeric bonding mode
    mode = opts.get('mode',
                    bonding.getAllDefaultBondingOptions()['0']['mode'][-1])
    if mode in bonding.BONDING_MODES_NUMBER_TO_NAME:
        numeric_mode = mode
    else:
        numeric_mode = bonding.BONDING_MODES_NAME_TO_NUMBER[mode]
        opts['mode'] = numeric_mode

    # Force a numeric value for an option
    for opname, opval in opts.items():
        numeric_val = bonding.get_bonding_option_numeric_val(numeric_mode,
                                                             opname, opval)
        if numeric_val is not None:
            opts[opname] = numeric_val

    defaults = bonding.getDefaultBondingOptions(numeric_mode)
    return dict(
        (k, v) for k, v in opts.iteritems() if v != defaults.get(k))
Example #4
0
def _parse_bond_options(opts):
    if not opts:
        return {}

    opts = dict((pair.split('=', 1) for pair in opts.split()))

    mode = opts.get('mode',
                    bonding.getAllDefaultBondingOptions()['0']['mode'][-1])
    opts['mode'] = numeric_mode = bonding.numerize_bond_mode(mode)

    # Force a numeric value for an option
    for opname, opval in opts.items():
        numeric_val = bond_opts_mapper.get_bonding_option_numeric_val(
            numeric_mode, opname, opval)
        if numeric_val is not None:
            opts[opname] = numeric_val

    defaults = bonding.getDefaultBondingOptions(numeric_mode)
    return dict((k, v) for k, v in six.viewitems(opts) if v != defaults.get(k))
Example #5
0
File: ifcfg.py Project: nirs/vdsm
def _restore_default_bond_options(bond_name, desired_options):
    """
    Restore the bond's options to defaults corresponding to the intended
    bonding mode. First change the mode to the desired one (if needed) to avoid
    'Operation not permitted' errors and then reset the non-default options.

    This works around an initscripts design limitation: ifup only touches
    declared options and leaves other (possibly non-default) options as-is.
    """

    desired_options = dict(p.split("=", 1) for p in desired_options.split())
    current_opts = netinfo_bonding.bondOpts(bond_name)
    current_mode = current_opts["mode"]
    desired_mode = _get_mode_from_desired_options(desired_options) or current_mode

    if desired_mode != current_mode:
        try:
            bond_mode_path = netinfo_bonding.BONDING_OPT % (bond_name, "mode")
            with open(bond_mode_path, "w") as f:
                f.write(" ".join(desired_mode))
        except IOError as e:
            if e.errno == errno.EPERM:
                # give up here since this bond was probably not configured by
                # VDSM and ifdown it leaves active slave interfaces
                logging.warning(
                    "Failed resetting bond %s options to default. "
                    "This happens probably because this is an "
                    "external bond and still has slaves even after"
                    "calling ifdown on it",
                    bond_name,
                )
                return
            raise

    diff = {}
    default_opts = netinfo_bonding.getDefaultBondingOptions(desired_mode[1])
    for k, v in default_opts.iteritems():
        if k != "mode" and k in current_opts and v != current_opts[k]:
            diff[k] = default_opts[k]
    for k, v in diff.iteritems():
        with open(netinfo_bonding.BONDING_OPT % (bond_name, k), "w") as f:
            f.write(" ".join(v))
Example #6
0
def _parse_bond_options(opts):
    if not opts:
        return {}

    opts = dict((pair.split('=', 1) for pair in opts.split()))

    mode = opts.get('mode',
                    bonding.getAllDefaultBondingOptions()['0']['mode'][-1])
    opts['mode'] = numeric_mode = bonding.numerize_bond_mode(mode)

    # Force a numeric value for an option
    for opname, opval in opts.items():
        numeric_val = bond_opts_mapper.get_bonding_option_numeric_val(
            numeric_mode, opname, opval)
        if numeric_val is not None:
            opts[opname] = numeric_val

    defaults = bonding.getDefaultBondingOptions(numeric_mode)
    return dict(
        (k, v) for k, v in six.viewitems(opts) if v != defaults.get(k))
Example #7
0
File: models.py Project: EdDev/vdsm
    def validateOptions(cls, bondingOptions):
        'Example: BONDING_OPTS="mode=802.3ad miimon=150"'
        mode = 'balance-rr'
        try:
            for option in bondingOptions.split():
                key, value = option.split('=', 1)
                if key == 'mode':
                    mode = value
        except ValueError:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Error parsing '
                                     'bonding options: %r' % bondingOptions)

        mode = bonding.numerize_bond_mode(mode)
        defaults = bonding.getDefaultBondingOptions(mode)

        for option in bondingOptions.split():
            key, _ = option.split('=', 1)
            if key not in defaults and key != 'custom':
                raise ConfigNetworkError(ne.ERR_BAD_BONDING, '%r is not a '
                                         'valid bonding option' % key)
Example #8
0
def _restore_default_bond_options(bond_name, desired_options):
    """
    Restore the bond's options to defaults corresponding to the intended
    bonding mode. First change the mode to the desired one (if needed) to avoid
    'Operation not permitted' errors and then reset the non-default options.

    This works around an initscripts design limitation: ifup only touches
    declared options and leaves other (possibly non-default) options as-is.
    """

    desired_options = dict(p.split('=', 1) for p in desired_options.split())
    current_opts = netinfo_bonding.bondOpts(bond_name)
    current_mode = current_opts['mode']
    desired_mode = (_get_mode_from_desired_options(desired_options)
                    or current_mode)

    if desired_mode != current_mode:
        try:
            bond_mode_path = netinfo_bonding.BONDING_OPT % (bond_name, 'mode')
            with open(bond_mode_path, 'w') as f:
                f.write(' '.join(desired_mode))
        except IOError as e:
            if e.errno == errno.EPERM:
                # give up here since this bond was probably not configured by
                # VDSM and ifdown it leaves active slave interfaces
                logging.warning(
                    'Failed resetting bond %s options to default. '
                    'This happens probably because this is an '
                    'external bond and still has slaves even after'
                    'calling ifdown on it', bond_name)
                return
            raise

    diff = {}
    default_opts = netinfo_bonding.getDefaultBondingOptions(desired_mode[1])
    for k, v in default_opts.iteritems():
        if k != 'mode' and k in current_opts and v != current_opts[k]:
            diff[k] = default_opts[k]
    for k, v in diff.iteritems():
        with open(netinfo_bonding.BONDING_OPT % (bond_name, k), 'w') as f:
            f.write(' '.join(v))
Example #9
0
    def validateOptions(cls, bondingOptions):
        'Example: BONDING_OPTS="mode=802.3ad miimon=150"'
        mode = 'balance-rr'
        try:
            for option in bondingOptions.split():
                key, value = option.split('=', 1)
                if key == 'mode':
                    mode = value
        except ValueError:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Error parsing '
                                     'bonding options: %r' % bondingOptions)

        if mode in bonding.BONDING_MODES_NAME_TO_NUMBER:
            mode = bonding.BONDING_MODES_NAME_TO_NUMBER[mode]
        defaults = bonding.getDefaultBondingOptions(mode)

        for option in bondingOptions.split():
            key, _ = option.split('=', 1)
            if key not in defaults and key != 'custom':
                raise ConfigNetworkError(ne.ERR_BAD_BONDING, '%r is not a '
                                         'valid bonding option' % key)