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 prepare_ovs_bridge_mappings(running_networks): rnets_config = translate_config(running_networks) current_ifaces_state = get_interfaces(state_show()) ovs_info = OvsInfo(rnets_config, current_ifaces_state) mapping_pairs = [] for sb, nbs in ovs_info.nb_by_sb.items(): bridge = ovs_info.bridge_by_sb[sb] mapping_pairs.extend([f'{nb}:{bridge}' for nb in nbs]) return mapping_pairs
def show_interfaces(filter=None): net_info = state_show() filter_set = set(filter) if filter else set() ifaces = ((ifstate[Interface.NAME], ifstate) for ifstate in net_info[Interface.KEY]) if filter: return { ifname: ifstate for ifname, ifstate in ifaces if ifname in filter_set } else: return {ifname: ifstate for ifname, ifstate in ifaces}
def show_nameservers(): state = state_show() return state[DNS.KEY].get(DNS.RUNNING, {}).get(DNS.SERVER, [])
def get_current_state(): state = state_show() return CurrentState(state)