def activate_changes_wait_for_completion(params): """Wait for activation completion This endpoint will periodically redirect on itself to prevent timeouts. """ activation_id = params["activation_id"] manager = watolib.ActivateChangesManager() manager.load() try: manager.load_activation(activation_id) except MKUserError: raise ProblemException( status=404, title=f"Activation {activation_id!r} not found.") done = manager.wait_for_completion(timeout=request.request_timeout - 10) if not done: response = Response(status=302) response.location = request.url return response return Response(status=204)
def _activate_changes(self, request): mode = request.get("mode", "dirty") if request.get("allow_foreign_changes"): allow_foreign_changes = bool(int(request.get("allow_foreign_changes"))) else: allow_foreign_changes = False sites = request.get("sites") changes = watolib.ActivateChanges() changes.load() if changes.has_foreign_changes(): if not config.user.may("wato.activateforeign"): raise MKAuthException(_("You are not allowed to activate changes of other users.")) if not allow_foreign_changes: raise MKAuthException( _("There are changes from other users and foreign changes are not allowed in this API call." )) if mode == "specific": for site in sites: if site not in config.allsites().keys(): raise MKUserError(None, _("Unknown site %s") % escaping.escape_attribute(site)) manager = watolib.ActivateChangesManager() manager.load() if not manager.has_changes(): raise MKUserError(None, _("Currently there are no changes to activate.")) if not sites: sites = manager.dirty_and_active_activation_sites() comment = request.get("comment", "").strip() if comment == "": comment = None manager.start(sites, comment=comment, activate_foreign=allow_foreign_changes) manager.wait_for_completion() return manager.get_state()
def page(self): watolib.init_wato_datastructures(with_wato_lock=True) config.user.need_permission("wato.activate") request = self.webapi_request() activate_until = request.get("activate_until") if not activate_until: raise MKUserError( "activate_until", _("Missing parameter \"%s\".") % "activate_until") manager = watolib.ActivateChangesManager() manager.load() affected_sites_request = six.ensure_str( request.get("sites", "").strip()) if not affected_sites_request: affected_sites = manager.dirty_and_active_activation_sites() else: affected_sites = affected_sites_request.split(",") comment = request.get("comment", "").strip() # type: Optional[str] if comment == "": comment = None activate_foreign = request.get("activate_foreign", "0") == "1" activation_id = manager.start( sites=affected_sites, activate_until=six.ensure_str(activate_until), comment=None if comment is None else six.ensure_str(comment), activate_foreign=activate_foreign, ) return { "activation_id": activation_id, }