Changes between Initial Version and Version 1 of FeddPluggingIn


Ignore:
Timestamp:
Jun 29, 2010 12:20:17 PM (14 years ago)
Author:
faber
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FeddPluggingIn

    v1 v1  
     1= Plugging In =
     2
     3The [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
     5An 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{{{
     8from util import *
     9from fedid import fedid, generate_fedid
     10from authorizer import authorizer
     11from service_error import service_error
     12from remote_service import xmlrpc_handler, soap_handler, service_caller
     13
     14import topdl
     15
     16from access import access_base
     17}}}
     18
     19to:
     20
     21{{{
     22from federation.util import *
     23from federation.fedid import fedid, generate_fedid
     24from federation.authorizer import authorizer
     25from federation.service_error import service_error
     26from federation.remote_service import xmlrpc_handler, soap_handler, service_caller
     27
     28import federation.topdl as topdl
     29
     30from federation.access import access_base
     31
     32}}}
     33
     34That 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
     36It 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{{{
     39self.log.debug("This is my plugin module")
     40}}}
     41
     42to the end of your {{{access.__init__(self, config, auth)}}} member.
     43
     44
     45To 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
     52If 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{{{
     55module_path: /usr/home/faber/plugins
     56access_type: plug
     57}}}
     58
     59Run fedd with your modified configuration after '''--config''' and with '''--debug''' to see your log message:
     60
     61{{{
     62fedd.py --config=/home/faber/fedd/fedd.config --debug
     63}}}
     64
     65and you should see something like:
     66
     67{{{
     6829 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'
     6929 Jun 10 19:33:29 fedd.access This is my plugin module
     70}}}