diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2010-08-09 12:56:32 -0500 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2010-08-09 12:56:32 -0500 |
| commit | 3e01acd4e70f9e850487c5ac4067ab2c2c1a18eb (patch) | |
| tree | 824e4726c6210adc25b13100fe9d713f91da8c00 /nova/scheduler | |
| parent | 795b32fc66f243239d05a5434f939a76800c0052 (diff) | |
| download | nova-3e01acd4e70f9e850487c5ac4067ab2c2c1a18eb.tar.gz nova-3e01acd4e70f9e850487c5ac4067ab2c2c1a18eb.tar.xz nova-3e01acd4e70f9e850487c5ac4067ab2c2c1a18eb.zip | |
separated scheduler types into own modules
Diffstat (limited to 'nova/scheduler')
| -rw-r--r-- | nova/scheduler/base.py (renamed from nova/scheduler/scheduler.py) | 32 | ||||
| -rw-r--r-- | nova/scheduler/bestfit.py | 30 | ||||
| -rw-r--r-- | nova/scheduler/chance.py | 33 | ||||
| -rw-r--r-- | nova/scheduler/service.py | 10 |
4 files changed, 72 insertions, 33 deletions
diff --git a/nova/scheduler/scheduler.py b/nova/scheduler/base.py index 49ef40f06..5c359943e 100644 --- a/nova/scheduler/scheduler.py +++ b/nova/scheduler/base.py @@ -15,10 +15,9 @@ # under the License. """ -Scheduler Classes +Scheduler base class that all Schedulers should inherit from """ -import random import time from nova import flags @@ -50,7 +49,9 @@ class Scheduler(object): return False # Would be a lot easier if we stored heartbeat time in epoch :) - time_str = time_str.replace('Z', 'UTC') + + # The 'str()' here is to get rid of a pylint error + time_str = str(time_str).replace('Z', 'UTC') time_split = time.strptime(time_str, '%Y-%m-%dT%H:%M:%S%Z') epoch_time = int(time.mktime(time_split)) - time.timezone return (time.time() - epoch_time) < FLAGS.node_down_time @@ -62,28 +63,3 @@ class Scheduler(object): def pick_node(self, instance_id, **_kwargs): """You DEFINITELY want to define this in your subclass""" raise NotImplementedError("Your subclass should define pick_node") - - -class RandomScheduler(Scheduler): - """ - Implements Scheduler as a random node selector - """ - - def __init__(self): - super(RandomScheduler, self).__init__() - - def pick_node(self, instance_id, **_kwargs): - nodes = self.compute_nodes_up() - return nodes[int(random.random() * len(nodes))] - - -class BestFitScheduler(Scheduler): - """ - Implements Scheduler as a best-fit node selector - """ - - def __init__(self): - super(BestFitScheduler, self).__init__() - - def pick_node(self, instance_id, **_kwargs): - raise NotImplementedError("BestFitScheduler is not done yet") diff --git a/nova/scheduler/bestfit.py b/nova/scheduler/bestfit.py new file mode 100644 index 000000000..1bd24456a --- /dev/null +++ b/nova/scheduler/bestfit.py @@ -0,0 +1,30 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2010 Openstack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Best Fit Scheduler +""" + +from nova.scheduler.base import Scheduler + + +class BestFitScheduler(Scheduler): + """ + Implements Scheduler as a best-fit node selector + """ + + def pick_node(self, instance_id, **_kwargs): + raise NotImplementedError("BestFitScheduler is not done yet") diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py new file mode 100644 index 000000000..c57c346f5 --- /dev/null +++ b/nova/scheduler/chance.py @@ -0,0 +1,33 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2010 Openstack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Chance (Random) Scheduler implementation +""" + +import random + +from nova.scheduler.base import Scheduler + + +class ChanceScheduler(Scheduler): + """ + Implements Scheduler as a random node selector + """ + + def pick_node(self, instance_id, **_kwargs): + nodes = self.compute_nodes_up() + return nodes[int(random.random() * len(nodes))] diff --git a/nova/scheduler/service.py b/nova/scheduler/service.py index 9d2d35f13..44b30ecb5 100644 --- a/nova/scheduler/service.py +++ b/nova/scheduler/service.py @@ -25,15 +25,16 @@ from nova import exception from nova import flags from nova import rpc from nova import service -from nova.scheduler import scheduler +from nova.scheduler import chance +from nova.scheduler import bestfit FLAGS = flags.FLAGS flags.DEFINE_string('scheduler_type', - 'random', + 'chance', 'the scheduler to use') -SCHEDULER_CLASSES = {'random': scheduler.RandomScheduler, - 'bestfit': scheduler.BestFitScheduler} +SCHEDULER_CLASSES = {'chance': chance.ChanceScheduler, + 'bestfit': bestfit.BestFitScheduler} class SchedulerService(service.Service): @@ -72,4 +73,3 @@ class SchedulerService(service.Service): "args": {"instance_id": instance_id}}) logging.debug("Casting to node %s for running instance %s", node, instance_id) - |
