* The same functionality exists in the filter scheduler, except for nova volumes. So just keep nova-volume scheduling here. * Add very basic Simple Scheduler testing * Simple Scheduler will be completely removed after Folsom release Change-Id: Ia2a2b26bc67cf152963533d68a774f454d763cbd
81 lines
3.1 KiB
Python
81 lines
3.1 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright (c) 2010 OpenStack, LLC.
|
|
# Copyright 2010 United States Government as represented by the
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
# All Rights Reserved.
|
|
#
|
|
# 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.
|
|
|
|
"""
|
|
Simple Scheduler - for Volumes
|
|
|
|
Note: Deprecated in Folsom. Will be removed along with nova-volumes
|
|
"""
|
|
|
|
from nova import db
|
|
from nova import exception
|
|
from nova import flags
|
|
from nova.openstack.common import cfg
|
|
from nova.scheduler import chance
|
|
from nova.scheduler import driver
|
|
from nova import utils
|
|
|
|
|
|
simple_scheduler_opts = [
|
|
cfg.IntOpt("max_gigabytes",
|
|
default=10000,
|
|
help="maximum number of volume gigabytes to allow per host"),
|
|
]
|
|
|
|
FLAGS = flags.FLAGS
|
|
FLAGS.register_opts(simple_scheduler_opts)
|
|
|
|
|
|
class SimpleScheduler(chance.ChanceScheduler):
|
|
"""Implements Naive Scheduler that tries to find least loaded host."""
|
|
|
|
def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
|
|
"""Picks a host that is up and has the fewest volumes."""
|
|
elevated = context.elevated()
|
|
|
|
volume_ref = db.volume_get(context, volume_id)
|
|
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(elevated, host, 'nova-volume')
|
|
if not utils.service_is_up(service):
|
|
raise exception.WillNotSchedule(host=host)
|
|
driver.cast_to_volume_host(context, host, 'create_volume',
|
|
volume_id=volume_id, **_kwargs)
|
|
return None
|
|
|
|
results = db.service_get_all_volume_sorted(elevated)
|
|
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:
|
|
msg = _("Not enough allocatable volume gigabytes remaining")
|
|
raise exception.NoValidHost(reason=msg)
|
|
if utils.service_is_up(service) and not service['disabled']:
|
|
driver.cast_to_volume_host(context, service['host'],
|
|
'create_volume', volume_id=volume_id, **_kwargs)
|
|
return None
|
|
msg = _("Is the appropriate service running?")
|
|
raise exception.NoValidHost(reason=msg)
|