4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.record import GeniRecord
9 from sfa.util.debug import log
10 from sfa.server.registry import Registries
11 from sfa.util.prefixTree import prefixTree
13 class resolve(Method):
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
22 interfaces = ['registry']
25 Parameter(str, "Credential string"),
26 Parameter(str, "Human readable name (hrn)")
29 returns = [GeniRecord]
31 def call(self, cred, hrn):
33 self.api.auth.check(cred, 'resolve')
36 # load all know registry names into a prefix tree and attempt to find
37 # the longest matching prefix
38 registries = Registries(self.api)
39 hrns = registries.keys()
42 registry_hrn = tree.best_match(hrn)
44 #if there was no match then this record belongs to an unknow registry
46 raise MissingAuthority(hrn)
48 # if the best match (longest matching hrn) is not the local registry,
50 if registry_hrn != self.api.hrn:
51 credential = self.api.getCredential()
53 records = registries[registry_hrn].resolve(credential, hrn)
54 good_records = [record.as_dict() for record in record_list]
60 # if we still havnt found the record yet, try the local registry
61 auth_hrn = self.api.auth.get_authority(hrn)
64 table = self.api.auth.get_auth_table(auth_hrn)
65 records = table.resolve('*', hrn)
67 raise RecordNotFound(hrn)
68 for record in records:
70 self.api.fill_record_info(record)
71 good_records.append(dict(record))
72 except PlanetLabRecordDoesNotExist:
74 # silently drop the ones that are missing in PL
75 print >> log, "ignoring geni record ", record.get_name(), \
76 " because pl record does not exist"