Esempio n. 1
0
 def areOptionsApplied(self):
     # TODO: this method returns True iff self.options are a subset of the
     # TODO: current bonding options. VDSM should probably compute if the
     # TODO: non-default settings are equal to the non-default state.
     # 'custom' is not a real bond option, it just piggybacks custom values
     options = remove_custom_bond_option(self.options)
     if options == '':
         return True
     confOpts = [option.split('=', 1) for option in options.split(' ')]
     activeOpts = bonding.bondOpts(self.name,
                                   (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
Esempio n. 2
0
def _get_default_bonding_options():
    """
    Return default options per mode, in a dictionary of dictionaries. All keys
    are strings.
    """
    bond_name = random_iface_name()
    with _bond_device(bond_name):
        default_mode = bondOpts(bond_name, keys=['mode'])['mode']

    # read default values for all modes
    opts = {}
    for mode in range(_MAX_BONDING_MODES + 1):
        mode = str(mode)
        # The bond is created per mode to resolve an EBUSY error
        # that appears randomly when changing bond mode and modifying its
        # attributes. (Seen only on CI runs)
        with _bond_device(bond_name, mode):
            opts[mode] = bondOpts(bond_name)
            opts[mode]['mode'] = default_mode

    return opts
Esempio n. 3
0
 def areOptionsApplied(self):
     # TODO: this method returns True iff self.options are a subset of the
     # TODO: current bonding options. VDSM should probably compute if the
     # TODO: non-default settings are equal to the non-default state.
     # 'custom' is not a real bond option, it just piggybacks custom values
     options = remove_custom_bond_option(self.options)
     if options == '':
         return True
     confOpts = [option.split('=', 1) for option in options.split(' ')]
     activeOpts = bonding.bondOpts(self.name,
                                   (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
Esempio n. 4
0
def _get_default_bonding_options():
    """
    Return default options per mode, in a dictionary of dictionaries. All keys
    are strings.
    """
    bond_name = random_iface_name()
    with _bond_device(bond_name):
        default_mode = bondOpts(bond_name, keys=['mode'])['mode']

    # read default values for all modes
    opts = {}
    for mode in range(_MAX_BONDING_MODES + 1):
        mode = str(mode)
        # The bond is created per mode to resolve an EBUSY error
        # that appears randomly when changing bond mode and modifying its
        # attributes. (Seen only on CI runs)
        with _bond_device(bond_name, mode):
            opts[mode] = bondOpts(bond_name)
            opts[mode]['mode'] = default_mode

    return opts
Esempio n. 5
0
File: ifcfg.py Progetto: 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))
Esempio n. 6
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))