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 __init__( self, long_id, inspect=None, host_namespace='', process_namespace=None, ): # Some quick sanity checks if not isinstance(long_id, basestring): raise TypeError('long_id should be a string') if inspect and not isinstance(inspect, dict): raise TypeError('inspect should be a dict.') if not inspect: try: inspect = exec_dockerinspect(long_id) except HTTPError: raise ContainerNonExistent('No docker container with ID: %s' % long_id) state = inspect['State'] self.image = inspect['Image'] assert(long_id == inspect['Id']) self.long_id = long_id self.host_namespace = host_namespace self.pid = str(state['Pid']) self.name = inspect['Name'] self.running = state['Running'] self.created = inspect['Created'] self.network_settings = inspect['NetworkSettings'] self.cmd = inspect['Config']['Cmd'] self.mounts = inspect.get('Mounts') self.volumes = inspect.get('Volumes') self.image_name = inspect['Config']['Image'] self.inspect = inspect self.process_namespace = (process_namespace or namespace.get_pid_namespace(self.pid)) # This short ID is mainly used for logging purposes self.short_id = long_id[:12] # Docker prepends a '/' to the name. Let's remove it. if self.name[0] == '/': self.name = self.name[1:] self._set_image_fields(inspect.get('RepoTag', '')) self._set_mounts_list() try: self.root_fs = get_docker_container_rootfs_path(self.long_id) except (HTTPError, RuntimeError, DockerutilsException) as e: logger.exception(e) self.root_fs = None self._set_logs_list_input() self._set_environment_specific_options() self._set_logs_list()
def __init__( self, long_id, inspect=None, host_namespace='', process_namespace=None, ): # Some quick sanity checks if not isinstance(long_id, basestring): raise TypeError('long_id should be a string') if inspect and not isinstance(inspect, dict): raise TypeError('inspect should be a dict.') if not inspect: try: inspect = exec_dockerinspect(long_id) except HTTPError: raise ContainerNonExistent('No docker container with ID: %s' % long_id) state = inspect['State'] self.image = inspect['Image'] assert (long_id == inspect['Id']) self.long_id = long_id self.host_namespace = host_namespace self.pid = str(state['Pid']) self.name = inspect['Name'] self.running = state['Running'] self.created = inspect['Created'] self.network_settings = inspect['NetworkSettings'] self.cmd = inspect['Config']['Cmd'] self.mounts = inspect.get('Mounts') self.volumes = inspect.get('Volumes') self.image_name = inspect['Config']['Image'] self.inspect = inspect self.process_namespace = (process_namespace or namespace.get_pid_namespace(self.pid)) # This short ID is mainly used for logging purposes self.short_id = long_id[:12] # Docker prepends a '/' to the name. Let's remove it. if self.name[0] == '/': self.name = self.name[1:] self._set_image_fields(inspect.get('RepoTag', '')) self._set_mounts_list() try: self.root_fs = get_docker_container_rootfs_path(self.long_id) except (HTTPError, RuntimeError, DockerutilsException) as e: logger.exception(e) self.root_fs = None self._set_logs_list_input() self._set_environment_specific_options() self._set_logs_list()
def test_get_container_rootfs(self): root = get_docker_container_rootfs_path(self.container['Id']) print root assert root.startswith('/var/lib/docker')