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
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
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
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())
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
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())
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