Esempio n. 1
0
class Pruner(object):
    def __init__(self, conf, **local_conf):
        self.conf = conf
        self.cache = ImageCache(conf)

    def run(self):
        self.cache.prune()
Esempio n. 2
0
class Cleaner(object):
    def __init__(self, conf, **local_conf):
        self.conf = conf
        self.cache = ImageCache(conf)

    def run(self):
        self.cache.clean()
Esempio n. 3
0
class Prefetcher(object):

    def __init__(self, conf, **local_conf):
        self.conf = conf
        tank.store.create_stores(conf)
        self.cache = ImageCache(conf)
        registry.configure_registry_client(conf)

    def fetch_image_into_cache(self, image_id):
        ctx = registry.get_client_context(self.conf,
                                          is_admin=True, show_deleted=True)
        try:
            image_meta = registry.get_image_metadata(ctx, image_id)
            if image_meta['status'] != 'active':
                logger.warn(_("Image '%s' is not active. Not caching."),
                            image_id)
                return False

        except exception.NotFound:
            logger.warn(_("No metadata found for image '%s'"), image_id)
            return False

        image_data, image_size = get_from_backend(image_meta['location'])
        logger.debug(_("Caching image '%s'"), image_id)
        self.cache.cache_image_iter(image_id, image_data)
        return True

    def run(self):

        images = self.cache.get_queued_images()
        if not images:
            logger.debug(_("Nothing to prefetch."))
            return True

        num_images = len(images)
        logger.debug(_("Found %d images to prefetch"), num_images)

        pool = eventlet.GreenPool(num_images)
        results = pool.imap(self.fetch_image_into_cache, images)
        successes = sum([1 for r in results if r is True])
        if successes != num_images:
            logger.error(_("Failed to successfully cache all "
                           "images in queue."))
            return False

        logger.info(_("Successfully cached all %d images"), num_images)
        return True
Esempio n. 4
0
class Queuer(object):

    def __init__(self, conf, **local_conf):
        self.conf = conf
        self.cache = ImageCache(conf)
        registry.configure_registry_client(conf)

    def queue_image(self, image_id):
        ctx = \
            registry.get_client_context(conf, is_admin=True, show_deleted=True)
        try:
            image_meta = registry.get_image_metadata(ctx, image_id)
            if image_meta['status'] != 'active':
                logger.warn(_("Image '%s' is not active. Not queueing."),
                            image_id)
                return False

        except exception.NotFound:
            logger.warn(_("No metadata found for image '%s'"), image_id)
            return False

        logger.debug(_("Queueing image '%s'"), image_id)
        self.cache.queue_image(image_id)
        return True

    def run(self, images):

        num_images = len(images)
        if num_images == 0:
            logger.debug(_("No images to queue!"))
            return True

        logger.debug(_("Received %d images to queue"), num_images)

        pool = eventlet.GreenPool(num_images)
        results = pool.imap(self.queue_image, images)
        successes = sum([1 for r in results if r is True])
        if successes != num_images:
            logger.error(_("Failed to successfully queue all "
                           "images in queue."))
            return False

        logger.info(_("Successfully queued all %d images"), num_images)
        return True
Esempio n. 5
0
class Prefetcher(object):
    def __init__(self, conf, **local_conf):
        self.conf = conf
        tank.store.create_stores(conf)
        self.cache = ImageCache(conf)
        registry.configure_registry_client(conf)

    def fetch_image_into_cache(self, image_id):
        ctx = registry.get_client_context(self.conf, is_admin=True, show_deleted=True)
        try:
            image_meta = registry.get_image_metadata(ctx, image_id)
            if image_meta["status"] != "active":
                logger.warn(_("Image '%s' is not active. Not caching."), image_id)
                return False

        except exception.NotFound:
            logger.warn(_("No metadata found for image '%s'"), image_id)
            return False

        image_data, image_size = get_from_backend(image_meta["location"])
        logger.debug(_("Caching image '%s'"), image_id)
        self.cache.cache_image_iter(image_id, image_data)
        return True

    def run(self):

        images = self.cache.get_queued_images()
        if not images:
            logger.debug(_("Nothing to prefetch."))
            return True

        num_images = len(images)
        logger.debug(_("Found %d images to prefetch"), num_images)

        pool = eventlet.GreenPool(num_images)
        results = pool.imap(self.fetch_image_into_cache, images)
        successes = sum([1 for r in results if r is True])
        if successes != num_images:
            logger.error(_("Failed to successfully cache all " "images in queue."))
            return False

        logger.info(_("Successfully cached all %d images"), num_images)
        return True
Esempio n. 6
0
 def __init__(self, conf, **local_conf):
     self.conf = conf
     tank.store.create_stores(conf)
     self.cache = ImageCache(conf)
     registry.configure_registry_client(conf)
Esempio n. 7
0
 def __init__(self, conf, **local_conf):
     self.conf = conf
     self.cache = ImageCache(conf)
Esempio n. 8
0
 def __init__(self, conf, **local_conf):
     self.conf = conf
     self.cache = ImageCache(conf)
     registry.configure_registry_client(conf)
Esempio n. 9
0
 def __init__(self, conf, **local_conf):
     self.conf = conf
     self.cache = ImageCache(conf)
Esempio n. 10
0
 def __init__(self, conf, **local_conf):
     self.conf = conf
     tank.store.create_stores(conf)
     self.cache = ImageCache(conf)
     registry.configure_registry_client(conf)