The nova.hooks Module

Decorator and config option definitions for adding custom code (hooks) around callables.

Any method may have the ‘add_hook’ decorator applied, which yields the ability to invoke Hook objects before or after the method. (i.e. pre and post)

Hook objects are loaded by HookLoaders. Each named hook may invoke multiple Hooks.

Example Hook object:

| class MyHook(object):
|    def pre(self, *args, **kwargs):
|       # do stuff before wrapped callable runs
|
|   def post(self, rv, *args, **kwargs):
|       # do stuff after wrapped callable runs

Example Hook object with function parameters:

| class MyHookWithFunction(object):
|   def pre(self, f, *args, **kwargs):
|       # do stuff with wrapped function info
|   def post(self, f, *args, **kwargs):
|       # do stuff with wrapped function info
exception FatalHookException

Bases: exceptions.Exception

Exception which should be raised by hooks to indicate that normal execution of the hooked function should be terminated. Raised exception will be logged and reraised.

class HookManager(name)

Bases: stevedore.hook.HookManager

run_post(name, rv, args, kwargs, f=None)

Execute optional post methods of loaded hooks.

Parameters:
  • name – The name of the loaded hooks.
  • rv – Return values of target method call.
  • args – Positional arguments which would be transmitted into all post methods of loaded hooks.
  • kwargs – Keyword args which would be transmitted into all post methods of loaded hooks.
  • f – Target function.
run_pre(name, args, kwargs, f=None)

Execute optional pre methods of loaded hooks.

Parameters:
  • name – The name of the loaded hooks.
  • args – Positional arguments which would be transmitted into all pre methods of loaded hooks.
  • kwargs – Keyword args which would be transmitted into all pre methods of loaded hooks.
  • f – Target function.
add_hook(name, pass_function=False)

Execute optional pre and post methods around the decorated function. This is useful for customization around callables.

reset()

Clear loaded hooks.

Previous topic

The nova.hacking.checks Module

Next topic

The nova.i18n Module

Project Source

This Page