def execute_live(args): """Execute inventory at container build time We assume a mounted working directory is ready to inventory""" logger.debug('Starting analysis...') # create the working directory setup() # create a layer object to bundle package metadata into layer = ImageLayer("") # see if there is an os-release file at the mount point layer.os_guess = single_layer.find_os_release(args.live) # create a Prereqs object to store requirements to inventory prereqs = core.Prereqs() prereqs.host_path = os.path.abspath(args.live) # Find a shell that may exist in the layer prereqs.fs_shell = dcom.find_shell(prereqs.host_path) # Find the host's shell prereqs.host_shell = host.check_shell() # collect metadata into the layer object fill_packages(layer, prereqs) # resolve unique packages for this run with reports from previous runs if args.with_context: # get a list of previous layers based on plugin type context_layers = get_context_layers(args.with_context, args.report_format) # resolve the packages for each of the layers context_layers.append(layer) resolve_context_packages(context_layers) final_layer = context_layers.pop() else: final_layer = layer # report out the packages logger.debug("Preparing report") report.report_layer(final_layer, args)
def create_image_layer(report): """Given a report file, create an ImageLayer object with the metadata""" # expect a json input, raise an error if it is not content = {} try: with open(os.path.abspath(report), encoding='utf-8') as f: content = json.load(f) except OSError as err: logger.critical("Cannot access file %s: %s", report, err) raise ConsumerError(f"Error with given report file: {report}") from err except json.JSONDecodeError as err: logger.critical("Cannot parse JSON in file %s: %s", report, err) raise ConsumerError(f"Error with given report file: {report}") from err # we should have some content but it may be empty if not content: raise ConsumerError("No content consumed from given report file") # instantiate a layer and fill it layer = ImageLayer("") try: layer.os_guess = content['os_guess'] for pkg in content['packages']: pkg_obj = Package(pkg['name']) pkg_obj.fill(pkg) layer.add_package(pkg_obj) for filedict in content['files']: file_obj = FileData(filedict['name'], filedict['path']) file_obj.fill(filedict) layer.add_file(file_obj) return layer except ValueError as err: logger.critical("Cannot find required data in report: %s", err) return None
def execute_live(args): """Execute inventory at container build time We assume a mounted working directory is ready to inventory""" logger.debug('Starting analysis...') # create the working directory setup() # create a layer object to bundle package metadata into layer = ImageLayer("") # see if there is an os-release file at the mount point layer.os_guess = single_layer.find_os_release(args.live) # create a Prereqs object to store requirements to inventory prereqs = core.Prereqs() prereqs.host_path = os.path.abspath(args.live) # Find a shell that may exist in the layer prereqs.fs_shell = dcom.find_shell(prereqs.host_path) # Find the host's shell prereqs.host_shell = host.check_shell() # collect metadata into the layer object fill_packages(layer, prereqs) # report out the packages report.report_layer(layer, args)