def activate(self): if self.con_id: self.import_by_id() elif self.nmdevice: self.import_by_device() elif not self.profile: raise NmstateInternalError( "BUG: Failed to find valid profile to activate: " f"id={self.con_id}, dev={self.devname}") specific_object = None if self.profile: action = f"Activate profile: {self.profile.get_id()}" elif self.nmdevice: action = f"Activate profile: {self.nmdevice.get_iface()}" else: raise NmstateInternalError( "BUG: Cannot activate a profile with empty profile id and " "empty NM.Device") user_data = action self._ctx.register_async(action) self._ctx.client.activate_connection_async( self.profile, self.nmdevice, specific_object, self._ctx.cancellable, self._active_connection_callback, user_data, )
def get_running(): dns_state = {DNS.SERVER: [], DNS.SEARCH: []} client = nmclient.client() for dns_conf in client.get_dns_configuration(): iface_name = dns_conf.get_interface() for ns in dns_conf.get_nameservers(): if iplib.is_ipv6_link_local_addr(ns, IPV6_ADDRESS_LENGTH): if not iface_name: # For IPv6 link local address, the interface name should be # appended also. raise NmstateInternalError( "Missing interface for IPv6 link-local DNS server " "entry {}".format(ns)) ns_addr = "{}%{}".format(ns, iface_name) else: ns_addr = ns if ns_addr not in dns_state[DNS.SERVER]: dns_state[DNS.SERVER].append(ns_addr) dns_domains = [ dns_domain for dns_domain in dns_conf.get_domains() if dns_domain not in dns_state[DNS.SEARCH] ] dns_state[DNS.SEARCH].extend(dns_domains) if not dns_state[DNS.SERVER] and not dns_state[DNS.SEARCH]: dns_state = {} return dns_state
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_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
def register_async(self, action, fast=False): """ Register action(string) to wait list. Set fast as True if requested action does not require too much time, for example: profile modification. """ queue = self._fast_queue if fast else self._slow_queue max_queue = FAST_ASYNC_QUEUE_SIZE if fast else SLOW_ASYNC_QUEUE_SIZE if len(queue) >= max_queue: logging.debug( f"Async queue({max_queue}) full, waiting all existing actions " "to be finished before registering more async action") # TODO: No need to wait all finish, should continue when the queue # is considerably empty and ready for new async action. self.wait_all_finish() if action in self._fast_queue or action in self._slow_queue: raise NmstateInternalError( f"BUG: An existing actions {action} is already registered") logging.debug(f"Async action: {action} started") queue.add(action)
def context(self): if not self._context: raise NmstateInternalError( "BUG: Accessing MainContext while it is None") return self._context
def remove_slave(self, slave_name): if not self.is_master: class_name = self.__class__.__name__ raise NmstateInternalError( f"Invalid invoke of {class_name}.remove_slave({slave_name}) " f"as {class_name} is not a master interface")