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.genitable import GeniTable
10 from sfa.util.debug import log
11 from sfa.server.registry import Registries
12 from sfa.util.prefixTree import prefixTree
14 class resolve(Method):
18 @param cred credential string authorizing the caller
19 @param hrn human readable name to resolve
20 @return a list of record dictionaries or empty list
23 interfaces = ['registry']
26 Parameter(str, "Credential string"),
27 Parameter(str, "Human readable name (hrn)")
30 returns = [GeniRecord]
32 def call(self, cred, hrn):
34 self.api.auth.check(cred, 'resolve')
37 # load all know registry names into a prefix tree and attempt to find
38 # the longest matching prefix
39 registries = Registries(self.api)
40 hrns = registries.keys()
43 registry_hrn = tree.best_match(hrn)
45 #if there was no match then this record belongs to an unknow registry
47 raise MissingAuthority(hrn)
49 # if the best match (longest matching hrn) is not the local registry,
51 if registry_hrn != self.api.hrn:
52 credential = self.api.getCredential()
54 records = registries[registry_hrn].resolve(credential, hrn)
55 good_records = [record.as_dict() for record in records]
61 # if we still havnt found the record yet, try the local registry
63 records = table.find(hrn)
65 raise RecordNotFound(hrn)
66 for record in records:
68 self.api.fill_record_info(record)
69 good_records.append(dict(record))
70 except PlanetLabRecordDoesNotExist:
71 # silently drop the ones that are missing in PL
72 print >> log, "ignoring geni record ", record.get_name(), \
73 " because pl record does not exist"