merge from geni_api branch
[sfa.git] / sfa / methods / get_geni_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.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.aggregate import Aggregates
10
11 class get_geni_aggregates(Method):
12     """
13     Get a list of connection information for all known GENI aggregates.      
14
15     @param cred credential string specifying the rights of the caller
16     @param a Human readable name (hrn or urn), 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         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
25               Parameter(None, "hrn not specified"))
26         ]
27     
28
29     returns = [Parameter(dict, "Aggregate interface information")]
30     
31     def call(self, cred, xrn = None):
32         hrn, type = urn_to_hrn(xrn)
33         self.api.auth.check(cred, 'list')
34         
35         geni_aggs = Aggregates(self.api, '/etc/sfa/geni_aggregates.xml').interfaces
36         geni_aggs[self.api.hrn]['port'] = 12348
37         geni_aggs[self.api.hrn]['urn'] = 'http://%s:12348' % geni_aggs[self.api.hrn]['addr']
38         geni_aggs = geni_aggs.values()
39
40
41
42         hrn_list = [] 
43         if hrn:
44             if isinstance(hrn, StringTypes):
45                 hrn_list = [hrn]
46             elif isinstance(hrn, list):
47                 hrn_list = hrn
48         
49         if not hrn_list:
50             interfaces = geni_aggs
51         else:
52             interfaces = [interface for interface in geni_aggs if interface['hrn'] in hrn_list]
53
54         # Add urns
55         for interface in interfaces:
56             interface['urn'] = hrn_to_urn(interface['hrn'], 'authority')
57
58         return interfaces