def crawl(self, container_id=None, avoid_setns=False, root_dir='/', **kwargs): logger.debug('Crawling packages for container %s' % container_id) inspect = exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) if avoid_setns: rootfs_dir = get_docker_container_rootfs_path( container_id) return crawl_packages( root_dir=join_abs_paths(rootfs_dir, root_dir), reload_needed=True) else: # in all other cases, including wrong mode set try: return run_as_another_namespace(pid, ALL_NAMESPACES, crawl_packages, None, root_dir, 0, False) except CrawlError: # Retry the crawl avoiding the setns() syscall. This is # needed for PPC where we can not jump into the container and # run its apt or rpm commands. rootfs_dir = get_docker_container_rootfs_path( container_id) return crawl_packages( root_dir=join_abs_paths(rootfs_dir, root_dir), reload_needed=True)
def crawl(self, container_id=None, avoid_setns=False, root_dir='/', **kwargs): logger.debug('Crawling packages for container %s' % container_id) inspect = exec_dockerinspect(container_id) state = inspect['State'] pid = str(state['Pid']) if avoid_setns: rootfs_dir = get_docker_container_rootfs_path(container_id) return crawl_packages(root_dir=join_abs_paths( rootfs_dir, root_dir), reload_needed=True) else: # in all other cases, including wrong mode set try: return run_as_another_namespace(pid, ALL_NAMESPACES, crawl_packages, None, root_dir, 0, False) except CrawlError: # Retry the crawl avoiding the setns() syscall. This is # needed for PPC where we can not jump into the container and # run its apt or rpm commands. rootfs_dir = get_docker_container_rootfs_path(container_id) return crawl_packages(root_dir=join_abs_paths( rootfs_dir, root_dir), reload_needed=True)
def _expand_and_map_log_link(self, log, host_log_dir, rootfs_path): """ Returns a list of LogFileLinks with all the fields set after expanding the globs and mapping mount points. """ _logs = [] if not self.mounts: source = misc.join_abs_paths(rootfs_path, log.name) if "*" in source: _logs = [LogFileLink(name=log.name, source=s, type=log.type, dest=s.split(rootfs_path, 1)[1], host_log_dir=host_log_dir) for s in glob.glob(source)] else: _logs = [LogFileLink(name=log.name, type=log.type, source=source, dest=log.name, host_log_dir=host_log_dir)] for mount in self.mounts: mount_src = mount['Source'] mount_dst = mount['Destination'] if log.name.startswith(mount['Destination']): source = log.name.replace(mount_dst, mount_src) if "*" in source: _logs = [LogFileLink(name=log.name, source=s, type=log.type, dest=s.replace(mount_src, mount_dst), host_log_dir=host_log_dir) for s in glob.glob(source)] else: _logs = [LogFileLink(name=log.name, source=source, dest=log.name, type=log.type, host_log_dir=host_log_dir)] else: source = misc.join_abs_paths(rootfs_path, log.name) if "*" in source: _logs = [LogFileLink(name=log.name, source=s, type=log.type, dest=s.split(rootfs_path, 1)[1], host_log_dir=host_log_dir) for s in glob.glob(source)] else: _logs = [LogFileLink(name=log.name, source=source, dest=log.name, type=log.type, host_log_dir=host_log_dir)] return _logs
def get_dest(self): if self.host_log_dir: return misc.join_abs_paths(self.host_log_dir, self.dest) return self.dest
def _expand_and_map_log_link(self, log, host_log_dir, rootfs_path): """ Returns a list of LogFileLinks with all the fields set after expanding the globs and mapping mount points. """ _logs = [] if not self.mounts: source = misc.join_abs_paths(rootfs_path, log.name) if "*" in source: _logs = [ LogFileLink(name=log.name, source=s, type=log.type, dest=s.split(rootfs_path, 1)[1], host_log_dir=host_log_dir) for s in glob.glob(source) ] else: _logs = [ LogFileLink(name=log.name, type=log.type, source=source, dest=log.name, host_log_dir=host_log_dir) ] for mount in self.mounts: mount_src = mount['Source'] mount_dst = mount['Destination'] if log.name.startswith(mount['Destination']): source = log.name.replace(mount_dst, mount_src) if "*" in source: _logs = [ LogFileLink(name=log.name, source=s, type=log.type, dest=s.replace(mount_src, mount_dst), host_log_dir=host_log_dir) for s in glob.glob(source) ] else: _logs = [ LogFileLink(name=log.name, source=source, dest=log.name, type=log.type, host_log_dir=host_log_dir) ] else: source = misc.join_abs_paths(rootfs_path, log.name) if "*" in source: _logs = [ LogFileLink(name=log.name, source=s, type=log.type, dest=s.split(rootfs_path, 1)[1], host_log_dir=host_log_dir) for s in glob.glob(source) ] else: _logs = [ LogFileLink(name=log.name, source=source, dest=log.name, type=log.type, host_log_dir=host_log_dir) ] return _logs