getting resolve working across federated aggregates
[sfa.git] / sfa / methods / resolve.py
1 ### $Id$
2 ### $URL$
3 import traceback
4 import types
5 from sfa.util.faults import *
6 from sfa.util.namespace import *
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.util.debug import log
10 from sfa.trust.credential import Credential
11 from sfa.util.record import SfaRecord
12
13 class resolve(Method):
14     """
15     Resolve a record.
16
17     @param cred credential string authorizing the caller
18     @param hrn human readable name to resolve (hrn or urn) 
19     @return a list of record dictionaries or empty list     
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Parameter(str, "Credential string"),
26         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
27               Parameter(list, "List of Human readable names ([hrn])"))  
28         ]
29
30     returns = [SfaRecord]
31     
32     def call(self, cred, xrns, origin_hrn=None):
33         user_cred = Credential(string=cred)
34         if not isinstance(xrns, types.ListType):
35             xrns=[xrns]
36         hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
37
38         #log the call
39         if not origin_hrn:
40             origin_hrn = user_cred.get_gid_caller().get_hrn()
41         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
42  
43         # validate the cred
44         self.api.auth.check(cred, 'resolve')
45         # send the call to the right manager
46         manager_base = 'sfa.managers'
47         mgr_type = self.api.config.SFA_REGISTRY_TYPE
48         manager_module = manager_base + ".registry_manager_%s" % mgr_type
49         manager = __import__(manager_module, fromlist=[manager_base])
50         return manager.resolve(self.api, xrns, origin_hrn=origin_hrn)
51
52
53