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

        MODE_NAME_TO_NUMBER = {
            'balance-rr': '0',
            'active-backup': '1',
            'balance-xor': '2',
            'broadcast': '3',
            '802.3ad': '4',
            'balance-tlb': '5',
            'balance-alb': '6',
        }

        if mode in MODE_NAME_TO_NUMBER:
            mode = MODE_NAME_TO_NUMBER[mode]
        defaults = netinfo.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 #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.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:
            with open(netinfo.BONDING_OPT % (bond_name, 'mode'), '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.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_OPT % (bond_name, k), 'w') as f:
            f.write(' '.join(v))
Example #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)

        MODE_NAME_TO_NUMBER = {
            "balance-rr": "0",
            "active-backup": "1",
            "balance-xor": "2",
            "broadcast": "3",
            "802.3ad": "4",
            "balance-tlb": "5",
            "balance-alb": "6",
        }

        if mode in MODE_NAME_TO_NUMBER:
            mode = MODE_NAME_TO_NUMBER[mode]
        defaults = netinfo.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 #4
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_NAME_TO_NUMBER = {
            'balance-rr': '0',
            'active-backup': '1',
            'balance-xor': '2',
            'broadcast': '3',
            '802.3ad': '4',
            'balance-tlb': '5',
            'balance-alb': '6',
        }

        if mode in MODE_NAME_TO_NUMBER:
            mode = MODE_NAME_TO_NUMBER[mode]
        defaults = netinfo.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 #5
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 netinfo.BONDING_MODES_NAME_TO_NUMBER:
            mode = netinfo.BONDING_MODES_NAME_TO_NUMBER[mode]
        defaults = netinfo.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 #6
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 netinfo.BONDING_MODES_NAME_TO_NUMBER:
            mode = netinfo.BONDING_MODES_NAME_TO_NUMBER[mode]
        defaults = netinfo.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 #7
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.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:
            with open(netinfo.BONDING_OPT % (bond_name, 'mode'), '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.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_OPT % (bond_name, k), 'w') as f:
            f.write(' '.join(v))