nm: Query interface names which hold DNS config
Add `nm.dns.get_dns_config_iface_names()` to get a list of interface names which hold static DNS configuration. Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
parent
241793968f
commit
665ed8bf18
@ -20,6 +20,7 @@ from operator import itemgetter
|
||||
from libnmstate import iplib
|
||||
from libnmstate.error import NmstateInternalError
|
||||
from libnmstate.nm import nmclient
|
||||
from libnmstate.nm import active_connection as nm_ac
|
||||
from libnmstate.schema import DNS
|
||||
|
||||
|
||||
@ -106,3 +107,14 @@ def add_dns(setting_ip, dns_state):
|
||||
setting_ip.add_dns(server)
|
||||
for search in dns_state.get(DNS.SEARCH, []):
|
||||
setting_ip.add_dns_search(search)
|
||||
|
||||
|
||||
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
|
||||
|
@ -22,6 +22,7 @@ from libnmstate import iplib
|
||||
from libnmstate.error import NmstateInternalError
|
||||
from libnmstate.error import NmstateNotImplementedError
|
||||
from libnmstate.nm import nmclient
|
||||
from libnmstate.nm import active_connection as nm_ac
|
||||
from libnmstate.schema import Route
|
||||
|
||||
NM_ROUTE_TABLE_ATTRIBUTE = 'table'
|
||||
@ -40,7 +41,7 @@ def get_running(acs_and_ip_cfgs):
|
||||
for (active_connection, ip_cfg) in acs_and_ip_cfgs:
|
||||
if not ip_cfg.props.routes:
|
||||
continue
|
||||
iface_name = _get_iface_name(active_connection)
|
||||
iface_name = nm_ac.ActiveConnection(active_connection).devname
|
||||
if not iface_name:
|
||||
raise NmstateInternalError(
|
||||
'Got connection {} has not interface name'.format(
|
||||
@ -73,7 +74,7 @@ def get_config(acs_and_ip_profiles):
|
||||
gateway = ip_profile.props.gateway
|
||||
if not nm_routes and not gateway:
|
||||
continue
|
||||
iface_name = _get_iface_name(active_connection)
|
||||
iface_name = nm_ac.ActiveConnection(active_connection).devname
|
||||
if not iface_name:
|
||||
raise NmstateInternalError(
|
||||
'Got connection {} has not interface name'.format(
|
||||
@ -110,14 +111,6 @@ def _get_per_route_table_id(nm_route, default_table_id):
|
||||
return int(table.get_uint32()) if table else default_table_id
|
||||
|
||||
|
||||
def _get_iface_name(active_connection):
|
||||
"""
|
||||
Return interface name for active_connection, return None if error.
|
||||
"""
|
||||
devs = active_connection.get_devices()
|
||||
return devs[0].get_iface() if devs else None
|
||||
|
||||
|
||||
def _nm_route_to_route(nm_route, table_id, iface_name):
|
||||
dst = '{ip}/{prefix}'.format(
|
||||
ip=nm_route.get_dest(), prefix=nm_route.get_prefix())
|
||||
|
Loading…
x
Reference in New Issue
Block a user