def execute(self, request): # type: (PushSnapshotRequest) -> bool with store.lock_checkmk_configuration(): multitar.extract_from_buffer(request.tar_content, cmk.gui.watolib.activate_changes.get_replication_paths()) try: self._save_site_globals_on_slave_site(request.tar_content) # pending changes are lost cmk.gui.watolib.activate_changes.confirm_all_local_changes() hooks.call("snapshot-pushed") # Create rule making this site only monitor our hosts create_distributed_wato_file(request.site_id, is_slave=True) except Exception: raise MKGeneralException( _("Failed to deploy configuration: \"%s\". " "Please note that the site configuration has been synchronized " "partially.") % traceback.format_exc()) cmk.gui.watolib.changes.log_audit( None, "replication", _("Synchronized with master (my site id is %s.)") % request.site_id) return True
def _save_site_globals_on_slave_site(self, tarcontent): tmp_dir = cmk.utils.paths.tmp_dir + "/sitespecific-%s" % id(html) try: if not os.path.exists(tmp_dir): store.mkdir(tmp_dir) multitar.extract_from_buffer(tarcontent, [("dir", "sitespecific", tmp_dir)]) site_globals = store.load_object_from_file(tmp_dir + "/sitespecific.mk", default={}) save_site_global_settings(site_globals) finally: shutil.rmtree(tmp_dir)