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