Allows non-admin users to use simple scheduler
Fixes bug 885955 Change-Id: I88be04cbc55e272162328a33656fc5d6e1831c32
This commit is contained in:
@@ -40,6 +40,7 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
|
|
||||||
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs):
|
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs):
|
||||||
"""Picks a host that is up and has the fewest running instances."""
|
"""Picks a host that is up and has the fewest running instances."""
|
||||||
|
elevated = context.elevated()
|
||||||
|
|
||||||
availability_zone = instance_opts.get('availability_zone')
|
availability_zone = instance_opts.get('availability_zone')
|
||||||
|
|
||||||
@@ -48,13 +49,12 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
zone, _x, host = availability_zone.partition(':')
|
zone, _x, host = availability_zone.partition(':')
|
||||||
|
|
||||||
if host and context.is_admin:
|
if host and context.is_admin:
|
||||||
service = db.service_get_by_args(context.elevated(), host,
|
service = db.service_get_by_args(elevated, host, 'nova-compute')
|
||||||
'nova-compute')
|
|
||||||
if not self.service_is_up(service):
|
if not self.service_is_up(service):
|
||||||
raise driver.WillNotSchedule(_("Host %s is not alive") % host)
|
raise driver.WillNotSchedule(_("Host %s is not alive") % host)
|
||||||
return host
|
return host
|
||||||
|
|
||||||
results = db.service_get_all_compute_sorted(context)
|
results = db.service_get_all_compute_sorted(elevated)
|
||||||
if zone:
|
if zone:
|
||||||
results = [(service, cores) for (service, cores) in results
|
results = [(service, cores) for (service, cores) in results
|
||||||
if service['availability_zone'] == zone]
|
if service['availability_zone'] == zone]
|
||||||
@@ -90,6 +90,8 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
|
|
||||||
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
|
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
|
||||||
"""Picks a host that is up and has the fewest volumes."""
|
"""Picks a host that is up and has the fewest volumes."""
|
||||||
|
elevated = context.elevated()
|
||||||
|
|
||||||
volume_ref = db.volume_get(context, volume_id)
|
volume_ref = db.volume_get(context, volume_id)
|
||||||
availability_zone = volume_ref.get('availability_zone')
|
availability_zone = volume_ref.get('availability_zone')
|
||||||
|
|
||||||
@@ -97,15 +99,14 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
if availability_zone:
|
if availability_zone:
|
||||||
zone, _x, host = availability_zone.partition(':')
|
zone, _x, host = availability_zone.partition(':')
|
||||||
if host and context.is_admin:
|
if host and context.is_admin:
|
||||||
service = db.service_get_by_args(context.elevated(), host,
|
service = db.service_get_by_args(elevated, host, 'nova-volume')
|
||||||
'nova-volume')
|
|
||||||
if not self.service_is_up(service):
|
if not self.service_is_up(service):
|
||||||
raise driver.WillNotSchedule(_("Host %s not available") % host)
|
raise driver.WillNotSchedule(_("Host %s not available") % host)
|
||||||
driver.cast_to_volume_host(context, host, 'create_volume',
|
driver.cast_to_volume_host(context, host, 'create_volume',
|
||||||
volume_id=volume_id, **_kwargs)
|
volume_id=volume_id, **_kwargs)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
results = db.service_get_all_volume_sorted(context)
|
results = db.service_get_all_volume_sorted(elevated)
|
||||||
if zone:
|
if zone:
|
||||||
results = [(service, gigs) for (service, gigs) in results
|
results = [(service, gigs) for (service, gigs) in results
|
||||||
if service['availability_zone'] == zone]
|
if service['availability_zone'] == zone]
|
||||||
@@ -124,8 +125,9 @@ class SimpleScheduler(chance.ChanceScheduler):
|
|||||||
|
|
||||||
def schedule_set_network_host(self, context, *_args, **_kwargs):
|
def schedule_set_network_host(self, context, *_args, **_kwargs):
|
||||||
"""Picks a host that is up and has the fewest networks."""
|
"""Picks a host that is up and has the fewest networks."""
|
||||||
|
elevated = context.elevated()
|
||||||
|
|
||||||
results = db.service_get_all_network_sorted(context)
|
results = db.service_get_all_network_sorted(elevated)
|
||||||
for result in results:
|
for result in results:
|
||||||
(service, instance_count) = result
|
(service, instance_count) = result
|
||||||
if instance_count >= FLAGS.max_networks:
|
if instance_count >= FLAGS.max_networks:
|
||||||
|
|||||||
Reference in New Issue
Block a user