a812c867cc52552c0d4bcfc478ec10d2b9c8b708
[sfa.git] / sfa / methods / List.py
1 ### $Id: list.py 16588 2010-01-13 17:53:44Z anil $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/list.py $
3
4 from sfa.util.faults import *
5 from sfa.util.namespace import urn_to_hrn
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.util.record import SfaRecord
9 from sfa.trust.credential import Credential
10
11 class List(Method):
12     """
13     List the records in an authority. 
14
15     @param cred credential string specifying the rights of the caller
16     @param hrn human readable name of authority to list (hrn or urn)
17     @return list of record dictionaries         
18     """
19     interfaces = ['registry']
20     
21     accepts = [
22         Parameter(str, "Human readable name (hrn or urn)"),
23         Mixed(Parameter(str, "Credential string"),
24               Parameter(type([str]), "List of credentials")),
25         ]
26
27     returns = [SfaRecord]
28     
29     def call(self, xrn, creds):
30         hrn, type = urn_to_hrn(xrn)
31         valid_creds = self.api.auth.checkCredentials(creds, 'list')
32
33         #log the call
34         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
35         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
36        
37         manager = self.api.get_interface_manager()
38         return manager.list(self.api, xrn)