solve conflicts
[sfa.git] / sfa / generic / __init__.py
1 from sfa.util.sfalogging import logger
2 from sfa.util.config import Config
3 import traceback
4
5 # a bundle is the combination of 
6 # (*) an api that reacts on the incoming requests to trigger the API methods
7 # (*) a manager that implements the function of the service, 
8 #     either aggregate, registry, or slicemgr
9 # (*) a driver that controls the underlying testbed
10
11
12 # The Generic class is a utility that uses the configuration to figure out 
13 # which combination of these pieces need to be put together 
14 # from config.
15 # this extra indirection is needed to adapt to the current naming scheme
16 # where we have 'pl' and 'plc' and components and the like, that does not 
17 # yet follow a sensible scheme
18
19 # needs refinements to cache more efficiently, esp. wrt the config
20
21 class Generic:
22
23     def __init__ (self, config):
24         self.config=config
25
26     # proof of concept
27     # example flavour='pl' -> sfa.generic.pl.pl()
28     @staticmethod
29     def the_flavour (flavour=None, config=None):
30         if config is None: config=Config()
31         if flavour is None: flavour=config.SFA_GENERIC_FLAVOUR
32         flavour = flavour.lower()
33         #mixed = flavour.capitalize()
34         module_path="sfa.generic.%s"%flavour
35         classname="%s"%flavour
36         logger.info("Generic.the_flavour with flavour=%s"%flavour)
37         try:
38             module = __import__ (module_path, globals(), locals(), [classname])
39             return getattr(module, classname)(config)
40         except:
41             logger.log_exc("Cannot locate generic instance with flavour=%s"%flavour)
42
43
44     # how to build an API object
45     # default is to use api_class but can be redefined
46     def make_api (self, *args, **kwds):
47         return self.api_class()(*args, **kwds)