7c7a00eccb131fe5668293b6d5f0788b81c0838e
[sfa.git] / sfa / methods / CreateSliver.py
1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter, Mixed
5 from sfa.util.sfatablesRuntime import run_sfatables
6 import sys
7 from sfa.trust.credential import Credential
8
9 class CreateSliver(Method):
10     """
11     Allocate resources to a slice.  This operation is expected to
12     start the allocated resources asynchornously after the operation
13     has successfully completed.  Callers can check on the status of
14     the resources using SliverStatus.
15
16     @param slice_urn (string) URN of slice to allocate to
17     @param credentials ([string]) of credentials
18     @param rspec (string) rspec to allocate
19     
20     """
21     interfaces = ['aggregate', 'slicemgr']
22     accepts = [
23         Parameter(str, "Slice URN"),
24         Mixed(Parameter(str, "Credential string"),
25               Parameter(type([str]), "List of credentials")),
26         Parameter(str, "RSpec"),
27         Parameter(type([]), "List of user information")
28         ]
29     returns = Parameter(str, "Allocated RSpec")
30
31     def call(self, slice_xrn, creds, rspec, users):
32         hrn, type = urn_to_hrn(slice_xrn)
33
34         self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
35
36         # Find the valid credentials
37         valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
38         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
39
40         manager = self.api.get_interface_manager()
41         
42         # flter rspec through sfatables
43         if self.api.interface in ['aggregate']:
44             chain_name = 'INCOMING'
45         elif self.api.interface in ['slicemgr']:
46             chain_name = 'FORWARD-INCOMING'
47         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
48         allocated = manager.create_slice(self.api, slice_xrn, creds, rspec, users)
49
50         return rspec 
51