def _handleBondings(bondings, configurator, in_rollback): """ Add/Edit/Remove bond interface """ logger = logging.getLogger("_handleBondings") _netinfo = CachingNetInfo() edition = [] addition = [] for name, attrs in bondings.items(): if 'remove' in attrs: if name not in _netinfo.bondings: if in_rollback: logger.error( 'Cannot remove bonding %s during rollback: ' 'does not exist', name) continue else: raise ConfigNetworkError( ne.ERR_BAD_BONDING, "Cannot remove bonding %s: does not exist" % name) bond_users = _netinfo.ifaceUsers(name) # networks removal takes place before bondings handling, therefore # all assigned networks (bond_users) should be already removed if bond_users: raise ConfigNetworkError( ne.ERR_USED_BOND, "Cannot remove bonding %s: used by another interfaces %s" % (name, bond_users)) bond = Bond.objectivize(name, configurator, attrs.get('options'), attrs.get('nics'), mtu=None, _netinfo=_netinfo, destroyOnMasterRemoval='remove' in attrs) bond.remove() _netinfo.del_bonding(name) elif name in _netinfo.bondings: edition.append((name, attrs)) else: addition.append((name, attrs)) for name, attrs in edition: bond = Bond.objectivize(name, configurator, attrs.get('options'), attrs.get('nics'), mtu=None, _netinfo=_netinfo, destroyOnMasterRemoval='remove' in attrs) if len(bond.slaves) == 0: raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics' ' for bonding device.') logger.debug("Editing bond %r with options %s", bond, bond.options) configurator.editBonding(bond, _netinfo) for name, attrs in addition: bond = Bond.objectivize(name, configurator, attrs.get('options'), attrs.get('nics'), mtu=None, _netinfo=_netinfo, destroyOnMasterRemoval='remove' in attrs) if len(bond.slaves) == 0: raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics' ' for bonding device.') logger.debug("Creating bond %r with options %s", bond, bond.options) configurator.configureBond(bond)
def __init__(self, name, configurator, ipv4=None, ipv6=None, blockingdhcp=False, mtu=None, _netinfo=None): if _netinfo is None: _netinfo = CachingNetInfo() if name not in _netinfo.nics: raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name) if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp, mtu)
def __init__(self, name, configurator, ipv4=None, ipv6=None, blockingdhcp=False, mtu=None, _netinfo=None): if _netinfo is None: _netinfo = CachingNetInfo() if name not in _netinfo.nics: raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name) if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp, mtu)