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
13 from sfa.trust.credential import Credential
15 class resolve(Method):
19 @param cred credential string authorizing the caller
20 @param hrn human readable name to resolve
21 @return a list of record dictionaries or empty list
24 interfaces = ['registry']
27 Parameter(str, "Credential string"),
28 Parameter(str, "Human readable name (hrn)"),
29 Mixed(Parameter(str, "Request hash"),
30 Parameter(None, "Request hash not specified"))
33 returns = [GeniRecord]
35 def call(self, cred, hrn, request_hash=None):
37 self.api.auth.authenticateCred(cred, [cred, hrn], request_hash)
38 self.api.auth.check(cred, 'resolve')
40 # load all know registry names into a prefix tree and attempt to find
41 # the longest matching prefix
43 registries = Registries(self.api)
44 hrns = registries.keys()
47 registry_hrn = tree.best_match(hrn)
49 #if there was no match then this record belongs to an unknow registry
51 raise MissingAuthority(hrn)
53 # if the best match (longest matching hrn) is not the local registry,
55 if registry_hrn != self.api.hrn:
56 credential = self.api.getCredential()
57 credential.set_gid_origin_caller(gid_origin_caller)
60 records = registries[registry_hrn].resolve(credential, hrn, request_hash)
61 good_records = [GeniRecord(dict=record).as_dict() for record in records]
63 arg_list = [credential, hrn]
64 request_hash=self.api.key.compute_hash(arg_list)
65 records = registries[registry_hrn].resolve(credential, hrn, request_hash)
66 good_records = [GeniRecord(dict=record).as_dict() for record in records]
71 # if we still havnt found the record yet, try the local registry
73 records = table.findObjects(hrn)
75 raise RecordNotFound(hrn)
76 for record in records:
78 self.api.fill_record_info(record)
79 good_records.append(dict(record))
80 except PlanetLabRecordDoesNotExist:
81 # silently drop the ones that are missing in PL
82 print >> log, "ignoring geni record ", record['hrn'], \
83 " because pl record does not exist"