X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=blobdiff_plain;f=sfa%2Fmethods%2FResolve.py;h=39618a731377379a71cf616b87de0245217b1c01;hp=03c40fabb8134f3fce38727d74a41c6ac5e739a9;hb=fd395e1944dcd49f10a4d5b27ce4983ad389fb96;hpb=680d4fc1af88ed631f820545216bee6e7a698f39 diff --git a/sfa/methods/Resolve.py b/sfa/methods/Resolve.py index 03c40fab..39618a73 100644 --- a/sfa/methods/Resolve.py +++ b/sfa/methods/Resolve.py @@ -1,50 +1,57 @@ -### $Id: resolve.py 17157 2010-02-21 04:19:34Z tmack $ -### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/resolve.py $ -import traceback -import types -from sfa.util.faults import * -from sfa.util.namespace import * +from sfa.util.xrn import Xrn, urn_to_hrn from sfa.util.method import Method -from sfa.util.parameter import Parameter, Mixed -from sfa.util.debug import log +from sfa.util.sfalogging import logger + from sfa.trust.credential import Credential -from sfa.util.record import SfaRecord + +from sfa.storage.parameter import Parameter, Mixed + class Resolve(Method): """ Resolve a record. @param cred credential string authorizing the caller - @param hrn human readable name to resolve (hrn or urn) - @return a list of record dictionaries or empty list + @param hrn human readable name to resolve (hrn or urn) + @return a list of record dictionaries or empty list """ interfaces = ['registry'] - + + # should we not accept an optional 'details' argument ? accepts = [ Mixed(Parameter(str, "Human readable name (hrn or urn)"), Parameter(list, "List of Human readable names ([hrn])")), Mixed(Parameter(str, "Credential string"), - Parameter(list, "List of credentials)")) - ] - - returns = [SfaRecord] - - def call(self, xrns, creds): - if not isinstance(xrns, types.ListType): - xrns=[xrns] + Parameter(list, "List of credentials)")), + Parameter(dict, "options"), + ] + + # xxx used to be [SfaRecord] + returns = [Parameter(dict, "registry record")] + + def call(self, xrns, creds, options=None): + if options is None: + options = {} + # use details=False by default, only when explicitly specified do we want + # to mess with the testbed details + if 'details' in options: + details = options['details'] + else: + details = False + type = None + if not isinstance(xrns, list): + type = Xrn(xrns).get_type() + xrns = [xrns] hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] - - #find valid credentials + # find valid credentials valid_creds = self.api.auth.checkCredentials(creds, 'resolve') - #log the call - origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() - self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name)) - - # send the call to the right manager - manager = self.api.get_interface_manager() - return manager.resolve(self.api, xrns, creds) - + # log the call + origin_hrn = Credential( + string=valid_creds[0]).get_gid_caller().get_hrn() + logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" % + (self.api.interface, origin_hrn, hrns, self.name)) - + # send the call to the right manager + return self.api.manager.Resolve(self.api, xrns, type, details=details)