66720d2cc1e5477922cf34bff47a76fa07d79626
[sfa.git] / sfa / methods / get_aggregates.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_aggregates.py $
3 from types import StringTypes
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.server.aggregate import Aggregates
9
10 class get_aggregates(Method):
11     """
12     Get a list of connection information for all known aggregates.      
13
14     @param cred credential string specifying the rights of the caller
15     @param a Human readable name (hrn), or list of hrns or None
16     @return list of dictionaries with aggregate information.  
17     """
18
19     interfaces = ['registry', 'aggregate', 'slicemgr']
20     
21     accepts = [
22         Parameter(str, "Credential string"),
23         Mixed(Parameter(str, "Human readable name (hrn)"),
24               Parameter(None, "hrn not specified"))
25         ]
26
27     returns = [Parameter(dict, "Aggregate interface information")]
28     
29     def call(self, cred, hrn = None):
30         self.api.auth.check(cred, 'list')
31         aggregates = Aggregates(self.api)
32         hrn_list = [] 
33         if hrn:
34             if isinstance(hrn, StringTypes):
35                 hrn_list = [hrn]
36             elif isinstance(hrn, list):
37                 hrn_list = hrn
38         
39         if not hrn_list:
40             interfaces = aggregates.interfaces
41         else:
42             interfaces = [interface for interface in aggregates.interfaces if interface['hrn'] in hrn_list]
43       
44         return interfaces