[Openstack] Custom Nova Scheduler Weigher

Sylvain Bauza sbauza at redhat.com
Fri Aug 1 20:43:01 UTC 2014


Le 01/08/2014 18:46, Danny Beutler a écrit :
> I am in the process of implementing a custom weigher class. I have 
> created a weigher that prefers hosts which do not have other instances 
> in the same group (think GroupAntiAffinityFilter but for weight).
>
> Here is the code for the class:
>
> # Copyright (c) 2011 OpenStack Foundation
> # 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
>
> """
> AntiAffinityWeigher.  Weigh hosts by whether or not they have another 
> host in the same group.
>
> """
>
> from oslo.config import cfg
>
> from nova import db
> from nova.openstack.common.gettextutils import _
> from nova.scheduler import weights
> from nova.scheduler import filters
> from nova.openstack.common import log as logging
>
> LOG = logging.getLogger(__name__)
>
> anti_affinity_weight_opts = [
>         cfg.FloatOpt('antiAffinityWeigher_Multiplier',
>                      default=1000.0,
>                      help='Multiplier used for weighing hosts.  Negative '
>                           'numbers mean to stack vs spread.'),
> ]
>
> CONF = cfg.CONF
> CONF.register_opts(anti_affinity_weight_opts)
>
>
> class AntiAffinityWeigher(weights.BaseHostWeigher):
>     def _weight_multiplier(self):
>         """Override the weight multiplier."""
>         return CONF.antiAffinityWeigher_Multiplier
>
>     def _weigh_object(self, host_state, weight_properties):
>         group_hosts = weight_properties.get('group_hosts') or []
>         LOG.debug(_("Group anti affinity Weigher: check if %(host)s not "
>             "in %(configured)s"), {'host': host_state.host,
>             'configured': group_hosts})
>         if group_hosts:
>             return group_hosts.amount() * 100000
>
>         # No groups configured
>         return 0
>
>
> I know the python is at least close to correct because the scheduler 
> service wouldn't even restart until it was. After I got the bugs 
> worked out of the module, I added modified the /etc/nova/nova.conf 
> file to have the custom weigher like so:
> scheduler_weight_classes=nova.scheduler.weights.all_weighers,nova.scheduler.AntiAffinityWeigher
>
> After restarting the scheduler service I get the following error in 
> the nova logs:
> <178>Aug  1 16:46:11 node-25 nova-nova CRITICAL: Class 
> AntiAffinityWeigher cannot be found (['Traceback (most recent call 
> last):\n', '  File 
> "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", 
> line 31, in import_class\n    return getattr(sys.modules[mod_str], 
> class_str)\n', "AttributeError: 'module' object has no attribute 
> 'AntiAffinityWeigher'\n"])
> Traceback (most recent call last):
>   File "/usr/bin/nova-scheduler", line 10, in <module>
>     sys.exit(main())
>   File "/usr/lib/python2.6/site-packages/nova/cmd/scheduler.py", line 
> 39, in main
>     topic=CONF.scheduler_topic)
>   File "/usr/lib/python2.6/site-packages/nova/service.py", line 257, 
> in create
>     db_allowed=db_allowed)
>   File "/usr/lib/python2.6/site-packages/nova/service.py", line 139, 
> in __init__
>     self.manager = manager_class(host=self.host, *args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/nova/scheduler/manager.py", 
> line 65, in __init__
>     self.driver = importutils.import_object(scheduler_driver)
>   File 
> "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", 
> line 40, in import_object
>     return import_class(import_str)(*args, **kwargs)
>   File 
> "/usr/lib/python2.6/site-packages/nova/scheduler/filter_scheduler.py", 
> line 59, in __init__
>     super(FilterScheduler, self).__init__(*args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/nova/scheduler/driver.py", 
> line 103, in __init__
>     CONF.scheduler_host_manager)
>   File 
> "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", 
> line 40, in import_object
>     return import_class(import_str)(*args, **kwargs)
>   File 
> "/usr/lib/python2.6/site-packages/nova/scheduler/host_manager.py", 
> line 297, in __init__
>     CONF.scheduler_weight_classes)
>   File "/usr/lib/python2.6/site-packages/nova/loadables.py", line 105, 
> in get_matching_classes
>     obj = importutils.import_class(cls_name)
>   File 
> "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", 
> line 35, in import_class
>     traceback.format_exception(*sys.exc_info())))
> ImportError: Class AntiAffinityWeigher cannot be found (['Traceback 
> (most recent call last):\n', '  File 
> "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", 
> line 31, in import_class\n    return getattr(sys.modules[mod_str], 
> class_str)\n', "AttributeError: 'module' object has no attribute 
> 'AntiAffinityWeigher'\n"])
>
>
>
> I have also tried a few different naming conventions such as 
> "AntiAffinityWeigher.AntiAffinityWeigher" and 
> "myWeigher.AntiAffinityWeigher" to no avail.
>
> Any help would be greatly appreciated.
>

Sure, just look at the traceback, the exception is really explicite. 
When giving in the config the name of the new weighter, you just missed 
a submodule in nova.scheduler.

Correct it, it's not nova.scheduler.AntiAffinityWeigher :-)


Don't hesitate to provide this change upstream, please so we could 
review it.

-Sylvain

> Thanks,
> Danny
>
>
> _______________________________________________
> Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack
> Post to     : openstack at lists.openstack.org
> Unsubscribe : http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20140801/3d8ef150/attachment.html>


More information about the Openstack mailing list