def generate_state(networks, bondings): """ Generate a new nmstate state given VDSM setup state format """ rconfig = RunningConfig() current_ifaces_state = get_interfaces(state_show()) ovs_nets, linux_br_nets = split_switch_type(networks, rconfig.networks) ovs_bonds, linux_br_bonds = split_switch_type(bondings, rconfig.bonds) ovs_requested = ovs_nets or ovs_bonds linux_br_requested = linux_br_nets or linux_br_bonds bond_ifstates = Bond.generate_state(bondings, rconfig.bonds) if ovs_requested: net_ifstates, routes_state, dns_state = ovs_generate_state( networks, rconfig.networks, current_ifaces_state ) else: net_ifstates, routes_state, dns_state = LinuxBrNet.generate_state( networks, rconfig.networks, current_ifaces_state ) ifstates = _merge_bond_and_net_ifaces_states(bond_ifstates, net_ifstates) if linux_br_requested: _set_vlans_base_mtu(ifstates, current_ifaces_state) _set_bond_slaves_mtu(ifstates, current_ifaces_state) return _merge_state(ifstates, routes_state, dns_state)
def netinfo(vdsmnets=None, compatibility=None): # TODO: Version requests by engine to ease handling of compatibility. running_config = RunningConfig() _netinfo = netinfo_get(vdsmnets, compatibility) ovs_nets, _ = util.split_switch_type(running_config.networks, running_config={}) ovs_bonds = util.split_switch_type(running_config.bonds, running_config={}) if ovs_nets or ovs_bonds: state = nmstate.state_show() nmstate.ovs_netinfo(_netinfo, running_config.networks, state) _set_bond_type_by_usage(_netinfo, running_config.bonds) return _netinfo
def validate(networks, bondings, net_info, running_config): ovs_nets, legacy_nets = util.split_switch_type(networks, running_config.networks) ovs_bonds, legacy_bonds = util.split_switch_type(bondings, running_config.bonds) use_legacy_switch = legacy_nets or legacy_bonds use_ovs_switch = ovs_nets or ovs_bonds if use_legacy_switch and use_ovs_switch: raise ne.ConfigNetworkError( ne.ERR_BAD_PARAMS, 'Mixing of legacy and OVS networks is not supported inside one ' 'setupNetworks() call.', ) validator.validate_network_setup(networks, bondings, net_info)
def generate_state(networks, bondings): """Generate a new nmstate state given VDSM setup state format""" rconfig = RunningConfig() current_state = get_current_state() ovs_nets, linux_br_nets = split_switch_type(networks, rconfig.networks) ovs_bonds, linux_br_bonds = split_switch_type(bondings, rconfig.bonds) ovs_requested = ovs_nets or ovs_bonds linux_br_requested = linux_br_nets or linux_br_bonds net_state = ( ovs_generate_state(networks, rconfig.networks, current_state) if ovs_requested else LinuxBrNet.generate_state( networks, rconfig.networks, current_state ) ) net_state.add_bond_state(Bond.generate_state(bondings, rconfig.bonds)) net_state.update_mtu(linux_br_requested, current_state.interfaces_state) return net_state.state()
def _setup_ovs_bridge_mappings(running_networks, networks): # All networks are already saved in the running_network that's why # we can use the split only over running_networks ovs_nets, _ = util.split_switch_type(running_networks, running_config={}) if networks and ovs_nets: mappings = (','.join( nmstate.prepare_ovs_bridge_mappings(running_networks)) or '""') cmds = [ 'ovs-vsctl', 'set', 'open', '.', f'external-ids:ovn-bridge-mappings={mappings}', ] rc, out, err = cmd.exec_sync(cmds) if rc: raise Exception( 'Failed to set external mappings for OvS: ' f'cmd={" ".join(cmds)}, rc={rc}, out={out}, err={err}')