Created
October 20, 2011 22:41
-
-
Save vishvananda/1302613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/nova/scheduler/simple.py b/nova/scheduler/simple.py | |
index fc1b314..b6cbff4 100644 | |
--- a/nova/scheduler/simple.py | |
+++ b/nova/scheduler/simple.py | |
@@ -42,10 +42,13 @@ class SimpleScheduler(chance.ChanceScheduler): | |
def _schedule_instance(self, context, instance_id, *_args, **_kwargs): | |
"""Picks a host that is up and has the fewest running instances.""" | |
instance_ref = db.instance_get(context, instance_id) | |
- if (instance_ref['availability_zone'] | |
- and ':' in instance_ref['availability_zone'] | |
- and context.is_admin): | |
- zone, _x, host = instance_ref['availability_zone'].partition(':') | |
+ | |
+ availability_zone = instance_ref.get('availability_zone') | |
+ zone, host = None, None | |
+ if availability_zone: | |
+ zone, _x, host = availability_zone.partition(':') | |
+ | |
+ if host and context.is_admin: | |
service = db.service_get_by_args(context.elevated(), host, | |
'nova-compute') | |
if not self.service_is_up(service): | |
@@ -57,7 +60,11 @@ class SimpleScheduler(chance.ChanceScheduler): | |
db.instance_update(context, instance_id, {'host': host, | |
'scheduled_at': now}) | |
return host | |
+ | |
results = db.service_get_all_compute_sorted(context) | |
+ if zone: | |
+ results = [(service, cores) for (service, cores) in results | |
+ if service['availability_zone'] == zone] | |
for result in results: | |
(service, instance_cores) = result | |
if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores: | |
@@ -84,10 +91,13 @@ class SimpleScheduler(chance.ChanceScheduler): | |
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs): | |
"""Picks a host that is up and has the fewest volumes.""" | |
volume_ref = db.volume_get(context, volume_id) | |
- if (volume_ref['availability_zone'] | |
- and ':' in volume_ref['availability_zone'] | |
- and context.is_admin): | |
- zone, _x, host = volume_ref['availability_zone'].partition(':') | |
+ | |
+ availability_zone = volume_ref.get('availability_zone') | |
+ zone, host = None, None | |
+ if availability_zone: | |
+ zone, _x, host = availability_zone.partition(':') | |
+ | |
+ if host and context.is_admin: | |
service = db.service_get_by_args(context.elevated(), host, | |
'nova-volume') | |
if not self.service_is_up(service): | |
@@ -99,7 +109,11 @@ class SimpleScheduler(chance.ChanceScheduler): | |
db.volume_update(context, volume_id, {'host': host, | |
'scheduled_at': now}) | |
return host | |
+ | |
results = db.service_get_all_volume_sorted(context) | |
+ if zone: | |
+ results = [(service, gigs) for (service, gigs) in results | |
+ if service['availability_zone'] == zone] | |
for result in results: | |
(service, volume_gigabytes) = result | |
if volume_gigabytes + volume_ref['size'] > FLAGS.max_gigabytes: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment