def log_msg(self, level: int, msg: str, args: Sequence[object], kwargs: Dict[str, object]) -> None: if len(args) > 0: raise Exception("Args not supported") if "exc_info" in kwargs: exc_info = kwargs["exc_info"] kwargs["traceback"] = traceback.format_exc() else: exc_info = False try: json_encode(kwargs) except Exception as e: raise Exception( "Exception during serializing log message arguments") from e log = data.LogLine.log(level, msg, **kwargs) self.logger.log(level, "resource %s: %s", self._resource.id.resource_version_str(), log._data["msg"], exc_info=exc_info) self._logs.append(log)
def run(self, types, scopes, no_commit=False, include_status=False): """ Run the export functions """ self.types = types self.scopes = scopes self._version = int(time.time()) # first run other export plugins self._run_export_plugins() if types is not None: # then process the configuration model to submit it to the mgmt server self._load_resources(types) # call dependency managers self._call_dep_manager(types) # validate the dependency graph self._validate_graph() resources = self.resources_to_list() if len(self._resources) == 0: LOGGER.warning("Empty deployment model.") if self.options and self.options.json: with open(self.options.json, "wb+") as fd: fd.write(protocol.json_encode(resources).encode("utf-8")) elif len(self._resources ) > 0 or len(unknown_parameters) > 0 and not no_commit: self.commit_resources(self._version, resources) LOGGER.info("Committed resources with version %d" % self._version) if include_status: return self._version, self._resources, self._resource_state return self._version, self._resources
def run( self, types: Optional[Dict[str, Entity]], scopes: Optional[Namespace], metadata: Dict[str, str] = {}, no_commit: bool = False, include_status: bool = False, model_export: bool = False, export_plugin: Optional[str] = None, ) -> None: """ Run the export functions """ self.types = types self.scopes = scopes self._version = self.get_version(no_commit) if types is not None: # then process the configuration model to submit it to the mgmt server self._load_resources(types) # call dependency managers self._call_dep_manager(types) metadata[const. META_DATA_COMPILE_STATE] = const.Compilestate.success.name self.failed = False else: metadata[ const.META_DATA_COMPILE_STATE] = const.Compilestate.failed.name self.failed = True LOGGER.warning("Compilation of model failed.") if not self.failed: if export_plugin is not None: # Run export plugin specified on CLI self.run_export_plugin(export_plugin) else: self._run_export_plugins_specified_in_config_file() # validate the dependency graph self._validate_graph() resources = self.resources_to_list() if len(self._resources) == 0: LOGGER.warning("Empty deployment model.") model: Optional[Dict[str, Any]] = {} if self.options and self.options.json: with open(self.options.json, "wb+") as fd: fd.write(protocol.json_encode(resources).encode("utf-8")) if types is not None and model_export: if len(self._resources) > 0 or len(unknown_parameters) > 0: model = ModelExporter(types).export_all() with open(self.options.json + ".types", "wb+") as fd: fd.write(protocol.json_encode(model).encode("utf-8")) elif (not self.failed or len(self._resources) > 0 or len(unknown_parameters) > 0) and not no_commit: model = None if types is not None and model_export: model = ModelExporter(types).export_all() self.commit_resources(self._version, resources, metadata, model) LOGGER.info("Committed resources with version %d" % self._version) if include_status: return self._version, self._resources, self._resource_state, model return self._version, self._resources
def finalize_context(self, ctx: handler.HandlerContext): # ensure logs can be serialized json_encode({"message": ctx.logs})