![Joe Gordon](/assets/img/avatar_default.png)
* Explain these docs are for trunk (copied from ironic) * All the docs in this repo are meant to be developer docs, so having a devref inside of the docs is redundant and just makes the docs more complicated to navigate. Move everything out of the devref folder and link to everything from main index. * Move man pages into separate section. The man pages are pretty sparse * right now, we should either make them useful or just delete them * Remove dead docs from unused_docs list in doc/source/conf.py * Shuffle docs landing page, move common referees to the top (API, hypervisor support matrix), Add a introduction section and more. The hope is the updated layout makes this document easier to navigate. * Use maxdepth of 1 * Rename a few sections with what are hopefully better names The next step is to prune out outdated documents and further cleanup this page. Change-Id: Iff453e47ccc902a0e72b1a5f6ce1ee939ff3a1a0
58 lines
1.5 KiB
ReStructuredText
58 lines
1.5 KiB
ReStructuredText
Hooks
|
|
=====
|
|
|
|
Hooks provide a mechanism to extend Nova with custom code through a plugin
|
|
mechanism.
|
|
|
|
Named hooks are added to nova code via a decorator that will lazily load
|
|
plugin code matching the name. The loading works via setuptools
|
|
`entry points`_.
|
|
|
|
.. _`entry points`: http://pythonhosted.org/setuptools/pkg_resources.html#entry-points
|
|
|
|
What are hooks good for?
|
|
------------------------
|
|
|
|
Hooks are good for anchoring your custom code to Nova internal APIs.
|
|
|
|
What are hooks NOT good for?
|
|
----------------------------
|
|
|
|
Hooks should not be used when API stability is a key factor. Internal APIs may
|
|
change. Consider using a notification driver if this is important to you.
|
|
|
|
Declaring hooks in the Nova codebase
|
|
------------------------------------
|
|
|
|
The following example declares a *resize_hook* around the *resize_instance* method::
|
|
|
|
from nova import hooks
|
|
|
|
@hooks.add_hook("resize_hook")
|
|
def resize_instance(self, context, instance, a=1, b=2):
|
|
...
|
|
|
|
Hook objects can now be attached via entry points to the *resize_hook*.
|
|
|
|
Adding hook object code
|
|
-----------------------
|
|
|
|
1. Setup a Python package with a setup.py file.
|
|
2. Add the following to the setup.py setup call::
|
|
|
|
entry_points = {
|
|
'nova.hooks': [
|
|
'resize_hook=your_package.hooks:YourHookClass',
|
|
]
|
|
},
|
|
|
|
3. *YourHookClass* should be an object with *pre* and/or *post* methods::
|
|
|
|
class YourHookClass(object):
|
|
|
|
def pre(self, *args, **kwargs):
|
|
....
|
|
|
|
def post(self, rv, *args, **kwargs):
|
|
....
|