added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / get_registries.py
1 ### $Id: get_slices.py 14387 2009-07-08 18:19:11Z faiyaza $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_registries.py $
3 from types import StringTypes
4 from sfa.util.faults import *
5 from sfa.util.namespace import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.auth import Auth
9 from sfa.server.registry import Registries
10
11 class get_registries(Method):
12     """
13     Get a list of connection information for all known registries.      
14
15     @param cred credential string specifying the rights of the caller
16     @param a Human readable name (hrn or urn), or list of names or None
17     @return list of dictionaries with aggregate information.  
18     """
19
20     interfaces = ['registry', 'aggregate', 'slicemgr']
21     
22     accepts = [
23         Parameter(str, "Credential string"),
24         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
25               Parameter(None, "hrn not specified"))
26         ]
27
28     returns = [Parameter(dict, "Registry interface information")]
29     
30     def call(self, cred, xrn = None):
31         hrn, type = urn_to_hrn(xrn)
32         self.api.auth.check(cred, 'list')
33         registries = Registries(self.api)
34         hrn_list = []
35         if hrn:
36             if isinstance(hrn, StringTypes):
37                 hrn_list = [hrn]
38             elif isinstance(hrn, list):
39                 hrn_list = hrn
40
41         if not hrn_list:
42             interfaces = registries.interfaces
43         else:
44             interfaces = [interface for interface in registries.interfaces if interface['hrn'] in hrn_list]
45
46         return interfaces