X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fgeneric%2F__init__.py;h=ece7e2b857317051f3aa769b82812a7e37eb0390;hb=597e216fce70183af63c50b99db2065cfa6e5e2d;hp=0f9043b2f848e2738f8cb7deed193f8f0c6f8049;hpb=81ec6a0c9ab0e8907af3a8d59fcb6f941aca400b;p=sfa.git diff --git a/sfa/generic/__init__.py b/sfa/generic/__init__.py index 0f9043b2..ece7e2b8 100644 --- a/sfa/generic/__init__.py +++ b/sfa/generic/__init__.py @@ -35,18 +35,22 @@ class Generic: #mixed = flavour.capitalize() module_path="sfa.generic.%s"%flavour classname="%s"%flavour - logger.info("Generic.the_flavour with flavour=%s"%flavour) + logger.debug("Generic.the_flavour with flavour=%s"%flavour) try: module = __import__ (module_path, globals(), locals(), [classname]) return getattr(module, classname)(flavour,config) except: logger.log_exc("Cannot locate generic instance with flavour=%s"%flavour) + # provide default for importer_class + def importer_class (self): + return None + # in the simplest case these can be redefined to the class/module objects to be used # see pl.py for an example # some descendant of SfaApi def api_class (self) : pass - # in practical terms these are modules for now + # the python classes to use to build up the context def registry_class (self) : pass def slicemgr_class (self) : pass def aggregate_class (self) : pass @@ -60,21 +64,21 @@ class Generic: if not 'interface' in kwargs: logger.critical("Generic.make_api: no interface found") api = self.api_class()(*args, **kwargs) - manager = self.make_manager(api.interface) - driver = self.make_driver (api.config, api.interface) + # xxx can probably drop support for managers implemented as modules + # which makes it a bit awkward + manager_class_or_module = self.make_manager(api.interface) + driver = self.make_driver (api) ### arrange stuff together # add a manager wrapper - manager = ManagerWrapper(manager,api.interface) - api.manager=manager - # insert driver in manager - manager.driver=driver - # add it in api as well for convenience + manager_wrap = ManagerWrapper(manager_class_or_module,api.interface,api.config) + api.manager=manager_wrap + # add it in api as well; driver.api is set too as part of make_driver api.driver=driver return api def make_manager (self, interface): """ - interface expected in ['registry', 'aggregate', 'slice', 'component'] + interface expected in ['registry', 'aggregate', 'slicemgr', 'component'] flavour is e.g. 'pl' or 'max' or whatever """ flavour = self.flavour @@ -82,14 +86,19 @@ class Generic: classname = "%s_manager_class"%interface try: - module = getattr(self,classname)() - logger.debug("%s : %s"%(message,module)) - return module + module_or_class = getattr(self,classname)() + logger.debug("%s : %s"%(message,module_or_class)) + # this gets passed to ManagerWrapper that will call the class constructor + # if it's a class, or use the module as is if it's a module + # so bottom line is, don't try the constructor here + return module_or_class except: logger.log_exc_critical(message) # need interface to select the right driver - def make_driver (self, config, interface): + def make_driver (self, api): + config=api.config + interface=api.interface flavour = self.flavour message="Generic.make_driver for flavour=%s and interface=%s"%(flavour,interface) @@ -100,8 +109,7 @@ class Generic: try: class_obj = getattr(self,classname)() logger.debug("%s : %s"%(message,class_obj)) - return class_obj(config) + return class_obj(api) except: logger.log_exc_critical(message) -