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