示例#1
0
    def create(self, name, project=None, capabilities=None):

        capabilities = {} if capabilities is None else capabilities
        subset_key = utils.flavor_project_subset_key(project)
        set_key = utils.flavor_set_key()
        hash_key = utils.flavor_name_hash_key(name)

        flavors = self._client.hgetall(hash_key)
        if len(flavors) == 0:
            flavors = {
                'f': name,
                'p': project,
                'c': self._packer(capabilities or {}),
            }
            # Pipeline ensures atomic inserts.
            with self._client.pipeline() as pipe:
                pipe.zadd(set_key, {hash_key: 1})
                pipe.zadd(subset_key, {hash_key: 1})
                pipe.hmset(hash_key, flavors)
                pipe.execute()
        else:
            with self._client.pipeline() as pipe:
                pipe.hset(hash_key, "c", self._packer(capabilities))
                pipe.hset(hash_key, "p", project)
                pipe.execute()
示例#2
0
文件: flavors.py 项目: anxinyf/zaqar
    def create(self, name, project=None, capabilities=None):

        capabilities = {} if capabilities is None else capabilities
        subset_key = utils.flavor_project_subset_key(project)
        set_key = utils.flavor_set_key()
        hash_key = utils.flavor_name_hash_key(name)

        flavors = self._client.hgetall(hash_key)
        if len(flavors) == 0:
            flavors = {
                'f': name,
                'p': project,
                'c': self._packer(capabilities or {}),
            }
            # Pipeline ensures atomic inserts.
            with self._client.pipeline() as pipe:
                pipe.zadd(set_key, 1, hash_key)
                pipe.zadd(subset_key, 1, hash_key)
                pipe.hmset(hash_key, flavors)
                pipe.execute()
        else:
            with self._client.pipeline() as pipe:
                pipe.hset(hash_key, "c", self._packer(capabilities))
                pipe.hset(hash_key, "p", project)
                pipe.execute()
示例#3
0
文件: flavors.py 项目: anxinyf/zaqar
    def get(self, name, project=None, detailed=False):
        hash_key = utils.flavor_name_hash_key(name)
        flavors = self._client.hgetall(hash_key)

        if flavors is None or len(flavors) == 0:
            raise errors.FlavorDoesNotExist(name)

        return self._normalize(flavors, detailed)
示例#4
0
    def get(self, name, project=None, detailed=False):
        hash_key = utils.flavor_name_hash_key(name)
        flavors = self._client.hgetall(hash_key)

        if flavors is None or len(flavors) == 0:
            raise errors.FlavorDoesNotExist(name)

        return self._normalize(flavors, detailed)
示例#5
0
文件: flavors.py 项目: anxinyf/zaqar
 def update(self, name, project=None, capabilities=None):
     hash_key = utils.flavor_name_hash_key(name)
     with self._client.pipeline() as pipe:
         pipe.hset(hash_key, "c", self._packer(capabilities))
         pipe.hset(hash_key, "p", project)
         try:
             pipe.execute()
         except redis.exceptions.ResponseError:
             raise errors.FlavorDoesNotExist(name)
示例#6
0
 def update(self, name, project=None, capabilities=None):
     hash_key = utils.flavor_name_hash_key(name)
     with self._client.pipeline() as pipe:
         pipe.hset(hash_key, "c", self._packer(capabilities))
         pipe.hset(hash_key, "p", project)
         try:
             pipe.execute()
         except redis.exceptions.ResponseError:
             raise errors.FlavorDoesNotExist(name)
示例#7
0
文件: flavors.py 项目: anxinyf/zaqar
 def delete(self, name, project=None):
     subset_key = utils.flavor_project_subset_key(project)
     set_key = utils.flavor_set_key()
     hash_key = utils.flavor_name_hash_key(name)
     if self._client.zrank(subset_key, hash_key) is not None:
         with self._client.pipeline() as pipe:
             pipe.zrem(set_key, hash_key)
             pipe.zrem(subset_key, hash_key)
             pipe.delete(hash_key)
             pipe.execute()
示例#8
0
 def delete(self, name, project=None):
     subset_key = utils.flavor_project_subset_key(project)
     set_key = utils.flavor_set_key()
     hash_key = utils.flavor_name_hash_key(name)
     if self._client.zrank(subset_key, hash_key) is not None:
         with self._client.pipeline() as pipe:
             pipe.zrem(set_key, hash_key)
             pipe.zrem(subset_key, hash_key)
             pipe.delete(hash_key)
             pipe.execute()
示例#9
0
文件: flavors.py 项目: anxinyf/zaqar
    def list(self, project=None, marker=None, limit=10, detailed=False):
        client = self._client
        subset_key = utils.flavor_project_subset_key(project)
        marker_key = utils.flavor_name_hash_key(marker)
        rank = client.zrank(subset_key, marker_key)
        start = rank + 1 if rank is not None else 0

        cursor = (f
                  for f in client.zrange(subset_key, start, start + limit - 1))
        marker_next = {}

        def normalizer(flavor):
            marker_next['next'] = flavor['f']
            return self._normalize(flavor, detailed=detailed)

        yield utils.FlavorListCursor(self._client, cursor, normalizer)
        yield marker_next and marker_next['next']
示例#10
0
    def list(self, project=None, marker=None, limit=10, detailed=False):
        client = self._client
        subset_key = utils.flavor_project_subset_key(project)
        marker_key = utils.flavor_name_hash_key(marker)
        if marker_key:
            rank = client.zrank(subset_key, marker_key)
        else:
            rank = None
        start = rank + 1 if rank is not None else 0

        cursor = (f for f in client.zrange(subset_key, start,
                                           start + limit - 1))
        marker_next = {}

        def normalizer(flavor):
            marker_next['next'] = flavor['f']
            return self._normalize(flavor, detailed=detailed)

        yield utils.FlavorListCursor(self._client, cursor, normalizer)
        yield marker_next and marker_next['next']
示例#11
0
文件: flavors.py 项目: anxinyf/zaqar
 def exists(self, name, project=None):
     set_key = utils.flavor_set_key()
     hash_key = utils.flavor_name_hash_key(name)
     return self._client.zrank(set_key, hash_key) is not None
示例#12
0
 def exists(self, name, project=None):
     set_key = utils.flavor_set_key()
     hash_key = utils.flavor_name_hash_key(name)
     return self._client.zrank(set_key, hash_key) is not None