X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2FsfatablesRuntime.py;h=d1a4e6cc80b5233fce8a409f1d29c279ea1f8e4c;hb=3d51e29695f79b143974f5cf7b2e104d89626ba4;hp=170fa880ea8f8dd8733daa7cf5b7346841bce30e;hpb=bc95bf33199bcaab75fc99908b0fcd35c83a9222;p=sfa.git diff --git a/sfa/util/sfatablesRuntime.py b/sfa/util/sfatablesRuntime.py index 170fa880..d1a4e6cc 100644 --- a/sfa/util/sfatablesRuntime.py +++ b/sfa/util/sfatablesRuntime.py @@ -1,36 +1,48 @@ -from sfatables.runtime import SFATablesRules +# sfa should not depend on sfatables +# if the sfatables.runtime import fails, just define run_sfatables as identity +import sys +try: + from sfatables.runtime import SFATablesRules -def fetch_context(slice_hrn, user_hrn, contexts): - """ - Returns the request context required by sfatables. At some point, this - mechanism should be changed to refer to "contexts", which is the - information that sfatables is requesting. But for now, we just return - the basic information needed in a dict. - """ - base_context = {'sfa':{'user':{'hrn':user_hrn}, 'slice':{'hrn':slice_hrn}}} - return base_context + def fetch_context(slice_hrn, user_hrn, contexts): + """ + Returns the request context required by sfatables. At some point, this + mechanism should be changed to refer to "contexts", which is the + information that sfatables is requesting. But for now, we just return + the basic information needed in a dict. + """ + base_context = {'sfa':{'user':{'hrn':user_hrn}, 'slice':{'hrn':slice_hrn}}} + return base_context -def run_sfatables(chain, hrn, origin_hrn, rspec, context_callback = None ): - """ - Run the rspec through sfatables - @param chain Name of rule chain - @param hrn Object's hrn - @param origin_hrn Original caller's hrn - @param rspec Incoming rspec - @param context_callback Callback used to generate the request context + def run_sfatables(chain, hrn, origin_hrn, rspec, context_callback = None ): + """ + Run the rspec through sfatables + @param chain Name of rule chain + @param hrn Object's hrn + @param origin_hrn Original caller's hrn + @param rspec Incoming rspec + @param context_callback Callback used to generate the request context + + @return rspec + """ + if not context_callback: + context_callback = fetch_context + + chain = chain.upper() + rules = SFATablesRules(chain) + print>>sys.stderr, " \r\n \r\n \t\t \t sfaTablesRuntime.py run_sfatables context_callback %s chain %s rules %s " %(context_callback,chain, rules ) + if rules.sorted_rule_list: + contexts = rules.contexts + request_context = context_callback(hrn, origin_hrn, contexts) + rules.set_context(request_context) + newrspec = rules.apply(rspec) + else: + newrspec = rspec + return newrspec - @return rspec - """ - if not context_callback: - context_callback = fetch_context - - chain = chain.upper() - rules = SFATablesRules(chain) - if rules.sorted_rule_list: - contexts = rules.contexts - request_context = context_callback(hrn, origin_hrn, contexts) - rules.set_context(request_context) - newrspec = rules.apply(rspec) - else: - newrspec = rspec - return newrspec +except: + + from sfa.util.sfalogging import logger + def run_sfatables (_,__,___, rspec, ____=None): + logger.warning("Cannot import sfatables.runtime, please install package sfa-sfatables") + return rspec