def validate_southbound_devices_usages(nets, ni): kernel_config = KernelConfig(ni) for requested_net, net_info in six.viewitems(nets): if 'remove' in net_info: kernel_config.removeNetwork(requested_net) for requested_net, net_info in six.viewitems(nets): if 'remove' in net_info: continue kernel_config.setNetwork(requested_net, net_info) underlying_devices = [] for net_name, net_attrs in six.viewitems(kernel_config.networks): vlan = net_attrs.get('vlan') if 'bonding' in net_attrs: underlying_devices.append((net_attrs['bonding'], vlan)) elif 'nic' in net_attrs: underlying_devices.append((net_attrs['nic'], vlan)) else: if not net_attrs['bridged']: raise ne.ConfigNetworkError( ne.ERR_BAD_PARAMS, 'southbound device not specified for non-bridged ' 'network "{}"'.format(net_name)) if len(set(underlying_devices)) < len(underlying_devices): raise ne.ConfigNetworkError( ne.ERR_BAD_PARAMS, 'multiple networks/similar vlans cannot be' ' defined on a single underlying device. ' 'kernel networks: {}\nrequested networks: {}'.format( kernel_config.networks, nets))
def _create_desired_config(self): desired_config = KernelConfig(self._net_info) for net_name, net_attr in self._nets.items(): if 'remove' in net_attr: desired_config.removeNetwork(net_name) else: desired_config.setNetwork(net_name, net_attr) for bond_name, bond_attr in self._bonds.items(): if 'remove' in bond_attr: desired_config.removeBonding(bond_name) else: desired_config.setBonding(bond_name, bond_attr) return desired_config
def _create_unified_configuration(rconfig, net_info): """ Given netinfo report, generate unified configuration and persist it. Networks and Bonds detected by the network caps/netinfo are recorded. In case there are external bonds (not owned), they are still counted for in this regard. Note: Unified persistence mode is not activated in this context, it is left as a separate step/action. """ kconfig = KernelConfig(net_info) rconfig.networks = kconfig.networks rconfig.bonds = _filter_owned_bonds(kconfig.bonds) rconfig.save() ConfigWriter.clearBackups() RunningConfig.store()