use self.get_auth_info
[sfa.git] / sfa / methods / resolve.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.util.auth import Auth
8 from sfa.util.record import GeniRecord
9 from sfa.util.debug import log
10
11 from sfa.server.registry import Registries
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
19     @return a list of record dictionaries or empty list     
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Parameter(str, "Credential string"),
26         Parameter(str, "Human readable name (hrn)")
27         ]
28
29     returns = [GeniRecord]
30     
31     def call(self, cred, hrn):
32         
33         self.api.auth.check(cred, 'resolve')
34         good_records = [] 
35         try:
36             auth_hrn = self.api.auth.get_authority(hrn)
37             if not auth_hrn:
38                 auth_hrn = hrn
39             table = self.api.auth.get_auth_table(auth_hrn)
40             records = table.resolve('*', hrn)
41             if not records:
42                 raise RecordNotFound(hrn) 
43             good_records = []
44             for record in records:
45                 try:
46                     self.api.fill_record_info(record)
47                     good_records.append(record)
48                 except PlanetLabRecordDoesNotExist:
49                     # silently drop the ones that are missing in PL
50                     print >> log, "ignoring geni record ", record.get_name(), \
51                               " because pl record does not exist"
52                     table.remove(record)
53         except:
54             # is this a foreign record
55             registries = Registries(self.api)
56             credential = self.api.getCredential()
57             for registry in registries:
58                 if hrn.startswith(registry) and not registry in [self.api.hrn]:
59                     records = registries[registry].resolve(credential, hrn)
60                     good_records = records
61         dicts = [record.as_dict() for record in good_records]
62
63         return dicts    
64