added slices call
[sfa.git] / geni / methods / slices.py
1 from geni.util.faults import *
2 from geni.util.excep import *
3 from geni.util.misc import *
4 from geni.util.method import Method
5 from geni.util.parameter import Parameter, Mixed
6 from geni.util.auth import Auth
7 from geni.aggregate import Aggregates
8
9 class slices(Method):
10     """
11     Get a list of instantiated slices at this authority.      
12
13     @param cred credential string specifying the rights of the caller
14     @return list of human readable slice names (hrn).  
15     """
16
17     interfaces = ['aggregate', 'slicemgr']
18     
19     accepts = [
20         Parameter(str, "Credential string"),
21         ]
22
23     returns = [Parameter(str, "Human readable slice name (hrn)")]
24     
25     def call(self, cred):
26        
27         self.api.auth.check(cred, 'listslices')
28         slice_hrns = []
29
30         if self.api.interface in ['aggregate']:
31             slices = self.api.plshell.GetSlices(self.api.plauth, {}, ['name'])
32             slice_hrns = [slicename_to_hrn(self.api.hrn, slice['name']) for slice in slices]
33         
34         else:
35             aggregates = Aggregates()
36             credential = self.api.getCredential()
37             for aggregate in aggregates:
38                 slices = aggregates[aggregate].slices(credential)
39                 slice_hrns.extend(slices)    
40             
41         return slice_hrns