ec47e41b1000c2cb16542a97c259bdd0e4a7b983
[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.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         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
26               Parameter(list, "List of Human readable names ([hrn])")),
27         Mixed(Parameter(str, "Credential string"),
28               Parameter(list, "List of credentials)"))  
29         ]
30
31     returns = [SfaRecord]
32     
33     def call(self, xrns, creds):
34         if not isinstance(xrns, types.ListType):
35             xrns=[xrns]
36         hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
37         
38         #find valid credentials
39         valid_creds = self.api.auth.checkCredentials(creds, 'resolve')
40
41         #log the call
42         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
43         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
44  
45         # send the call to the right manager
46         manager = self.api.get_interface_manager()
47         return manager.resolve(self.api, xrns)
48
49
50