def get_pools(self, context, filters=None): """Returns a dict of all pools on all hosts HostManager knows about.""" self._update_host_state_map(context) all_pools = [] for host, host_state in self.host_state_map.items(): for pool in host_state.pools.values(): fully_qualified_pool_name = share_utils.append_host( host, pool.pool_name) host_name = share_utils.extract_host( fully_qualified_pool_name, level='host') backend_name = share_utils.extract_host( fully_qualified_pool_name, level='backend').split('@')[1] \ if '@' in fully_qualified_pool_name else None pool_name = share_utils.extract_host( fully_qualified_pool_name, level='pool') new_pool = { 'name': fully_qualified_pool_name, 'host': host_name, 'backend': backend_name, 'pool': pool_name, 'capabilities': pool.capabilities, } if self._passes_filters(new_pool, filters): all_pools.append(new_pool) return all_pools
def get_pools(self, context, filters=None, cached=False): """Returns a dict of all pools on all hosts HostManager knows about.""" if not cached or not self.host_state_map: self._update_host_state_map(context) all_pools = [] for host, host_state in self.host_state_map.items(): for pool in host_state.pools.values(): fully_qualified_pool_name = share_utils.append_host( host, pool.pool_name) host_name = share_utils.extract_host(fully_qualified_pool_name, level='host') backend_name = (share_utils.extract_host( fully_qualified_pool_name, level='backend').split('@')[1] if '@' in fully_qualified_pool_name else None) pool_name = share_utils.extract_host(fully_qualified_pool_name, level='pool') new_pool = { 'name': fully_qualified_pool_name, 'host': host_name, 'backend': backend_name, 'pool': pool_name, 'capabilities': pool.capabilities, } if self._passes_filters(new_pool, filters): all_pools.append(new_pool) return all_pools
def get_pools(self, context, filters=None): """Returns a dict of all pools on all hosts HostManager knows about.""" self._update_host_state_map(context) all_pools = [] for host, host_state in self.host_state_map.items(): for pool in host_state.pools.values(): fully_qualified_pool_name = share_utils.append_host(host, pool.pool_name) host_name = share_utils.extract_host(fully_qualified_pool_name, level="host") backend_name = ( share_utils.extract_host(fully_qualified_pool_name, level="backend").split("@")[1] if "@" in fully_qualified_pool_name else None ) pool_name = share_utils.extract_host(fully_qualified_pool_name, level="pool") new_pool = { "name": fully_qualified_pool_name, "host": host_name, "backend": backend_name, "pool": pool_name, "capabilities": pool.capabilities, } if self._passes_filters(new_pool, filters): all_pools.append(new_pool) return all_pools
def _ensure_share_has_pool(self, ctxt, share): pool = share_utils.extract_host(share['host'], 'pool') if pool is None: # No pool name encoded in host, so this is a legacy # share created before pool is introduced, ask # driver to provide pool info if it has such # knowledge and update the DB. try: pool = self.driver.get_pool(share) except Exception as err: LOG.error(_LE("Failed to fetch pool name for share: " "%(share)s. Error: %(error)s."), {'share': share['id'], 'error': err}) return if pool: new_host = share_utils.append_host(share['host'], pool) self.db.share_update(ctxt, share['id'], {'host': new_host}) return pool
def test_append_host_with_no_values(self): host = None pool = None expected = None self.assertEqual(expected, share_utils.append_host(host, pool))
def test_append_host_with_pool(self): host = None pool = 'pool' expected = None self.assertEqual(expected, share_utils.append_host(host, pool))
def test_append_host_with_host(self): host = 'Host' pool = None expected = 'Host' self.assertEqual(expected, share_utils.append_host(host, pool))
def test_append_host_with_host_and_pool(self): host = 'Host' pool = 'Pool' expected = 'Host#Pool' self.assertEqual(expected, share_utils.append_host(host, pool))
def __init__(self, host, capabilities, pool_name): new_host = share_utils.append_host(host, pool_name) super(PoolState, self).__init__(new_host, capabilities) self.pool_name = pool_name # No pools in pool self.pools = None