def bond_device(slaves, prefix='bond', max_length=11): check_sysfs_bond_permission() name = random_iface_name(prefix, max_length) with linkbond.Bond(name, slaves) as bond: bond.create() yield bond.master bond.destroy()
def _split_switch_type_entries(entries, running_entries): legacy_entries = {} ovs_entries = {} def store_broken_entry(name, attrs): """ If a network/bond should be removed but its existing entry was not found in running config, we have to find out what switch type has to be used for removal on our own. All we do now is, that we pass orphan entry to legacy swich which is (unlike OVS switch) able to remove broken networks/bonds. TODO: Try to find out which switch type should be used for broken network/bonding removal. """ legacy_entries[name] = attrs def store_entry(name, attrs, switch_type): if switch_type is None: store_broken_entry(name, attrs) elif switch_type == legacy_switch.SWITCH_TYPE: legacy_entries[name] = attrs elif switch_type == ovs_switch.SWITCH_TYPE: ovs_entries[name] = attrs else: raise ne.ConfigNetworkError( ne.ERR_BAD_PARAMS, 'Invalid switch type %s' % attrs['switch'] ) for name, attrs in six.iteritems(entries): if 'remove' in attrs: running_attrs = running_entries.get(name, {}) switch_type = running_attrs.get('switch') # When removing a network/bond, we try to determine its switch # type from the netinfo report. # This is not always possible, specifically with bonds owned by ovs # but not successfully deployed (not saved in running config). if ( switch_type == legacy_switch.SWITCH_TYPE and bond.Bond(name).exists() and not Ifcfg.owned_device(name) ): # If not owned by Legacy, assume OVS and let it be removed in # the OVS way. switch_type = ovs_switch.SWITCH_TYPE else: switch_type = attrs['switch'] store_entry(name, attrs, switch_type) return legacy_entries, ovs_entries
def canonicalize_external_bonds_used_by_nets(nets, bonds): for netattrs in six.viewvalues(nets): if 'remove' in netattrs: continue bondname = netattrs.get('bonding') if bondname and bondname not in bonds: bond_dev = bond.Bond(bondname) if bond_dev.exists(): bonds[bondname] = { 'nics': list(bond_dev.slaves), 'options': bonding.bondOptsForIfcfg(bond_dev.options), 'switch': netattrs['switch'], }
def _bond_hwaddr_should_be_enforced(bondname): """ Bond MAC address is to be enforced under these conditions: - Bond device exists already. - One of these conditions exists (OR): - Unowned by VDSM (not in running config). - Owned by VDSM and HWADDR is specified in the config. """ bond_dev = bond.Bond(bondname) if bond_dev.exists(): running_bonds = RunningConfig().bonds bondattr = running_bonds.get(bondname) return not bondattr or bondattr.get('hwaddr') return False
def configure(self, **opts): # When the bond is up and we are not changing the configuration that # is already applied in any way, we can skip the configuring. if (self.vlan and self.name in bonding.bondings() and (not self.configurator.unifiedPersistence or self.name in self.configurator.runningConfig.bonds) and nics.operstate(self.name) == nics.OPERSTATE_UP and self.configurator.net_info.ifaceUsers(self.name) and self.mtu <= mtus.getMtu(self.name) and self.areOptionsApplied() and frozenset(slave.name for slave in self.slaves) == frozenset( link_bond.Bond(self.name).slaves)): return self.configurator.configureBond(self, **opts)
def _get_kernel_bonds_slaves(): kernel_bonds_slaves = set() for bond_name in bond.Bond.bonds(): kernel_bonds_slaves |= bond.Bond(bond_name).slaves return kernel_bonds_slaves