Esempio n. 1
0
    def execute(self, event, user_id: int, user_name: str, log_flag: bool = True) -> ExportdHeader:
        # get cmdb objects from all sources
        cmdb_objects = set()
        exportd_header = ExportdHeader()
        for source in self.sources:
            cmdb_objects.update(source.get_objects())

        # for every destination: do export
        for destination in self.destinations:
            external_system = destination.get_external_system()
            external_system.prepare_export()

            for cmdb_object in cmdb_objects:
                # setup objectdata for use in ExportVariable templates
                template_data = ObjectTemplateData(self.__object_manager, cmdb_object).get_template_data()
                external_system.add_object(cmdb_object, template_data)
            exportd_header = external_system.finish_export()

            if log_flag:
                try:
                    log_params = {
                        'job_id': self.job.get_public_id(),
                        'state': True,
                        'user_id': user_id,
                        'user_name': user_name,
                        'event': event.get_type(),
                        'message': external_system.msg_string,
                    }
                    self.log_manager.insert_log(action=LogAction.EXECUTE, log_type=ExportdJobLog.__name__, **log_params)
                except LogManagerInsertError as err:
                    LOGGER.error(err)
        return exportd_header
 def finish_export(self):
     json_data = json.dumps(self.__rows)
     header = ExportdHeader(json_data)
     return header
 def finish_export(self):
     # create JSON
     groups = self.ansible_groups
     groups.update({'_meta': {'hostvars': self.ansible_hostvars}})
     header = ExportdHeader(json.dumps(groups))
     return header