def __init__(
        self,
        long_id,
        inspect=None,
        namespace_opts={},
    ):

        if not inspect:
            inspect = exec_dockerinspect(long_id)

        state = inspect['State']
        self.image = inspect['Image']

        assert(long_id == inspect['Id'])
        self.long_id = long_id
        self.pid = 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.inspect = inspect

        # 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.namespace = None
Esempio n. 2
0
    def __init__(
        self,
        long_id,
        inspect=None,
        namespace_opts={},
    ):

        if not inspect:
            inspect = exec_dockerinspect(long_id)

        state = inspect['State']
        self.image = inspect['Image']

        assert (long_id == inspect['Id'])
        self.long_id = long_id
        self.pid = 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.inspect = inspect

        # 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.namespace = None
Esempio n. 3
0
    def __init__(
        self,
        long_id,
        inspect=None,
        container_opts={},
        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 container_opts and not isinstance(container_opts, dict):
            raise TypeError('container_opts 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.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.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(container_opts)
        self._set_logs_list()
    def __init__(
        self,
        long_id,
        inspect=None,
        container_opts={},
    ):

        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.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.inspect = inspect

        # 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:]

        repo_tag = inspect.get('RepoTag', '')
	self.docker_image_long_name = repo_tag
	self.docker_image_short_name = os.path.basename(repo_tag)
	if ':' in repo_tag and not '/' in repo_tag.rsplit(':', 1)[1]:
	    self.docker_image_tag = repo_tag.rsplit(':', 1)[1]
	else:
	    self.docker_image_tag = ''
	self.docker_image_registry = os.path.dirname(repo_tag).split('/')[0]
	try:
            # This is the 'abc' in 'registry/abc/bla:latest'
	    self.owner_namespace = os.path.dirname(repo_tag).split('/', 1)[1]
	except IndexError:
	    self.owner_namespace = ''

        try:
            self.root_fs = get_docker_container_rootfs_path(self.long_id)
        except HTTPError as e:
            print e
            logger.exception(e)
            self.root_fs = None

        self._set_logfiles_links_source()
        self._set_environment_specific_options(container_opts)
        self._set_logfiles_links_source_and_dest()
    def crawl_dockerinspect(self):
        logger.debug('Crawling docker inspect')

        long_id = self.container.long_id
        try:
            inspect = dockerutils.exec_dockerinspect(long_id)
            yield (long_id, inspect)
        except Exception as e:
            logger.error('Error crawling docker inspect', exc_info=True)
            raise CrawlError(e)
Esempio n. 6
0
    def crawl_dockerinspect(self):
        logger.debug('Crawling docker inspect')

        long_id = self.container.long_id
        try:
            inspect = dockerutils.exec_dockerinspect(long_id)
            yield (long_id, inspect)
        except Exception as e:
            logger.error('Error crawling docker inspect', exc_info=True)
            raise CrawlError(e)
Esempio n. 7
0
    def crawl(self, container_id, avoid_setns=False, **kwargs):
        inspect = dockerutils.exec_dockerinspect(container_id)
        state = inspect['State']
        pid = str(state['Pid'])
        logger.debug('Crawling OS for container %s' % container_id)

        if avoid_setns:
            return self._crawl_without_setns(container_id)
        else:  # in all other cases, including wrong mode set
            return run_as_another_namespace(pid,
                                            ALL_NAMESPACES,
                                            self._crawl_in_system)
    def crawl(self, container_id, avoid_setns=False, **kwargs):
        inspect = dockerutils.exec_dockerinspect(container_id)
        state = inspect['State']
        pid = str(state['Pid'])
        logger.debug('Crawling OS for container %s' % container_id)

        if avoid_setns:
            return self._crawl_without_setns(container_id)
        else:  # in all other cases, including wrong mode set
            self.get_packages_generic = False  # can be made an arg to crawl()
            return run_as_another_namespace(pid,
                                            ALL_NAMESPACES,
                                            self._crawl_in_system)
Esempio n. 9
0
    def __init__(
        self,
        long_id,
        inspect=None,
        container_opts={},
    ):

        # 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 container_opts and not isinstance(container_opts, dict):
            raise TypeError('container_opts 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.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.inspect = inspect

        # 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:]

        repo_tag = inspect.get('RepoTag', '')
        self.docker_image_long_name = repo_tag
        self.docker_image_short_name = os.path.basename(repo_tag)
        if ':' in repo_tag and not '/' in repo_tag.rsplit(':', 1)[1]:
            self.docker_image_tag = repo_tag.rsplit(':', 1)[1]
        else:
            self.docker_image_tag = ''
        self.docker_image_registry = os.path.dirname(repo_tag).split('/')[0]
        try:
            # This is the 'abc' in 'registry/abc/bla:latest'
            self.owner_namespace = os.path.dirname(repo_tag).split('/', 1)[1]
        except IndexError:
            self.owner_namespace = ''

        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_logfiles_links_source()
        self._set_environment_specific_options(container_opts)
        self._set_logfiles_links_source_and_dest()