Last bit of code injection that hits the mainline (not max, not vini) code path
[sfa.git] / sfa / methods / create_slice.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 # RSpecManager_pl is not used. This is just to resolve issues with the dynamic __import__ that comes later.
11 import sfa.rspecs.aggregates.rspec_manager_pl
12
13
14 class create_slice(Method):
15     """
16     Instantiate the specified slice according to whats defined in the specified rspec      
17
18     @param cred credential string specifying the rights of the caller
19     @param hrn human readable name of slice to instantiate
20     @param rspec resource specification
21     @return 1 is successful, faults otherwise  
22     """
23
24     interfaces = ['aggregate', 'slicemgr']
25     
26     accepts = [
27         Parameter(str, "Credential string"),
28         Parameter(str, "Human readable name of slice to instantiate"),
29         Parameter(str, "Resource specification"),
30         ]
31
32     returns = Parameter(int, "1 if successful")
33     
34     def call(self, cred, hrn, rspec):
35         sfa_aggregate_type = Config().get_aggregate_rspec_type()
36         if (sfa_aggregate_type == 'pl'):
37             self.api.auth.check(cred, 'createslice')
38             slices = Slices(self.api)
39             slices.create_slice(hrn, rspec)    
40         else:
41             # To clean up after July 21 - SB    
42             rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type)
43             rspec = rspec_manager.create_slice(hrn, rspec)
44         
45         return 1