コード例 #1
0
ファイル: ifcfg.py プロジェクト: germanovm/vdsm
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))
コード例 #2
0
ファイル: models.py プロジェクト: kvaps/vdsm
 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.
     if not self.options:
         return True
     confOpts = [option.split('=', 1) for option in self.options.split(' ')]
     activeOpts = netinfo.bondOpts(self.name,
                                   (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
コード例 #3
0
ファイル: models.py プロジェクト: nickxiao/vdsm
 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 = netinfo.bondOpts(self.name, (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
コード例 #4
0
ファイル: models.py プロジェクト: borisroman/vdsm
 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 = netinfo.bondOpts(self.name,
                                   (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
コード例 #5
0
ファイル: ifcfg.py プロジェクト: rexhsu/vdsm-debian
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))
コード例 #6
0
ファイル: models.py プロジェクト: kripper/vdsm
 def areOptionsApplied(self):
     confOpts = [option.split('=', 1) for option in self.options.split(' ')]
     activeOpts = netinfo.bondOpts(self.name,
                                   (name for name, value in confOpts))
     return all(value in activeOpts[name] for name, value in confOpts)
コード例 #7
0
ファイル: utils.py プロジェクト: therealmik/vdsm
 def getBondMode(self, bond, keys=None):
     MODE_ID = 1
     return netinfo.bondOpts(bond, keys)['mode'][MODE_ID]