def __init__(self, filename, text, provider): """ Initialize the plug-in with the specified name text """ self._filename = filename self._job_list = [] logger.debug(_("Loading jobs definitions from %r..."), filename) try: records = load_rfc822_records( text, source=FileTextSource(filename)) except RFC822SyntaxError as exc: raise PlugInError( _("Cannot load job definitions from {!r}: {}").format( filename, exc)) for record in records: try: job = JobDefinition.from_rfc822_record(record) except ValueError as exc: raise PlugInError( _("Cannot define job from record {!r}: {}").format( record, exc)) else: job._provider = provider self._job_list.append(job) logger.debug(_("Loaded %r"), job)
def run_local_job(self, checksum, env): """ Run a job with and interpret the stdout as a job definition. :param checksum: The checksum of the job to execute :param env: Environment to execute the job in. :returns: A list of job definitions that were parsed out of the output. :raises LookupError: If the checksum does not match any known job """ job = self.find_job(checksum) cmd = ["bash", "-c", job.command] output = subprocess.check_output(cmd, universal_newlines=True, env=self.modify_execution_environment(env)) job_list = [] source = JobOutputTextSource(job) try: record_list = load_rfc822_records(output, source=source) except RFC822SyntaxError as exc: logging.error(_("Syntax error in job generated from %s: %s"), job, exc) else: for record in record_list: job = JobDefinition.from_rfc822_record(record) job_list.append(job) return job_list
def run_local_job(self, checksum, env): """ Run a job with and interpret the stdout as a job definition. :param checksum: The checksum of the job to execute :param env: Environment to execute the job in. :returns: A list of job definitions that were parsed out of the output. :raises LookupError: If the checksum does not match any known job """ job = self.find_job(checksum) cmd = ['bash', '-c', job.command] output = subprocess.check_output( cmd, universal_newlines=True, env=self.modify_execution_environment(env)) job_list = [] source = JobOutputTextSource(job) try: record_list = load_rfc822_records(output, source=source) except RFC822SyntaxError as exc: logging.error(_("Syntax error in job generated from %s: %s"), job, exc) else: for record in record_list: job = JobDefinition.from_rfc822_record(record) job_list.append(job) return job_list
def __init__(self, filename, text, provider): """ Initialize the plug-in with the specified name text """ self._filename = filename self._job_list = [] logger.debug(_("Loading jobs definitions from %r..."), filename) try: records = load_rfc822_records(text, source=FileTextSource(filename)) except RFC822SyntaxError as exc: raise PlugInError( _("Cannot load job definitions from {!r}: {}").format( filename, exc)) for record in records: try: job = JobDefinition.from_rfc822_record(record) except ValueError as exc: raise PlugInError( _("Cannot define job from record {!r}: {}").format( record, exc)) else: job._provider = provider self._job_list.append(job) logger.debug(_("Loaded %r"), job)
def run_generator_job(self, checksum, env): """ Run a job with and process the stdout to get a job definition. :param checksum: The checksum of the job to execute :param env: Environment to execute the job in. :returns: A list of job definitions that were processed from the output. :raises LookupError: If the checksum does not match any known job """ job = self.find_job(checksum) cmd = [job.shell, '-c', job.command] output = subprocess.check_output( cmd, universal_newlines=True, env=self.modify_execution_environment(env)) job_list = [] source = JobOutputTextSource(job) try: record_list = load_rfc822_records(output, source=source) except RFC822SyntaxError as exc: logging.error(_("Syntax error in record generated from %s: %s"), job, exc) else: if job.plugin == 'local': for record in record_list: job = JobDefinition.from_rfc822_record(record) job_list.append(job) elif job.plugin == 'resource': resource_list = [] for record in record_list: resource = Resource(record.data) resource_list.append(resource) for plugin in all_providers.get_all_plugins(): for u in plugin.plugin_object.unit_list: if (isinstance(u, TemplateUnit) and u.resource_id == job.id): logging.info(_("Instantiating unit: %s"), u) for new_unit in u.instantiate_all(resource_list): job_list.append(new_unit) return job_list