47
47
'AvailabilityZoneFilter',
50
'ComputeCapabilitiesFilter'
50
'ComputeCapabilitiesFilter',
51
'ImagePropertiesFilter'
52
53
help='Which filter class names to use for filtering hosts '
53
54
'when not specified in the request.'),
120
121
"""Update information about a host from its compute_node info."""
121
122
all_disk_mb = compute['local_gb'] * 1024
122
123
all_ram_mb = compute['memory_mb']
123
vcpus_total = compute['vcpus']
125
free_disk_mb = compute['free_disk_gb'] * 1024
126
free_ram_mb = compute['free_ram_mb']
124
128
if FLAGS.reserved_host_disk_mb > 0:
125
129
all_disk_mb -= FLAGS.reserved_host_disk_mb
130
free_disk_mb -= FLAGS.reserved_host_disk_mb
126
131
if FLAGS.reserved_host_memory_mb > 0:
127
132
all_ram_mb -= FLAGS.reserved_host_memory_mb
133
free_ram_mb -= FLAGS.reserved_host_memory_mb
128
135
#NOTE(jogo) free_ram_mb can be negative
129
self.free_ram_mb = all_ram_mb
136
self.free_ram_mb = free_ram_mb
130
137
self.total_usable_ram_mb = all_ram_mb
131
self.free_disk_mb = all_disk_mb
132
self.vcpus_total = vcpus_total
138
self.free_disk_mb = free_disk_mb
139
self.vcpus_total = compute['vcpus']
140
self.vcpus_used = compute['vcpus_used']
134
142
def consume_from_instance(self, instance):
135
"""Update information about a host from instance info."""
143
"""Incrementally update host state from an instance"""
136
144
disk_mb = (instance['root_gb'] + instance['ephemeral_gb']) * 1024
137
145
ram_mb = instance['memory_mb']
138
146
vcpus = instance['vcpus']
174
182
class HostManager(object):
175
183
"""Base HostManager class."""
177
# Can be overriden in a subclass
185
# Can be overridden in a subclass
178
186
host_state_cls = HostState
180
188
def __init__(self):
253
261
host_state_map = {}
255
# Make a compute node dict with the bare essential metrics.
263
# Get resource usage across the available compute nodes:
256
264
compute_nodes = db.compute_node_get_all(context)
257
265
for compute in compute_nodes:
258
266
service = compute['service']
267
275
host_state.update_from_compute_node(compute)
268
276
host_state_map[host] = host_state
270
# "Consume" resources from the host the instance resides on.
271
instances = db.instance_get_all(context,
272
columns_to_join=['instance_type'])
273
for instance in instances:
274
host = instance['host']
277
host_state = host_state_map.get(host, None)
280
host_state.consume_from_instance(instance)
281
278
return host_state_map