<br><br><div class="gmail_quote">On Tue, Nov 20, 2012 at 10:40 AM, Russell Bryant <span dir="ltr"><<a href="mailto:rbryant@redhat.com" target="_blank">rbryant@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Greetings,<br>
<br>
There is currently a patch in the review queue for nova that adds hooks.<br>
<br>
<a href="https://review.openstack.org/#/c/16336/" target="_blank">https://review.openstack.org/#/c/16336/</a><br>
<br>
I like the concept, but I think it could benefit from some design<br>
discussion.  That's difficult on gerrit and much better suited for the<br>
mailing list, so here we are.<br>
<br>
My biggest design comment on this has been that I think it needs to<br>
support loading custom modules that register hooks.  I also would like<br>
to minimize how much of this we have to expose to the configuration.<br>
Here's the general functionality I have in mind:<br>
<br>
   I want to hook into nova at the defined 'foo' hook point.  I write a<br>
   hook module and drop it into the predefined directory<br>
   /path/to/nova/modules/.  Nova should automatically import everything<br>
   in this custom module directory and the hooks get registered.<br>
<br>
   The registration mechanism could either be the modules calling an API<br>
   to register their hooks at load time, or nova could scan the module<br>
   for hooks and register them automatically.  Whichever is more<br>
   Pythonic is fine with me.<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
The only configuration option I see that would be needed here is the<br>
ability to customize with directory (or directories) are used for<br>
loading custom modules.<br>
<br>
There are some related efforts going on here that need to be considered,<br>
as well:<br>
<br>
1) nova/loadables.py<br>
<br>
This is used in the patch right now.  Some comments on this approach:<br>
<br>
 - It means nova scans the module and automatically registers hook<br>
   classes that are of the right type.  I think that makes sense, but<br>
   is that the most Pythonic approach for this kind of thing?<br>
<br>
 - This will need to be extended if we want to support a directory of<br>
   user provided modules that have hooks in them.  I think that's<br>
   pretty important for the primary hook use case.<br>
<br>
2) nova/openstack/common/pluginmanager.py<br></blockquote><div><br></div><div>At the summit Monty proposed using Stevedore and entry points for loading dynamic code in nova (I think that patch is waiting for some attention to make the tests run more quickly).</div>
<div><br></div><div>In addition to the DriverManager Monty was using, Stevedore has a HookManager for exactly this use case of running hooks (<a href="http://stevedore.readthedocs.org/en/latest/managers.html#hookmanager">http://stevedore.readthedocs.org/en/latest/managers.html#hookmanager</a>). Using the HookManager loads only the plugins necessary for a given hook. The steps for loading and invoking are separate, allowing hooks to be loaded at application startup to avoid runtime penalties from loading code dynamically the first time a method is called.</div>
<div><br></div><div>In addition to the developer benefits of using entry points, they provide some important deployment benefits. For example, there's no need to deploy code from multiple unrelated OS packages into the same directory, which is a common source of complaints from packagers. It also avoids the need to configure "a" search path, since anything visible on the python import path can provide a plugin. We've used entry points to good effect in ceilometer, especially when allowing deployers to provide custom meters or pollsters.</div>
<div><br></div><div>Doug</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I haven't looked into this lately, but at a high level, there seems to<br>
be some overlap here.  I'd like to see this analyzed for how it could<br>
apply to hooks.  If it doesn't fit, that's fine, I just want to make<br>
sure it's considered and the results documented.<br>
<br>
Thanks,<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Russell Bryant<br>
<br>
_______________________________________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</font></span></blockquote></div><br>