def get_indexed_dns_config_by_iface(acs_and_ipv4_profiles, acs_and_ipv6_profiles): """ Get current DNS config indexed by interface name. Return dict like { 'iface_name': { Interface.IPV4: { DNS.SERVER: servers, DNS.SEARCH: searches, DNS_METADATA_PRIORITY: priority }, Interface.IPV6: { DNS.SERVER: servers, DNS.SEARCH: searches, DNS_METADATA_PRIORITY: priority }, } } """ iface_dns_configs = defaultdict(dict) for ac, ip_profile in acs_and_ipv6_profiles: if ip_profile.props.dns or ip_profile.props.dns_search: iface_name = nm_ac.ActiveConnection(ac).devname iface_dns_configs[iface_name][ Interface.IPV6] = _get_ip_profile_dns_config(ip_profile) for ac, ip_profile in acs_and_ipv4_profiles: if ip_profile.props.dns or ip_profile.props.dns_search: iface_name = nm_ac.ActiveConnection(ac).devname iface_dns_configs[iface_name][ Interface.IPV4] = _get_ip_profile_dns_config(ip_profile) return iface_dns_configs
def get_running(acs_and_ip_cfgs): """ Query running routes The acs_and_ip_cfgs should be generate to generate a tuple: NM.NM.ActiveConnection, NM.IPConfig """ routes = [] for (active_connection, ip_cfg) in acs_and_ip_cfgs: if not ip_cfg.props.routes: continue iface_name = nm_ac.ActiveConnection(active_connection).devname if not iface_name: raise NmstateInternalError( "Got connection {} has not interface name".format( active_connection.get_id() ) ) for nm_route in ip_cfg.props.routes: table_id = _get_per_route_table_id( nm_route, iplib.KERNEL_MAIN_ROUTE_TABLE_ID ) route_entry = _nm_route_to_route(nm_route, table_id, iface_name) if route_entry: routes.append(route_entry) routes.sort( key=itemgetter( Route.TABLE_ID, Route.NEXT_HOP_INTERFACE, Route.DESTINATION ) ) return routes
def get_dns_config_iface_names(acs_and_ipv4_profiles, acs_and_ipv6_profiles): """ Return a list of interface names which hold static DNS configuration. """ iface_names = [] for ac, ip_profile in chain(acs_and_ipv6_profiles, acs_and_ipv4_profiles): if ip_profile.props.dns or ip_profile.props.dns_search: iface_names.append(nm_ac.ActiveConnection(ac).devname) return iface_names
def get_config(acs_and_ip_profiles): """ Query running routes The acs_and_ip_profiles should be generate to generate a tuple: NM.NM.ActiveConnection, NM.SettingIPConfig """ routes = [] for (active_connection, ip_profile) in acs_and_ip_profiles: nm_routes = ip_profile.props.routes gateway = ip_profile.props.gateway if not nm_routes and not gateway: continue iface_name = nm_ac.ActiveConnection(active_connection).devname if not iface_name: raise NmstateInternalError( "Got connection {} has not interface name".format( active_connection.get_id() ) ) default_table_id = ip_profile.props.route_table if gateway: routes.append( _get_default_route_config( gateway, ip_profile.props.route_metric, default_table_id, iface_name, ) ) # NM supports multiple route table in single profile: # https://bugzilla.redhat.com/show_bug.cgi?id=1436531 # The `ipv4.route-table` and `ipv6.route-table` will be the default # table id for static routes and auto routes. But each static route can # still specify route table id. for nm_route in nm_routes: table_id = _get_per_route_table_id(nm_route, default_table_id) route_entry = _nm_route_to_route(nm_route, table_id, iface_name) if route_entry: routes.append(route_entry) routes.sort( key=itemgetter( Route.TABLE_ID, Route.NEXT_HOP_INTERFACE, Route.DESTINATION ) ) return routes