def list_docker_containers(namespace_opts={}):
    """
    Get the list of running Docker containers, as `DockerContainer` objects.

    This is basically polling. Ideally, we should subscribe to Docker
    events so we can keep the containers list up to date without having to
    poll like this.
    """
    for inspect in exec_dockerps():
        long_id = inspect['Id']
        try:
            yield DockerContainer(long_id, inspect, namespace_opts)
        except ContainerInvalidEnvironment as e:
            logger.exception(e)
Exemplo n.º 2
0
def list_docker_containers(namespace_opts={}):
    """
    Get the list of running Docker containers, as `DockerContainer` objects.

    This is basically polling. Ideally, we should subscribe to Docker
    events so we can keep the containers list up to date without having to
    poll like this.
    """
    for inspect in exec_dockerps():
        long_id = inspect['Id']
        try:
            yield DockerContainer(long_id, inspect, namespace_opts)
        except ContainerInvalidEnvironment as e:
            logger.exception(e)
Exemplo n.º 3
0
    def crawl_dockerps(self):
        assert(self.crawl_mode == Modes.INVM)
        logger.debug('Crawling docker ps results')

        try:
            for inspect in dockerutils.exec_dockerps():
                yield (inspect['Id'], DockerPSFeature._make([
                    inspect['State']['Running'],
                    0,
                    inspect['Image'],
                    [],
                    inspect['Config']['Cmd'],
                    inspect['Name'],
                    inspect['Id'],
                ]))
        except Exception as e:
            logger.error('Error crawling docker ps', exc_info=True)
            raise CrawlError(e)
Exemplo n.º 4
0
def list_docker_containers(container_opts={}, user_list='ALL'):
    """
    Get the list of running Docker containers, as `DockerContainer` objects.

    This is basically polling. Ideally, we should subscribe to Docker
    events so we can keep the containers list up to date without having to
    poll like this.
    """
    for inspect in exec_dockerps():
        long_id = inspect['Id']

        if user_list not in ['ALL', 'all', 'All']:
            user_ctrs = [cid[:12] for cid in user_list.split(',')]
            short_id = long_id[:12]
            if short_id not in user_ctrs:
                continue

        try:
            c = DockerContainer(long_id, inspect, container_opts)
            if c.namespace:
                yield c
        except ContainerInvalidEnvironment as e:
            logger.exception(e)
    def crawl_dockerps(self):
        assert(self.crawl_mode == Modes.INVM)
        logger.debug('Crawling docker ps results')

        try:
            for inspect in dockerutils.exec_dockerps():
                long_id = inspect['Id']
                state = inspect['State']
                running = state['Running']
                image = inspect['Image']
                names = inspect['Name']
                cmd = inspect['Config']['Cmd']
                yield (long_id, DockerPSFeature._make([
                    running,
                    0,
                    image,
                    [],
                    cmd,
                    names,
                    long_id,
                ]))
        except Exception as e:
            logger.error('Error crawling docker ps', exc_info=True)
            raise CrawlError(e)
Exemplo n.º 6
0
    def crawl_dockerps(self):
        assert(self.crawl_mode == Modes.INVM)
        logger.debug('Crawling docker ps results')

        try:
            for inspect in dockerutils.exec_dockerps():
                long_id = inspect['Id']
                state = inspect['State']
                running = state['Running']
                image = inspect['Image']
                names = inspect['Name']
                cmd = inspect['Config']['Cmd']
                yield (long_id, DockerPSFeature._make([
                    running,
                    0,
                    image,
                    [],
                    cmd,
                    names,
                    long_id,
                ]))
        except Exception as e:
            logger.error('Error crawling docker ps', exc_info=True)
            raise CrawlError(e)