def list_raw_containers(user_list='ALL'): """ A running container is defined as a group of processes with the `pid` namespace different to the `init` process `pid` namespace. """ init_ns = namespace.get_pid_namespace(1) for p in psutil.process_iter(): pid = (p.pid() if hasattr(p.pid, '__call__') else p.pid) if pid == 1 or pid == '1': # don't confuse the init process as a container continue if user_list not in ['ALL', 'all', 'All']: if str(pid) not in user_list: # skip containers not in the list continue if misc.process_is_crawler(pid): # don't confuse the crawler process with a container continue curr_ns = namespace.get_pid_namespace(pid) if not curr_ns: # invalid container continue if curr_ns == init_ns: continue yield Container(pid, curr_ns)
def list_raw_containers(user_list="ALL"): """ A running container is defined as a group of processes with the `pid` namespace different to the `init` process `pid` namespace. """ init_ns = namespace.get_pid_namespace(1) for p in psutil.process_iter(): pid = p.pid() if hasattr(p.pid, "__call__") else p.pid if pid == 1 or pid == "1": # don't confuse the init process as a container continue if user_list not in ["ALL", "all", "All"]: if str(pid) not in user_list: # skip containers not in the list continue if misc.process_is_crawler(pid): # don't confuse the crawler process with a container continue curr_ns = namespace.get_pid_namespace(pid) if not curr_ns: # invalid container continue if curr_ns == init_ns: continue yield Container(pid, curr_ns)
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 __init__(self, pid, process_namespace=None): self.pid = str(pid) self.short_id = str(hash(pid)) self.long_id = str(hash(pid)) self.name = str(pid) self.namespace = str(pid) self.image = None self.root_fs = None self.log_prefix = None self.log_file_list = None self.process_namespace = process_namespace or namespace.get_pid_namespace(pid)
def __init__(self, pid, process_namespace=None): self.pid = str(pid) self.short_id = str(hash(pid)) self.long_id = str(hash(pid)) self.name = str(pid) self.namespace = str(pid) self.image = None self.root_fs = None self.log_prefix = None self.log_file_list = None self.process_namespace = (process_namespace or namespace.get_pid_namespace(pid))