def get_all_host_states(self, context): """Returns a dict of all the hosts the HostManager knows about. Also, each of the consumable resources in HostState are pre-populated and adjusted based on data in the db. For example: {'192.168.1.100': HostState(), ...} """ # Get resource usage across the available volume nodes: topic = FLAGS.volume_topic volume_services = db.service_get_all_by_topic(context, topic) for service in volume_services: if not utils.service_is_up(service) or service['disabled']: LOG.warn(_("service is down or disabled.")) continue host = service['host'] capabilities = self.service_states.get(host, None) host_state = self.host_state_map.get(host) if host_state: # copy capabilities to host_state.capabilities host_state.update_capabilities(capabilities, dict(service.iteritems())) else: host_state = self.host_state_cls(host, capabilities=capabilities, service=dict( service.iteritems())) self.host_state_map[host] = host_state # update host_state host_state.update_from_volume_capability(capabilities) return self.host_state_map.itervalues()
def get_all_host_states(self, context): """Returns a dict of all the hosts the HostManager knows about. Also, each of the consumable resources in HostState are pre-populated and adjusted based on data in the db. For example: {'192.168.1.100': HostState(), ...} """ # Get resource usage across the available volume nodes: topic = FLAGS.volume_topic volume_services = db.service_get_all_by_topic(context, topic) for service in volume_services: if not utils.service_is_up(service) or service['disabled']: LOG.warn(_("service is down or disabled.")) continue host = service['host'] capabilities = self.service_states.get(host, None) host_state = self.host_state_map.get(host) if host_state: # copy capabilities to host_state.capabilities host_state.update_capabilities(capabilities, dict(service.iteritems())) else: host_state = self.host_state_cls(host, capabilities=capabilities, service= dict(service.iteritems())) self.host_state_map[host] = host_state # update host_state host_state.update_from_volume_capability(capabilities) return self.host_state_map.itervalues()
def hosts_up(self, context, topic): """Return the list of hosts that have a running service for topic.""" services = db.service_get_all_by_topic(context, topic) return [service['host'] for service in services if utils.service_is_up(service)]