def __init__(self, config, spec, exclude, mountpoint): InsightsSpec.__init__(self, config, spec, exclude) self.command = spec['command'].replace( '{CONTAINER_MOUNT_POINT}', mountpoint) self.archive_path = mangle.mangle_command(self.command) if not six.PY3: self.command = self.command.encode('utf-8', 'ignore')
def __init__(self, config, spec, exclude, mountpoint, parent_pid=None): InsightsSpec.__init__(self, config, spec, exclude, parent_pid) self.command = spec['command'].replace('{CONTAINER_MOUNT_POINT}', mountpoint) self.archive_path = mangle.mangle_command(self.command) self.is_hostname = spec.get('symbolic_name') == 'hostname' if not six.PY3: self.command = self.command.encode('utf-8', 'ignore')
def __init__(self, config, spec, mountpoint): super(InsightsCommand, self).__init__(config, spec) self.command = spec['command'].replace('{CONTAINER_MOUNT_POINT}', mountpoint) self.archive_path = mangle.mangle_command(self.command) self.is_hostname = spec.get('symbolic_name') == 'hostname' if not six.PY3: self.command = self.command.encode('utf-8', 'ignore')
def run_collection(self, conf, rm_conf, branch_info): ''' Run specs and collect all the data ''' if rm_conf is None: rm_conf = {} logger.debug('Beginning to run collection spec...') exclude = None if rm_conf: try: exclude = rm_conf['patterns'] logger.warn("WARNING: Skipping patterns found in remove.conf") except LookupError: logger.debug('Patterns section of remove.conf is empty.') for c in conf['commands']: # remember hostname archive path if c.get('symbolic_name') == 'hostname': self.hostname_path = os.path.join( 'insights_commands', mangle.mangle_command(c['command'])) rm_commands = rm_conf.get('commands', []) if c['command'] in rm_commands or c.get( 'symbolic_name') in rm_commands: logger.warn("WARNING: Skipping command %s", c['command']) elif self.mountpoint == "/" or c.get("image"): cmd_specs = self._parse_command_spec(c, conf['pre_commands']) for s in cmd_specs: cmd_spec = InsightsCommand(self.config, s, exclude, self.mountpoint) self.archive.add_to_archive(cmd_spec) for f in conf['files']: rm_files = rm_conf.get('files', []) if f['file'] in rm_files or f.get('symbolic_name') in rm_files: logger.warn("WARNING: Skipping file %s", f['file']) else: file_specs = self._parse_file_spec(f) for s in file_specs: # filter files post-wildcard parsing if s['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", s['file']) else: file_spec = InsightsFile(s, exclude, self.mountpoint) self.archive.add_to_archive(file_spec) if 'globs' in conf: for g in conf['globs']: glob_specs = self._parse_glob_spec(g) for g in glob_specs: if g['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", g) else: glob_spec = InsightsFile(g, exclude, self.mountpoint) self.archive.add_to_archive(glob_spec) logger.debug('Spec collection finished.') # collect metadata logger.debug('Collecting metadata...') self._write_branch_info(branch_info) logger.debug('Metadata collection finished.')
def run_collection(self, conf, rm_conf, branch_info, blacklist_report): ''' Run specs and collect all the data ''' parent_pid = read_pidfile() if rm_conf is None: rm_conf = {} logger.debug('Beginning to run collection spec...') exclude = None if rm_conf: try: exclude = rm_conf['patterns'] # handle the None or empty case of the sub-object if 'regex' in exclude and not exclude['regex']: raise LookupError logger.warn( "WARNING: Skipping patterns defined in blacklist configuration" ) except LookupError: logger.debug( 'Patterns section of blacklist configuration is empty.') for c in conf['commands']: # remember hostname archive path if c.get('symbolic_name') == 'hostname': self.hostname_path = os.path.join( 'insights_commands', mangle.mangle_command(c['command'])) rm_commands = rm_conf.get('commands', []) if c['command'] in rm_commands or c.get( 'symbolic_name') in rm_commands: logger.warn("WARNING: Skipping command %s", c['command']) elif self.mountpoint == "/" or c.get("image"): cmd_specs = self._parse_command_spec(c, conf['pre_commands']) for s in cmd_specs: if s['command'] in rm_commands: logger.warn("WARNING: Skipping command %s", s['command']) continue cmd_spec = InsightsCommand(self.config, s, exclude, self.mountpoint, parent_pid) self.archive.add_to_archive(cmd_spec) for f in conf['files']: rm_files = rm_conf.get('files', []) if f['file'] in rm_files or f.get('symbolic_name') in rm_files: logger.warn("WARNING: Skipping file %s", f['file']) else: file_specs = self._parse_file_spec(f) for s in file_specs: # filter files post-wildcard parsing if s['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", s['file']) else: file_spec = InsightsFile(s, exclude, self.mountpoint, parent_pid) self.archive.add_to_archive(file_spec) if 'globs' in conf: for g in conf['globs']: glob_specs = self._parse_glob_spec(g) for g in glob_specs: if g['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", g) else: glob_spec = InsightsFile(g, exclude, self.mountpoint, parent_pid) self.archive.add_to_archive(glob_spec) logger.debug('Spec collection finished.') # collect metadata logger.debug('Collecting metadata...') self._write_branch_info(branch_info) self._write_display_name() self._write_version_info() self._write_tags() self._write_blacklist_report(blacklist_report) logger.debug('Metadata collection finished.')
def run_collection(self, conf, rm_conf, branch_info, blacklist_report): ''' Run specs and collect all the data ''' # initialize systemd-notify thread systemd_notify_init_thread() self.archive.create_archive_dir() self.archive.create_command_dir() collection_stats = {} if rm_conf is None: rm_conf = {} logger.debug('Beginning to run collection spec...') for c in conf['commands']: # remember hostname archive path if c.get('symbolic_name') == 'hostname': self.hostname_path = os.path.join( 'insights_commands', mangle.mangle_command(c['command'])) rm_commands = rm_conf.get('commands', []) if c['command'] in rm_commands or c.get( 'symbolic_name') in rm_commands: logger.warn("WARNING: Skipping command %s", c['command']) elif self.mountpoint == "/" or c.get("image"): cmd_specs = self._parse_command_spec(c, conf['pre_commands']) for s in cmd_specs: if s['command'] in rm_commands: logger.warn("WARNING: Skipping command %s", s['command']) continue cmd_spec = InsightsCommand(self.config, s, self.mountpoint) self.archive.add_to_archive(cmd_spec) collection_stats[s['command']] = { 'return_code': cmd_spec.return_code, 'exec_time': cmd_spec.exec_time, 'output_size': cmd_spec.output_size } for f in conf['files']: rm_files = rm_conf.get('files', []) if f['file'] in rm_files or f.get('symbolic_name') in rm_files: logger.warn("WARNING: Skipping file %s", f['file']) else: file_specs = self._parse_file_spec(f) for s in file_specs: # filter files post-wildcard parsing if s['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", s['file']) else: file_spec = InsightsFile(s, self.mountpoint) self.archive.add_to_archive(file_spec) collection_stats[s['file']] = { 'exec_time': file_spec.exec_time, 'output_size': file_spec.output_size } if 'globs' in conf: for g in conf['globs']: glob_specs = self._parse_glob_spec(g) for g in glob_specs: if g['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", g) else: glob_spec = InsightsFile(g, self.mountpoint) self.archive.add_to_archive(glob_spec) collection_stats[g['file']] = { 'exec_time': glob_spec.exec_time, 'output_size': glob_spec.output_size } logger.debug('Spec collection finished.') self.redact(rm_conf) # collect metadata logger.debug('Collecting metadata...') self._write_branch_info(branch_info) self._write_display_name() self._write_version_info() self._write_tags() self._write_blacklist_report(blacklist_report) self._write_egg_release() self._write_collection_stats(collection_stats) logger.debug('Metadata collection finished.')
def run_collection(self, conf, rm_conf, branch_info): ''' Run specs and collect all the data ''' if rm_conf is None: rm_conf = {} logger.debug('Beginning to run collection spec...') exclude = None if rm_conf: try: exclude = rm_conf['patterns'] except LookupError: logger.debug('Could not parse remove.conf. Ignoring...') if self.config.run_specific_specs is not None: logger.debug('Running specific specs %s', self.config.run_specific_specs) for specific_spec in self.config.run_specific_specs.split(','): logger.debug('Running specific spec %s', specific_spec) self.run_specific_specs(specific_spec, conf, rm_conf, exclude, branch_info) logger.debug('Finished running specific spec %s', specific_spec) return for c in conf['commands']: # remember hostname archive path if c.get('symbolic_name') == 'hostname': self.hostname_path = os.path.join( 'insights_commands', mangle.mangle_command(c['command'])) if c['command'] in rm_conf.get('commands', []): logger.warn("WARNING: Skipping command %s", c['command']) elif self.mountpoint == "/" or c.get("image"): cmd_specs = self._parse_command_spec(c, conf['pre_commands']) for s in cmd_specs: cmd_spec = InsightsCommand(self.config, s, exclude, self.mountpoint) self.archive.add_to_archive(cmd_spec) for f in conf['files']: if f['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", f['file']) else: file_specs = self._parse_file_spec(f) for s in file_specs: file_spec = InsightsFile(s, exclude, self.mountpoint) self.archive.add_to_archive(file_spec) if 'globs' in conf: for g in conf['globs']: glob_specs = self._parse_glob_spec(g) for g in glob_specs: if g['file'] in rm_conf.get('files', []): logger.warn("WARNING: Skipping file %s", g) else: glob_spec = InsightsFile(g, exclude, self.mountpoint) self.archive.add_to_archive(glob_spec) logger.debug('Spec collection finished.') # collect metadata logger.debug('Collecting metadata...') self._write_branch_info(branch_info) logger.debug('Metadata collection finished.')