namespace module is gone, plxrn provides PL-specific translations
[sfa.git] / sfa / methods / Resolve.py
1 ### $Id: resolve.py 17157 2010-02-21 04:19:34Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/resolve.py $
3 import traceback
4 import types
5 from sfa.util.faults import *
6 from sfa.util.xrn import urn_to_hrn
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.trust.credential import Credential
10 from sfa.util.record import SfaRecord
11
12 class Resolve(Method):
13     """
14     Resolve a record.
15
16     @param cred credential string authorizing the caller
17     @param hrn human readable name to resolve (hrn or urn) 
18     @return a list of record dictionaries or empty list     
19     """
20
21     interfaces = ['registry']
22     
23     accepts = [
24         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
25               Parameter(list, "List of Human readable names ([hrn])")),
26         Mixed(Parameter(str, "Credential string"),
27               Parameter(list, "List of credentials)"))  
28         ]
29
30     returns = [SfaRecord]
31     
32     def call(self, xrns, creds):
33         if not isinstance(xrns, types.ListType):
34             xrns=[xrns]
35         hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
36         
37         #find valid credentials
38         valid_creds = self.api.auth.checkCredentials(creds, 'resolve')
39
40         #log the call
41         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
42         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
43  
44         # send the call to the right manager
45         manager = self.api.get_interface_manager()
46         return manager.resolve(self.api, xrns)
47
48
49