def _apply_ifaces_state( desired_state, verify_change, commit, rollback_timeout ): current_state = state.State(netinfo.show()) desired_state.sanitize_ethernet(current_state) desired_state.sanitize_dynamic_ip() desired_state.merge_routes(current_state) desired_state.merge_dns(current_state) metadata.generate_ifaces_metadata(desired_state, current_state) validator.validate_interfaces_state(desired_state, current_state) validator.validate_routes(desired_state, current_state) new_interfaces = _list_new_interfaces(desired_state, current_state) try: with nm.checkpoint.CheckPoint( autodestroy=commit, timeout=rollback_timeout ) as checkpoint: with _setup_providers(): _add_interfaces(new_interfaces, desired_state) state2edit = _create_editable_desired_state( desired_state, current_state, new_interfaces ) _edit_interfaces(state2edit) if verify_change: _verify_change(desired_state) if not commit: return checkpoint except nm.checkpoint.NMCheckPointPermissionError: raise NmstatePermissionError('Error creating a check point') except nm.checkpoint.NMCheckPointCreationError: raise NmstateConflictError('Error creating a check point')
def _apply_ifaces_state(desired_state, verify_change, commit, rollback_timeout): original_desired_state = copy.deepcopy(desired_state) current_state = state.State(netinfo.show()) desired_state.sanitize_ethernet(current_state) desired_state.sanitize_dynamic_ip() desired_state.merge_routes(current_state) desired_state.merge_dns(current_state) desired_state.merge_route_rules(current_state) desired_state.remove_unknown_interfaces() desired_state.complement_master_interfaces_removal(current_state) metadata.generate_ifaces_metadata(desired_state, current_state) validator.validate_interfaces_state(original_desired_state, current_state) validator.validate_routes(desired_state, current_state) try: with nm.checkpoint.CheckPoint(autodestroy=commit, timeout=rollback_timeout) as checkpoint: with _setup_providers(): state2edit = state.State(desired_state.state) state2edit.merge_interfaces(current_state) nm.applier.apply_changes( list(state2edit.interfaces.values()), original_desired_state, ) verified = False if verify_change: for _ in range(VERIFY_RETRY_TIMEOUT): try: _verify_change(desired_state) verified = True break except NmstateVerificationError: time.sleep(VERIFY_RETRY_INTERNAL) if not verified: _verify_change(desired_state) if not commit: return checkpoint except nm.checkpoint.NMCheckPointPermissionError: raise NmstatePermissionError("Error creating a check point") except nm.checkpoint.NMCheckPointCreationError: raise NmstateConflictError("Error creating a check point") except NmstateError: # Assume rollback occurred. # Checkpoint rollback is async, there is a need to wait for it to # finish before proceeding with other actions. time.sleep(5) raise
def _apply_ifaces_state( desired_state, verify_change, commit, rollback_timeout ): current_state = state.State(netinfo.show()) desired_state.sanitize_ethernet(current_state) desired_state.sanitize_dynamic_ip() desired_state.merge_routes(current_state) desired_state.merge_dns(current_state) metadata.generate_ifaces_metadata(desired_state, current_state) validator.validate_interfaces_state(desired_state, current_state) validator.validate_routes(desired_state, current_state) new_interfaces = _list_new_interfaces(desired_state, current_state) try: with nm.checkpoint.CheckPoint( autodestroy=commit, timeout=rollback_timeout ) as checkpoint: with _setup_providers(): ifaces2add, ifaces_add_configs = _add_interfaces( new_interfaces, desired_state ) state2edit = _create_editable_desired_state( desired_state, current_state, new_interfaces ) ifaces2edit, ifaces_edit_configs = _edit_interfaces(state2edit) nm.applier.set_ifaces_admin_state( ifaces2add + ifaces2edit, con_profiles=ifaces_add_configs + ifaces_edit_configs, ) _disable_ipv6(desired_state) if verify_change: _verify_change(desired_state) if not commit: return checkpoint except nm.checkpoint.NMCheckPointPermissionError: raise NmstatePermissionError('Error creating a check point') except nm.checkpoint.NMCheckPointCreationError: raise NmstateConflictError('Error creating a check point') except NmstateError: # Assume rollback occured, revert IPv6 stack state. # Checkpoint rollback is async, there is a need to wait for it to # finish before proceeding with other actions. # TODO: https://nmstate.atlassian.net/browse/NMSTATE-103 time.sleep(5) _disable_ipv6(current_state) raise