def _synchronize_profile(self, site_id, site, user_id): users = userdb.load_users(lock=False) if user_id not in users: raise MKUserError(None, _('The requested user does not exist')) start = time.time() result = push_user_profiles_to_site_transitional_wrapper(site, {user_id: users[user_id]}) duration = time.time() - start watolib.ActivateChanges().update_activation_time(site_id, ACTIVATION_TIME_PROFILE_SYNC, duration) return result
def user_profile_async_replication_dialog(sites: List[SiteId], back_url: str) -> None: html.p( _( "In order to activate your changes available on all remote sites, your user profile needs " "to be replicated to the remote sites. This is done on this page now. Each site " "is being represented by a single image which is first shown gray and then fills " "to green during synchronisation." ) ) html.h3(_("Replication States")) html.open_div(id_="profile_repl") num_replsites = 0 for site_id in sites: site = config.sites[site_id] if "secret" not in site: status_txt = _("Not logged in.") start_sync = False icon = "repl_locked" else: status_txt = _("Waiting for replication to start") start_sync = True icon = "repl_pending" html.open_div(class_="site", id_="site-%s" % site_id) html.div("", title=status_txt, class_=["icon", "repl_status", icon]) if start_sync: changes_manager = watolib.ActivateChanges() changes_manager.load() estimated_duration = changes_manager.get_activation_time( site_id, ACTIVATION_TIME_PROFILE_SYNC, 2.0 ) html.javascript( "cmk.profile_replication.start(%s, %d, %s);" % ( json.dumps(site_id), int(estimated_duration * 1000.0), json.dumps(_("Replication in progress")), ) ) num_replsites += 1 else: _add_profile_replication_change(site_id, status_txt) html.span(site.get("alias", site_id)) html.close_div() html.javascript( "cmk.profile_replication.prepare(%d, %s);\n" % (num_replsites, json.dumps(back_url)) ) html.close_div()
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 user_profile_async_replication_dialog(sites): html.p( _('In order to activate your changes available on all remote sites, your user profile needs ' 'to be replicated to the remote sites. This is done on this page now. Each site ' 'is being represented by a single image which is first shown gray and then fills ' 'to green during synchronisation.')) html.h3(_('Replication States')) html.open_div(id_="profile_repl") num_replsites = 0 for site_id in sites: site = config.sites[site_id] if "secret" not in site: status_txt = _('Not logged in.') start_sync = False icon = 'repl_locked' else: status_txt = _('Waiting for replication to start') start_sync = True icon = 'repl_pending' html.open_div(class_="site", id_="site-%s" % site_id) html.div("", title=status_txt, class_=["icon", "repl_status", icon]) if start_sync: changes_manager = watolib.ActivateChanges() changes_manager.load() estimated_duration = changes_manager.get_activation_time( site_id, ACTIVATION_TIME_PROFILE_SYNC, 2.0) html.javascript( 'cmk.profile_replication.start(\'%s\', %d, \'%s\');' % (site_id, int(estimated_duration * 1000.0), _('Replication in progress'))) num_replsites += 1 else: _add_profile_replication_change(site_id, status_txt) html.span(site.get('alias', site_id)) html.close_div() html.javascript('cmk.profile_replication.prepare(%d);\n' % num_replsites) html.close_div()