| 1 | = Plugging In = |
| 2 | |
| 3 | The [source:fedd/trunk/federation/skeleton.py skeleton plugin] is not a real plug-in. It is one of the standard access controllers that ships with the fedd install. First we'll create a plug-in. A plug in is just python code that defines a class called {{{access}}} that accepts the same parameters to its initializer as the [source:fedd/trunk/federation/skeleton.py skeleton plugin]. These are a configuration object and an authorizer object (and the [source:fedd/trunk/federation/access.py standard plug-in base class] will handle the authorizer for you. It should also conform to the conventions in the skeleton with respect to setting up the {{{self.soap_services}}} and {{{self.xmlrpc_services}}} dicts, and handle the various [FeddPluginCalls plug-in calls]. |
| 4 | |
| 5 | An easy way to do this is to simply copy the skeleton into a file in another directory with a different name. Because you have moved this module relative to its current place in the hierarchy (it is no longer in the {{{federation}}} directory) you will have to modify the import paths at the beginning. Specifically change the lines: |
| 6 | |
| 7 | {{{ |
| 8 | from util import * |
| 9 | from fedid import fedid, generate_fedid |
| 10 | from authorizer import authorizer |
| 11 | from service_error import service_error |
| 12 | from remote_service import xmlrpc_handler, soap_handler, service_caller |
| 13 | |
| 14 | import topdl |
| 15 | |
| 16 | from access import access_base |
| 17 | }}} |
| 18 | |
| 19 | to: |
| 20 | |
| 21 | {{{ |
| 22 | from federation.util import * |
| 23 | from federation.fedid import fedid, generate_fedid |
| 24 | from federation.authorizer import authorizer |
| 25 | from federation.service_error import service_error |
| 26 | from federation.remote_service import xmlrpc_handler, soap_handler, service_caller |
| 27 | |
| 28 | import federation.topdl as topdl |
| 29 | |
| 30 | from federation.access import access_base |
| 31 | |
| 32 | }}} |
| 33 | |
| 34 | That is, explicitly set the {{{federation.}}} scope for modules in {{{fedd}}}'s {{{federation}}} directory. The plugin sits outside the fedd code tree, so if it needs to use other code that lives in that tree, it must import from the {{{federation}}} package. |
| 35 | |
| 36 | It is also probably worthwhile to add a log message to the initializer so that you can tell your code ran. For example, add |
| 37 | |
| 38 | {{{ |
| 39 | self.log.debug("This is my plugin module") |
| 40 | }}} |
| 41 | |
| 42 | to the end of your {{{access.__init__(self, config, auth)}}} member. |
| 43 | |
| 44 | |
| 45 | To dynamically load the plug-in you need to: |
| 46 | |
| 47 | * Create a directory readable by the user fedd will run as |
| 48 | * Move your python plug-in code into there. Name the file something other than {{{emulab.py}}}, {{{dragon.py}}}, {{{protogeni.py}}}, {{{deter_internal.py}}} or {{{skel.py}}}. Make sure it can also be read by the fedd user. |
| 49 | * Add your pathname to the '''module_path''' configuration variable in the '''[globals]''' section |
| 50 | * Set the '''access_type''' to the name of your file (without the {{{.py}}}). |
| 51 | |
| 52 | If your plugin is in {{{/usr/home/faber/plugins/plug.py}}} then your configuration file should contain the following definitions in the {{{[globals]}}} section: |
| 53 | |
| 54 | {{{ |
| 55 | module_path: /usr/home/faber/plugins |
| 56 | access_type: plug |
| 57 | }}} |
| 58 | |
| 59 | Run fedd with your modified configuration after '''--config''' and with '''--debug''' to see your log message: |
| 60 | |
| 61 | {{{ |
| 62 | fedd.py --config=/home/faber/fedd/fedd.config --debug |
| 63 | }}} |
| 64 | |
| 65 | and you should see something like: |
| 66 | |
| 67 | {{{ |
| 68 | 29 Jun 10 19:33:29 fedd.access [read_state]: No saved state: Can't open /users/faber/fedd-config/skel2/skel_access.state: [Errno 2] No such file or directory: '/users/faber/fedd-config/skel2/skel_access.state' |
| 69 | 29 Jun 10 19:33:29 fedd.access This is my plugin module |
| 70 | }}} |