示例#1
0
    def test_local_cache_no_file_no_context(self):
        """Test local cache without a context manager."""
        c = utils.LocalCache()
        cache = c.lc_open()
        cache['test_key3'] = True
        try:
            self.assertTrue('test_key3' in cache)
        finally:
            c.lc_close()

        with utils.LocalCache() as c:
            self.assertTrue('test_key3' in c)
示例#2
0
    def get_flavors(self):
        """Retrieve all of flavors.

        :returns: dict
        """
        flavors = dict()
        with utils.LocalCache() as c:
            for flavor in self.conn.compute.flavors():
                _flavor = flavor.to_dict()
                cache_key = 'flavor_' + str(flavor.id)
                c.set(cache_key, _flavor, expire=43200, tag='flavors')
                entry = flavors[flavor.id] = dict()
                entry.update(_flavor)
        return flavors
示例#3
0
    def get_projects(self):
        """Retrieve a list of projects.

        :returns: list
        """
        _consumers = list()
        with utils.LocalCache() as c:
            for project in self.conn.identity.projects():
                _consumers.append(project)
                cache_key = 'projects_' + str(project.id)
                c.set(cache_key,
                      project.to_dict(),
                      expire=43200,
                      tag='projects')
        return _consumers
示例#4
0
    def get_flavor(self, flavor_id):
        """Retrieve a flavor.

        :param flavor_id: ID of a given flavor to lookup.
        :type flavor_id: int || str
        :returns: dict
        """
        flavor = None
        cache_key = 'flavor_{}'.format(flavor_id)
        with utils.LocalCache() as c:
            try:
                flavor = c.get(cache_key)
                if not flavor:
                    raise LookupError
            except LookupError:
                flavor_info = self.conn.compute.get_flavor(flavor_id)
                flavor = flavor_info.to_dict()
                c.set(cache_key, flavor, expire=43200, tag='flavors')
            finally:
                return flavor
示例#5
0
    def get_project(self, project_id):
        """Retrieve project data.

        :param project_id: ID of a given project to lookup.
        :type project_id: str || uuid
        :returns: dict
        """
        project = None
        cache_key = 'projects_{}'.format(project_id)
        with utils.LocalCache() as c:
            try:
                project = c.get(cache_key)
                if not project:
                    raise LookupError
            except LookupError:
                project_info = self.conn.identity.get_project(project_id)
                project = project_info.to_dict()
                c.set(cache_key, project, expire=43200, tag='projects')
            finally:
                return project
示例#6
0
 def test_local_cache_file(self):
     """Test local cache."""
     with utils.LocalCache(cache_path=self.t_testfile) as c:
         c['test_key2'] = True
         self.assertTrue('test_key2' in c)
示例#7
0
 def test_local_cache_no_file(self):
     """Test local cache."""
     with utils.LocalCache() as c:
         c['test_key1'] = True
         self.assertTrue('test_key1' in c)
示例#8
0
 def test_local_cache_named_ext(self):
     """Test local cache without loading anything with a named extension."""
     utils.LocalCache(cache_path='{}.cache'.format(self.t_testfile))
示例#9
0
 def test_local_cache_no_load(self):
     """Test local cache without loading anything."""
     c = utils.LocalCache(cache_path=self.t_testfile)
     c.lc_close()