request hash argument is optional for now
[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.misc 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.aggregate import Aggregates
10
11 class get_aggregates(Method):
12     """
13     Get a list of connection information for all known aggregates.      
14
15     @param cred credential string specifying the rights of the caller
16     @param a Human readable name (hrn), or list of hrns 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         
25         Mixed(Parameter(str, "Human readable name (hrn)"),
26               Parameter(None, "hrn not specified")),
27         Mixed(Parameter(str, "Request hash"),
28               Parameter(None, "Request hash not specified"))
29         ]
30
31     returns = [Parameter(dict, "Aggregate interface information")]
32     
33     def call(self, cred, hrn = None, request_hash=None):
34         self.api.auth.authenticateCred(cred, [cred, hrn], request_hash) 
35         self.api.auth.check(cred, 'list')
36         aggregates = Aggregates(self.api)
37         hrn_list = [] 
38         if hrn:
39             if isinstance(hrn, StringTypes):
40                 hrn_list = [hrn]
41             elif isinstance(hrn, list):
42                 hrn_list = hrn
43         
44         if not hrn_list:
45             interfaces = aggregates.interfaces
46         else:
47             interfaces = [interface for interface in aggregates.interfaces if interface['hrn'] in hrn_list]
48       
49         return interfaces