44
43
'maps to all filters included with nova.'),
45
44
cfg.ListOpt('scheduler_default_filters',
47
47
'AvailabilityZoneFilter',
50
'ComputeCapabilitiesFilter'
51
52
help='Which filter class names to use for filtering hosts '
52
53
'when not specified in the request.'),
221
222
filtered_hosts.append(host)
222
223
return filtered_hosts
224
def get_host_list(self):
225
"""Returns a list of dicts for each host that the Zone Manager
226
knows about. Each dict contains the host_name and the service
229
all_hosts = self.service_states.keys()
231
for host in self.service_states:
232
for svc in self.service_states[host]:
233
ret.append({"service": svc, "host_name": host})
236
def get_service_capabilities(self):
237
"""Roll up all the individual host info to generic 'service'
238
capabilities. Each capability is aggregated into
239
<cap>_min and <cap>_max values."""
240
hosts_dict = self.service_states
242
# TODO(sandy) - be smarter about fabricating this structure.
243
# But it's likely to change once we understand what the Best-Match
244
# code will need better.
245
combined = {} # { <service>_<cap> : (min, max), ... }
246
stale_host_services = {} # { host1 : [svc1, svc2], host2 :[svc1]}
247
for host, host_dict in hosts_dict.iteritems():
248
for service_name, service_dict in host_dict.iteritems():
249
if not service_dict.get("enabled", True):
250
# Service is disabled; do no include it
253
# Check if the service capabilities became stale
254
if self.host_service_caps_stale(host, service_name):
255
if host not in stale_host_services:
256
stale_host_services[host] = [] # Adding host key once
257
stale_host_services[host].append(service_name)
259
for cap, value in service_dict.iteritems():
260
if cap == "timestamp": # Timestamp is not needed
262
key = "%s_%s" % (service_name, cap)
263
min_value, max_value = combined.get(key, (value, value))
264
min_value = min(min_value, value)
265
max_value = max(max_value, value)
266
combined[key] = (min_value, max_value)
268
# Delete the expired host services
269
self.delete_expired_host_services(stale_host_services)
272
225
def update_service_capabilities(self, service_name, host, capabilities):
273
226
"""Update the per-service capabilities based on this notification."""
274
227
LOG.debug(_("Received %(service_name)s service update from "
280
233
service_caps[service_name] = capab_copy
281
234
self.service_states[host] = service_caps
283
def host_service_caps_stale(self, host, service):
284
"""Check if host service capabilites are not recent enough."""
285
allowed_time_diff = FLAGS.periodic_interval * 3
286
caps = self.service_states[host][service]
287
if ((timeutils.utcnow() - caps["timestamp"]) <=
288
datetime.timedelta(seconds=allowed_time_diff)):
292
def delete_expired_host_services(self, host_services_dict):
293
"""Delete all the inactive host services information."""
294
for host, services in host_services_dict.iteritems():
295
service_caps = self.service_states[host]
296
for service in services:
297
del service_caps[service]
298
if len(service_caps) == 0: # Delete host if no services
299
del self.service_states[host]
301
236
def get_all_host_states(self, context, topic):
302
237
"""Returns a dict of all the hosts the HostManager
303
238
knows about. Also, each of the consumable resources in HostState