Example #1
0
 def __init__(self, host, cluster_name, capabilities, pool_name):
     new_host = volume_utils.append_host(host, pool_name)
     new_cluster = volume_utils.append_host(cluster_name, pool_name)
     super(PoolState, self).__init__(new_host, new_cluster, capabilities)
     self.pool_name = pool_name
     # No pools in pool
     self.pools = None
Example #2
0
    def get_pools(self, context, filters=None):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        self._update_backend_state_map(context)

        all_pools = {}
        name = volume_type = None
        if filters:
            name = filters.pop('name', None)
            volume_type = filters.pop('volume_type', None)

        for backend_key, state in self.backend_state_map.items():
            for key in state.pools:
                filtered = False
                pool = state.pools[key]
                # use backend_key.pool_name to make sure key is unique
                pool_key = volume_utils.append_host(backend_key,
                                                    pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))

                if name and new_pool.get('name') != name:
                    continue

                if filters:
                    # filter all other items in capabilities
                    for (attr, value) in filters.items():
                        cap = new_pool.get('capabilities').get(attr)
                        if not self._equal_after_convert(cap, value):
                            filtered = True
                            break

                if not filtered:
                    all_pools[pool_key] = pool

        # filter pools by volume type
        if volume_type:
            volume_type = volume_types.get_by_name_or_id(context, volume_type)
            all_pools = (self._filter_pools_by_volume_type(
                context, volume_type, all_pools))

        # encapsulate pools in format:{name: XXX, capabilities: XXX}
        return [
            dict(name=key, capabilities=value.capabilities)
            for key, value in all_pools.items()
        ]