minor bug
[sfa.git] / sfa / methods / get_slices.py
1 ### $Id$
2 ### $URL$
3
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.plc.slices import Slices
9 from sfa.trust.credential import Credential
10
11 class get_slices(Method):
12     """
13     Get a list of instantiated slices at this authority.      
14
15     @param cred credential string specifying the rights of the caller
16     @return list of human readable slice names (hrn).  
17     """
18
19     interfaces = ['aggregate', 'slicemgr', 'component']
20     
21     accepts = [
22         Parameter(str, "Credential string"),
23         Mixed(Parameter(str, "Human readable name of the original caller"),
24               Parameter(None, "Origin hrn not specified"))
25         ]
26
27     returns = [Parameter(str, "Human readable slice name (hrn)")]
28     
29     def call(self, cred, origin_hrn=None):
30         user_cred = Credential(string=cred)
31         #log the call
32         if not origin_hrn:
33             origin_hrn = user_cred.get_gid_caller().get_hrn()
34         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, None, self.name))
35
36         # validate the cred
37         self.api.auth.check(cred, 'listslices')
38
39         slices = []
40         # send the call to the right manager 
41         manager_base = 'sfa.managers'
42         if self.api.interface in ['component']:
43             mgr_type = self.api.config.SFA_CM_TYPE
44             manager_module = manager_base + ".component_manager_%s" % mgr_type
45             manager = __import__(manager_module, fromlist=[manager_base])
46             slices = manager.get_slices(self.api)
47         elif self.api.interface in ['aggregate']:
48             mgr_type = self.api.config.SFA_AGGREGATE_TYPE
49             manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
50             manager = __import__(manager_module, fromlist=[manager_base])
51             slices = manager.get_slices(self.api)
52         elif self.api.interface in ['slicemgr']:
53             mgr_type = self.api.config.SFA_SM_TYPE
54             manager_module = manager_base + ".slice_manager_%s" % mgr_type
55             manager = __import__(manager_module, fromlist=[manager_base])
56             slices = manager.get_slices(self.api)
57
58         return slices