Beispiel #1
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)
Beispiel #2
0
def _restore_default_bond_options(bond_name, desired_options):
    """Restore bond options to the default options of the desired mode. First
    we change the bond mode to the desired mode (if needed) to avoid
    'Operation not permitted' errors and then reset the non-default options
    """

    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))
Beispiel #3
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)
Beispiel #4
0
def _restore_default_bond_options(bond_name, desired_options):
    """Restore bond options to the default options of the desired mode. First
    we change the bond mode to the desired mode (if needed) to avoid
    'Operation not permitted' errors and then reset the non-default options
    """

    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))