コード例 #1
0
ファイル: docker_backend.py プロジェクト: andrewrothstein/sen
    def realtime_updates(self):
        it = repeater(self.client.events, kwargs={"decode": True}, retries=5)
        while True:
            event = repeater(next, args=(it, ), retries=2)  # likely an engine restart
            if not event:
                it = repeater(self.client.events, kwargs={"decode": True}, retries=5)
                if not it:
                    raise NotifyError("Unable to fetch realtime updates from docker engine.")
                continue
            logger.debug("RT event: %s", event)
            yield event
            continue
            # FIXME: this needs rewrite

            try:
                # 1.10+
                is_container = event["Type"] == "container"
            except KeyError:
                # event["from'] means it's a container
                is_container = "from" in event
            if is_container:
                # inspect doesn't contain info about status and you can't query just one
                # container with containers()
                # let's do full-blown containers() query; it's not that expensive
                self.get_containers(cached=False)
            else:
                # similar as ^
                # images() doesn't support query by ID
                # inspect doesn't contain info about repositories
                self.get_images(cached=False)
            content, _, _ = self.filter(containers=True, images=True, stopped=True,
                                        cached=True, sort_by_created=True)
            yield content
コード例 #2
0
ファイル: test_util.py プロジェクト: TomasTomecek/sen
def test_repeater():
    def g(l, item=1):
        l.append(1)
        return l[item]

    assert repeater(g, args=([],)) == 1
    with pytest.raises(Exception):
        repeater(f, args=([],), kwargs={"item": 10}) == 1
コード例 #3
0
ファイル: test_util.py プロジェクト: andrewrothstein/sen
def test_repeater():
    def g(l, item=1):
        l.append(1)
        return l[item]

    assert repeater(g, args=([], )) == 1
    with pytest.raises(Exception):
        repeater(f, args=([], ), kwargs={"item": 10}) == 1
コード例 #4
0
ファイル: docker_backend.py プロジェクト: TomasTomecek/sen
 def get_images(self, cached=True):
     if cached is False or self._images is None:
         logger.debug("doing images() query")
         self._images = {}
         images_response = repeater(self.client.images) or []
         for i in images_response:
             img = DockerImage(i, self)
             self._images[img.image_id] = img
         self._all_images = {}
         all_images_response = repeater(self.client.images, kwargs={"all": True}) or []
         for i in all_images_response:
             img = DockerImage(i, self)
             self._all_images[img.image_id] = img
     return list(self._images.values())
コード例 #5
0
ファイル: docker_backend.py プロジェクト: rm3l/sen
 def get_images(self, cached=True):
     if cached is False or self._images is None:
         logger.debug("doing images() query")
         self._images = {}
         images_response = repeater(self.client.images) or []
         for i in images_response:
             img = DockerImage(i, self)
             self._images[img.image_id] = img
         self._all_images = {}
         all_images_response = repeater(self.client.images, kwargs={"all": True}) or []
         for i in all_images_response:
             img = DockerImage(i, self)
             self._all_images[img.image_id] = img
     return list(self._images.values())
コード例 #6
0
ファイル: docker_backend.py プロジェクト: TomasTomecek/sen
    def realtime_updates(self):
        event = it = None
        while True:
            if not it or not event:
                it = repeater(self.client.events, kwargs={"decode": True}, retries=5)
                if not it:
                    raise NotifyError("Unable to fetch realtime updates from docker engine.")

            event = repeater(next, args=(it, ), retries=2)  # likely an engine restart
            if not event:
                continue

            logger.debug("RT event: %s", event)

            yield event
コード例 #7
0
ファイル: docker_backend.py プロジェクト: rm3l/sen
    def realtime_updates(self):
        event = it = None
        while True:
            if not it or not event:
                it = repeater(self.client.events, kwargs={"decode": True}, retries=5)
                if not it:
                    raise NotifyError("Unable to fetch realtime updates from docker engine.")

            event = repeater(next, args=(it, ), retries=2)  # likely an engine restart
            if not event:
                continue

            logger.debug("RT event: %s", event)

            yield event
コード例 #8
0
ファイル: docker_backend.py プロジェクト: TomasTomecek/sen
 def get_containers(self, cached=True, stopped=True):
     if cached is False or self._containers is None:
         logger.debug("doing containers() query")
         self._containers = {}
         containers_reponse = repeater(self.client.containers, kwargs={"all": stopped}) or []
         for c in containers_reponse:
             container = DockerContainer(c, self)
             self._containers[container.container_id] = container
     if not stopped:
         return [x for x in list(self._containers.values()) if x.running]
     return list(self._containers.values())
コード例 #9
0
ファイル: docker_backend.py プロジェクト: rm3l/sen
 def get_containers(self, cached=True, stopped=True):
     if cached is False or self._containers is None:
         logger.debug("doing containers() query")
         self._containers = {}
         containers_reponse = repeater(self.client.containers, kwargs={"all": stopped}) or []
         for c in containers_reponse:
             container = DockerContainer(c, self)
             self._containers[container.container_id] = container
     if not stopped:
         return [x for x in list(self._containers.values()) if x.running]
     return list(self._containers.values())
コード例 #10
0
ファイル: docker_backend.py プロジェクト: andrewrothstein/sen
    def realtime_updates(self):
        it = repeater(self.client.events, kwargs={"decode": True}, retries=5)
        while True:
            event = repeater(next, args=(it, ),
                             retries=2)  # likely an engine restart
            if not event:
                it = repeater(self.client.events,
                              kwargs={"decode": True},
                              retries=5)
                if not it:
                    raise NotifyError(
                        "Unable to fetch realtime updates from docker engine.")
                continue
            logger.debug("RT event: %s", event)
            yield event
            continue
            # FIXME: this needs rewrite

            try:
                # 1.10+
                is_container = event["Type"] == "container"
            except KeyError:
                # event["from'] means it's a container
                is_container = "from" in event
            if is_container:
                # inspect doesn't contain info about status and you can't query just one
                # container with containers()
                # let's do full-blown containers() query; it's not that expensive
                self.get_containers(cached=False)
            else:
                # similar as ^
                # images() doesn't support query by ID
                # inspect doesn't contain info about repositories
                self.get_images(cached=False)
            content, _, _ = self.filter(containers=True,
                                        images=True,
                                        stopped=True,
                                        cached=True,
                                        sort_by_created=True)
            yield content