<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Danny-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">People have been thinking about affinity/anti-affinity scheduling so this is a good area to look at but we might want to think of a general approach that addresses
this and other issues. I know that Yathi & Debo have proposed a BP:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
<a href="https://blueprints.launchpad.net/nova/+spec/solver-scheduler">https://blueprints.launchpad.net/nova/+spec/solver-scheduler</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">you might want to check it out and see how it relates to your issues.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Don Dugger<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">"Censeo Toto nos in Kansa esse decisse." - D. Gale<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Ph: 303/443-3786<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif""> Danny Beutler [mailto:dannybeutler@gmail.com]
<br>
<b>Sent:</b> Friday, August 1, 2014 10:47 AM<br>
<b>To:</b> openstack@lists.openstack.org<br>
<b>Subject:</b> [Openstack] Custom Nova Scheduler Weigher<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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).
<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Here is the code for the class:<br>
<br>
# Copyright (c) 2011 OpenStack Foundation<br>
# All Rights Reserved.<br>
#<br>
# Licensed under the Apache License, Version 2.0 (the "License"); you may<br>
# not use this file except in compliance with the License. You may obtain<br>
# a copy of the License at<br>
#<br>
# <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>
#<br>
# Unless required by applicable law or agreed to in writing, software<br>
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT<br>
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the<br>
# License for the specific language governing permissions and limitations<br>
<br>
"""<br>
AntiAffinityWeigher. Weigh hosts by whether or not they have another host in the same group.<br>
<br>
"""<br>
<br>
from oslo.config import cfg<br>
<br>
from nova import db<br>
from nova.openstack.common.gettextutils import _<br>
from nova.scheduler import weights<br>
from nova.scheduler import filters<br>
from nova.openstack.common import log as logging<br>
<br>
LOG = logging.getLogger(__name__)<br>
<br>
anti_affinity_weight_opts = [<br>
cfg.FloatOpt('antiAffinityWeigher_Multiplier',<br>
default=1000.0,<br>
help='Multiplier used for weighing hosts. Negative '<br>
'numbers mean to stack vs spread.'),<br>
]<br>
<br>
CONF = cfg.CONF<br>
CONF.register_opts(anti_affinity_weight_opts)<br>
<br>
<br>
class AntiAffinityWeigher(weights.BaseHostWeigher):<br>
def _weight_multiplier(self):<br>
"""Override the weight multiplier."""<br>
return CONF.antiAffinityWeigher_Multiplier<br>
<br>
def _weigh_object(self, host_state, weight_properties):<br>
group_hosts = weight_properties.get('group_hosts') or []<br>
LOG.debug(_("Group anti affinity Weigher: check if %(host)s not "<br>
"in %(configured)s"), {'host': host_state.host,<br>
'configured': group_hosts})<br>
if group_hosts:<br>
return group_hosts.amount() * 100000<br>
<br>
# No groups configured<br>
return 0<br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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: <br>
scheduler_weight_classes=nova.scheduler.weights.all_weighers,nova.scheduler.AntiAffinityWeigher<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">After restarting the scheduler service I get the following error in the nova logs:<br>
<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"])<br>
Traceback (most recent call last):<br>
File "/usr/bin/nova-scheduler", line 10, in <module><br>
sys.exit(main())<br>
File "/usr/lib/python2.6/site-packages/nova/cmd/scheduler.py", line 39, in main<br>
topic=CONF.scheduler_topic)<br>
File "/usr/lib/python2.6/site-packages/nova/service.py", line 257, in create<br>
db_allowed=db_allowed)<br>
File "/usr/lib/python2.6/site-packages/nova/service.py", line 139, in __init__<br>
self.manager = manager_class(host=self.host, *args, **kwargs)<br>
File "/usr/lib/python2.6/site-packages/nova/scheduler/manager.py", line 65, in __init__<br>
self.driver = importutils.import_object(scheduler_driver)<br>
File "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", line 40, in import_object<br>
return import_class(import_str)(*args, **kwargs)<br>
File "/usr/lib/python2.6/site-packages/nova/scheduler/filter_scheduler.py", line 59, in __init__<br>
super(FilterScheduler, self).__init__(*args, **kwargs)<br>
File "/usr/lib/python2.6/site-packages/nova/scheduler/driver.py", line 103, in __init__<br>
CONF.scheduler_host_manager)<br>
File "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", line 40, in import_object<br>
return import_class(import_str)(*args, **kwargs)<br>
File "/usr/lib/python2.6/site-packages/nova/scheduler/host_manager.py", line 297, in __init__<br>
CONF.scheduler_weight_classes)<br>
File "/usr/lib/python2.6/site-packages/nova/loadables.py", line 105, in get_matching_classes<br>
obj = importutils.import_class(cls_name)<br>
File "/usr/lib/python2.6/site-packages/nova/openstack/common/importutils.py", line 35, in import_class<br>
traceback.format_exception(*sys.exc_info())))<br>
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"])<br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">I have also tried a few different naming conventions such as "AntiAffinityWeigher.AntiAffinityWeigher" and "myWeigher.AntiAffinityWeigher" to no avail.
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Any help would be greatly appreciated.<br>
<br>
Thanks,<br>
Danny<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>