def assert_ifaces_state(ifaces_desired_state, ifaces_current_state): if not (set(ifaces_desired_state) <= set(ifaces_current_state)): raise DesiredStateIsNotCurrentError( format_desired_current_state_diff(ifaces_desired_state, ifaces_current_state) ) for ifname in ifaces_desired_state: iface_cstate = ifaces_current_state[ifname] iface_dstate = _canonicalize_desired_state( ifaces_desired_state[ifname], iface_cstate) iface_dstate, iface_cstate = _cleanup_iface_ethernet_state_sanitize( iface_dstate, iface_cstate) iface_dstate, iface_cstate = _sort_lag_slaves( iface_dstate, iface_cstate) iface_dstate, iface_cstate = _canonicalize_ipv6_state( iface_dstate, iface_cstate) iface_dstate, iface_cstate = _remove_iface_ipv6_link_local_addr( iface_dstate, iface_cstate) iface_cstate = sanitize_dhcp_state({ifname: iface_cstate})[ifname] iface_dstate, iface_cstate = _sort_ip_addresses( iface_dstate, iface_cstate) if iface_dstate != iface_cstate: raise DesiredStateIsNotCurrentError( format_desired_current_state_diff(iface_dstate, iface_cstate) )
def _assert_interfaces_included_in(self, current_state): if not (set(self.interfaces) <= set(current_state.interfaces)): raise NmstateVerificationError( format_desired_current_state_diff( self.interfaces, current_state.interfaces ) )
def verify_dns(self, other_state): if self.config_dns != other_state.config_dns: raise NmstateVerificationError( format_desired_current_state_diff( {DNS.KEY: self.config_dns}, {DNS.KEY: other_state.config_dns}, ))
def verify(self, cur_rule_state): current = RouteRuleState( route_state=None, des_rule_state=None, cur_rule_state=cur_rule_state, ) for route_table, rules in self._rules.items(): rule_info = [ _remove_route_rule_default_values(r.to_dict()) for r in sorted(rules) ] cur_rule_info = [ r.to_dict() for r in sorted(current._rules.get(route_table, set())) ] if not state_match(rule_info, cur_rule_info): raise NmstateVerificationError( format_desired_current_state_diff( {RouteRule.KEY: { RouteRule.CONFIG: rule_info }}, {RouteRule.KEY: { RouteRule.CONFIG: cur_rule_info }}, ))
def verify(self, cur_dns_state): cur_dns = DnsState(des_dns_state=None, cur_dns_state=cur_dns_state,) if self.config != cur_dns.config: raise NmstateVerificationError( format_desired_current_state_diff( {DNS.KEY: self.config}, {DNS.KEY: cur_dns.config}, ) )
def verify_routes(self, other_state): for iface_name, routes in six.viewitems(self.config_iface_routes): other_routes = other_state.config_iface_routes.get(iface_name, []) if routes != other_routes: raise NmstateVerificationError( format_desired_current_state_diff( {Route.KEY: [r.to_dict() for r in routes]}, {Route.KEY: [r.to_dict() for r in other_routes]}, ))
def verify(self, cur_iface_infos): cur_ifaces = Ifaces( des_iface_infos=None, cur_iface_infos=cur_iface_infos, save_to_disk=self._save_to_disk, ) cur_ifaces._remove_unknown_interface_type_slaves() for iface in self._ifaces.values(): if iface.is_desired: if iface.is_virtual and iface.original_dict.get( Interface.STATE) in (InterfaceState.DOWN, InterfaceState.ABSENT): cur_iface = cur_ifaces.get(iface.name) if cur_iface: raise NmstateVerificationError( format_desired_current_state_diff( iface.original_dict, cur_iface.state_for_verify(), )) elif iface.is_up or (iface.is_down and not iface.is_virtual): cur_iface = cur_ifaces.get(iface.name) if not cur_iface: raise NmstateVerificationError( format_desired_current_state_diff( iface.original_dict, {})) elif not iface.match(cur_iface): if iface.type == InterfaceType.LINUX_BRIDGE: ( key, value, cur_value, ) = LinuxBridgeIface.is_integer_rounded( iface, cur_iface) if key: raise NmstateKernelIntegerRoundedError( "Linux kernel configured with 250 HZ " "will round up/down the integer in linux " f"bridge {iface.name} option '{key}' " f"from {value} to {cur_value}.") raise NmstateVerificationError( format_desired_current_state_diff( iface.state_for_verify(), cur_iface.state_for_verify(), ))
def _assert_interfaces_equal(self, current_state): for ifname in self.interfaces: iface_dstate = self.interfaces[ifname] iface_cstate = current_state.interfaces[ifname] if not state_match(iface_dstate, iface_cstate): raise NmstateVerificationError( format_desired_current_state_diff( self.interfaces[ifname], current_state.interfaces[ifname], ))
def verify(self, cur_iface_infos): cur_ifaces = Ifaces( des_iface_infos=None, cur_iface_infos=cur_iface_infos, save_to_disk=self._save_to_disk, ) for iface in self._ifaces.values(): if iface.is_desired: if iface.is_up or (iface.is_down and not iface.is_virtual): cur_iface = cur_ifaces.get(iface.name) if not cur_iface: raise NmstateVerificationError( format_desired_current_state_diff( iface.original_dict, {})) elif not iface.match(cur_iface): raise NmstateVerificationError( format_desired_current_state_diff( iface.state_for_verify(), cur_iface.state_for_verify(), ))
def verify(self, cur_dns_state): cur_dns = DnsState( des_dns_state=None, cur_dns_state=cur_dns_state, ) if self.config.get(DNS.SERVER, []) != cur_dns.config.get( DNS.SERVER, []) or self.config.get( DNS.SEARCH, []) != cur_dns.config.get(DNS.SEARCH, []): raise NmstateVerificationError( format_desired_current_state_diff( {DNS.KEY: self.config}, {DNS.KEY: cur_dns.config}, ))
def _verify_route_rules(self_indexed_rules, other_indexed_rules): for table_id, rules in self_indexed_rules.items(): self_rules = [ _remove_route_rule_default_values(rule.to_dict()) for rule in rules ] other_rules = [ rule.to_dict() for rule in other_indexed_rules.get(table_id, []) ] if not state_match(self_rules, other_rules): raise NmstateVerificationError( format_desired_current_state_diff( {RouteRule.KEY: {RouteRule.CONFIG: self_rules}}, {RouteRule.KEY: {RouteRule.CONFIG: other_rules}}, ) )
def verify(self, cur_route_state): current = RouteState(ifaces=None, des_route_state=None, cur_route_state=cur_route_state) for iface_name, route_set in self._routes.items(): routes_info = [r.to_dict() for r in sorted(route_set)] cur_routes_info = [ r.to_dict() for r in sorted(current._routes.get(iface_name, set())) ] if not state_match(routes_info, cur_routes_info): raise NmstateVerificationError( format_desired_current_state_diff( {Route.KEY: { Route.CONFIG: routes_info }}, {Route.KEY: { Route.CONFIG: cur_routes_info }}, ))