I am trying to create a custom filter for OpenStack, using their FilterScheduler component. The documentation for the FilterScheduler is here: http://docs.openstack.org/developer/nova/devref/filter_scheduler.html#
Now, there is not much in the way of documentation for creating your own custom filter. Infact, the complete documentation is:
If you want to create your own filter you just need to inherit from BaseHostFilter and implement one method: host_passes. This method should return True if host passes the filter. It takes host_state (describes host) and filter_properties dictionary as the parameters.
As an example, nova.conf could contain the following scheduler-related settings:
--scheduler_driver=nova.scheduler.FilterScheduler
--scheduler_available_filters=nova.scheduler.filters.standard_filters
--scheduler_available_filters=myfilter.MyFilter
--scheduler_default_filters=RamFilter,ComputeFilter,MyFilter
I have created a custom "test_filter.py" -- it is very similar to "all_hosts_filter.py", which is the simplest standard filter.
Here it is in it's entirety:
from nova.scheduler import filters
from nova.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class TestFilter(filters.BaseHostFilter):
"""NOOP host filter. Returns all hosts."""
def host_passes(self, host_state, filter_properties):
LOG.debug("COMING FROM: nova/scheduler/filters/test_filter.py")
return True
But when I put this file, "test_filter.py", in the nova/scheduler/filters folder and restart OpenStack I get the following exception:
CRITICAL nova [-] Class test_filter could not be found: 'module' object has no attribute 'test_filter'
It appears that OpenStack is registering and trying to import my new filter, but some error is occuring. For reference, this is what the releveant sections of my /etc/nova/nova.conf file looks like:
scheduler_available_filters=nova.scheduler.filters.all_filters
scheduler_available_filters=nova.scheduler.filters.test_filter.TestFilter
scheduler_default_filters=TestFilter,RamFilter,ComputeFilter
======
UPDATE: 15th April 2000 hours BST.
An update to this question, still struggling. After discussing the problem with boris-42 on the OpenStack IRC channel we have investigated a bit more:
Openstack-scheduler is run as service from /usr/bin/nova-scheduler
It then has an error:
"Inner Exception: 'module' object has no attribute 'test_filter' from (pid=32696) import_class /usr/lib/python2.7/dist-packages/nova/utils.py:78"
Which suggests it is using the /usr/lib/python2.7/dist-packages/nova/ folder for the source files of the installation.
Putting my custom "test_filter.py" into /usr/lib/python2.7/dist-packages/nova/scheduler/filters causes the error above.
However, on closer inspection it appears that all other files in the /usr/lib/python2.7/dist-packages/nova/scheduler/filters folder are actually links to the files in /usr/share/pyshared/nova/scheduler/filters
So I put my "test_filter.py" in /usr/share/pyshared/nova/scheduler/filters -- and then created a symbolic link in the original folder.
This results in exactly the same folder. As long as the file is either present or a link exists in the folder /usr/lib/python2.7/dist-packages/nova/scheduler/filters then the error occurs.
The nova.conf file has been updated as follows:
scheduler_available_filters=nova.scheduler.filters.TestFilter
scheduler_default_filters=TestFilter