Example #1
0
    def _lookup(self, charm_name, metakey, exc_cb):
        with CharmStoreAPI._cachelock:
            if charm_name in CharmStoreAPI._cache:
                val = CharmStoreAPI._cache[charm_name]
                if isinstance(val, Future):
                    f = submit(
                        partial(self._wait_for_pending_lookup, val, charm_name,
                                metakey), exc_cb)
                else:
                    if metakey is None:
                        d = val
                    else:
                        d = val['Meta']['charm-metadata'][metakey]
                    f = submit(lambda: d, exc_cb)
            else:
                whole_entity_f = submit(
                    partial(self._do_remote_lookup, charm_name, metakey),
                    exc_cb)
                CharmStoreAPI._cache[charm_name] = whole_entity_f

                f = submit(
                    partial(self._wait_for_pending_lookup, whole_entity_f,
                            charm_name, metakey), exc_cb)

        return f
Example #2
0
    def _lookup(self, charm_name, metakey, exc_cb):
        with CharmStoreAPI._cachelock:
            if charm_name in CharmStoreAPI._cache:
                val = CharmStoreAPI._cache[charm_name]
                if isinstance(val, Future):
                    f = submit(partial(self._wait_for_pending_lookup,
                                       val, charm_name, metakey),
                               exc_cb)
                else:
                    if metakey is None:
                        d = val
                    else:
                        d = val['Meta']['charm-metadata'][metakey]
                    f = submit(lambda: d, exc_cb)
            else:
                whole_entity_f = submit(partial(self._do_remote_lookup,
                                                charm_name,
                                                metakey),
                                        exc_cb)
                CharmStoreAPI._cache[charm_name] = whole_entity_f

                f = submit(partial(self._wait_for_pending_lookup,
                                   whole_entity_f, charm_name,
                                   metakey),
                           exc_cb)

        return f
Example #3
0
    def nodes(self, constraints=None):
        """ Cache MAAS nodes
        """
        elapsed_time = time.time() - self._start_time
        if elapsed_time <= 20:
            return self._filtered_nodes

        def _do_update():
            nodes = self.maas_client.nodes
            self.invalidate_nodes_cache()
            return nodes

        if self._nodes_future:
            if self._nodes_future.done():
                with self._nodes_lock:
                    self._maas_client_nodes = self._nodes_future.result()
                self._nodes_future = None
        else:
            self._nodes_future = submit(_do_update, lambda _: None)

        if constraints:
            self._filtered_nodes = self._filter_nodes(self._maas_client_nodes,
                                                      constraints)
        else:
            self._filtered_nodes = self._maas_client_nodes

        self._start_time = time.time()
        return self._filtered_nodes
Example #4
0
    def nodes(self, constraints=None):
        """ Cache MAAS nodes
        """
        elapsed_time = time.time() - self._start_time
        if elapsed_time <= 20:
            return self._filtered_nodes

        def _do_update():
            nodes = self.maas_client.nodes
            self.invalidate_nodes_cache()
            return nodes

        if self._nodes_future:
            if self._nodes_future.done():
                with self._nodes_lock:
                    self._maas_client_nodes = self._nodes_future.result()
                self._nodes_future = None
        else:
            self._nodes_future = submit(_do_update, lambda _: None)

        if constraints:
            self._filtered_nodes = self._filter_nodes(self._maas_client_nodes,
                                                      constraints)
        else:
            self._filtered_nodes = self._maas_client_nodes

        self._start_time = time.time()
        return self._filtered_nodes
Example #5
0
    def request_readme(self, charm_id, short_charm_id):
        rf = submit(partial(self._request_readme, charm_id, short_charm_id),
                    lambda _: None)
        self.readme_futures[short_charm_id] = rf

        cb = self.readme_callbacks.get(short_charm_id, None)
        if cb:
            rf.add_done_callback(cb)
Example #6
0
    def request_readme(self, charm_id, short_charm_id):
        rf = submit(
            partial(self._request_readme, charm_id, short_charm_id),
            lambda _: None)
        self.readme_futures[short_charm_id] = rf

        cb = self.readme_callbacks.get(short_charm_id, None)
        if cb:
            rf.add_done_callback(cb)
Example #7
0
    def get_readme(self, short_charm_id, cb):
        readme = self.readmes.get(short_charm_id, None)
        if readme:
            f = submit(lambda: readme, None)
            f.add_done_callback(cb)
            return

        readme_f = self.readme_futures.get(short_charm_id, None)
        if readme_f:
            readme_f.add_done_callback(cb)
        else:
            self.readme_callbacks[short_charm_id] = cb
Example #8
0
    def get_readme(self, short_charm_id, cb):
        readme = self.readmes.get(short_charm_id, None)
        if readme:
            f = submit(lambda: readme, None)
            f.add_done_callback(cb)
            return

        readme_f = self.readme_futures.get(short_charm_id, None)
        if readme_f:
            readme_f.add_done_callback(cb)
        else:
            self.readme_callbacks[short_charm_id] = cb
Example #9
0
    def get_matches(self, substring, exc_cb):
        def _do_search():
            url = (self.baseurl +
                   "/search?text={}&autocomplete=1".format(substring) +
                   "&limit=20&include=charm-metadata&include=bundle-metadata")
            charm_url = url + "&type=charm&series={}".format(self.series)
            bundle_url = url + "&type=bundle"
            cr = requests.get(charm_url)
            crj = cr.json()
            br = requests.get(bundle_url)
            brj = br.json()
            return brj['Results'], crj['Results']

        f = submit(_do_search, exc_cb)
        return f
Example #10
0
    def load(self, charm_names_or_sources, done_cb=None):
        if len(charm_names_or_sources) == 0:
            return

        if self.metadata_future:
            # just wait for successive loads:
            self.metadata_future.result()

        with self.metadata_future_lock:
            self.metadata_future = submit(
                partial(self._do_load, charm_names_or_sources),
                self.handle_search_error)
            if done_cb:
                self.metadata_future.add_done_callback(done_cb)
            self.metadata_future.add_done_callback(self.handle_load_done)
Example #11
0
    def get_matches(self, substring, exc_cb):
        def _do_search():
            url = (self.baseurl +
                   "/search?text={}&autocomplete=1".format(substring) +
                   "&limit=20&include=charm-metadata&include=bundle-metadata")
            charm_url = url + "&type=charm&series={}".format(self.series)
            bundle_url = url + "&type=bundle"
            cr = requests.get(charm_url)
            crj = cr.json()
            br = requests.get(bundle_url)
            brj = br.json()
            return brj['Results'], crj['Results']

        f = submit(_do_search, exc_cb)
        return f
Example #12
0
    def load(self, charm_names_or_sources, done_cb=None):
        if len(charm_names_or_sources) == 0:
            return

        if self.metadata_future:
            # just wait for successive loads:
            self.metadata_future.result()

        with self.metadata_future_lock:
            self.metadata_future = submit(partial(self._do_load,
                                                  charm_names_or_sources),
                                          self.handle_search_error)
            if done_cb:
                self.metadata_future.add_done_callback(done_cb)
            self.metadata_future.add_done_callback(self.handle_load_done)