26
26
from nova import exception
27
27
from nova.scheduler import driver
28
28
from nova.scheduler import chance
29
from nova import utils
30
31
FLAGS = flags.FLAGS
31
32
flags.DEFINE_integer("max_cores", 16,
58
59
if host and context.is_admin:
59
60
service = db.service_get_by_args(elevated, host, 'nova-compute')
60
if not self.service_is_up(service):
61
if not utils.service_is_up(service):
61
62
raise exception.WillNotSchedule(host=host)
79
80
instance_cores + instance_opts['vcpus'] > FLAGS.max_cores:
80
81
msg = _("Not enough allocatable CPU cores remaining")
81
82
raise exception.NoValidHost(reason=msg)
82
if self.service_is_up(service):
83
if utils.service_is_up(service) and not service['disabled']:
83
84
return service['host']
84
85
msg = _("Is the appropriate service running?")
85
86
raise exception.NoValidHost(reason=msg)
120
121
zone, _x, host = availability_zone.partition(':')
121
122
if host and context.is_admin:
122
123
service = db.service_get_by_args(elevated, host, 'nova-volume')
123
if not self.service_is_up(service):
124
if not utils.service_is_up(service):
124
125
raise exception.WillNotSchedule(host=host)
125
126
driver.cast_to_volume_host(context, host, 'create_volume',
126
127
volume_id=volume_id, **_kwargs)
135
136
if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes:
136
137
msg = _("Not enough allocatable volume gigabytes remaining")
137
138
raise exception.NoValidHost(reason=msg)
138
if self.service_is_up(service):
139
if utils.service_is_up(service) and not service['disabled']:
139
140
driver.cast_to_volume_host(context, service['host'],
140
141
'create_volume', volume_id=volume_id, **_kwargs)
142
143
msg = _("Is the appropriate service running?")
143
144
raise exception.NoValidHost(reason=msg)
145
def schedule_set_network_host(self, context, *_args, **_kwargs):
146
"""Picks a host that is up and has the fewest networks."""
147
elevated = context.elevated()
149
results = db.service_get_all_network_sorted(elevated)
150
for result in results:
151
(service, instance_count) = result
152
if instance_count >= FLAGS.max_networks:
153
msg = _("Not enough allocatable networks remaining")
154
raise exception.NoValidHost(reason=msg)
155
if self.service_is_up(service):
156
driver.cast_to_network_host(context, service['host'],
157
'set_network_host', **_kwargs)
159
msg = _("Is the appropriate service running?")
160
raise exception.NoValidHost(reason=msg)