trimmed useless imports, unstarred all imports
[sfa.git] / sfa / methods / get_aggregates.py
1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.server.aggregate import Aggregates
5
6 class get_aggregates(Method):
7     """
8     Get a list of connection information for all known aggregates.      
9
10     @param cred credential string specifying the rights of the caller
11     @param a Human readable name (hrn or urn), or list of hrns or None
12     @return list of dictionaries with aggregate information.  
13     """
14
15     interfaces = ['registry', 'aggregate', 'slicemgr']
16     
17     accepts = [
18         Parameter(str, "Credential string"),
19         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
20               Parameter(None, "hrn not specified"))
21         ]
22
23     returns = [Parameter(dict, "Aggregate interface information")]
24     
25     def call(self, cred, xrn = None):
26         hrn, type = urn_to_hrn(xrn)
27         self.api.auth.check(cred, 'list')
28         aggregates = Aggregates(self.api).interfaces.values()
29         if hrn:
30             aggregates = [agg for agg in aggregates if agg['hrn'] == hrn]
31         return aggregates