bugfix (aka oops, my bad)
[sfa.git] / sfa / methods / CreateSliver.py
1 from sfa.util.faults import SfaInvalidArgument
2 from sfa.util.xrn import urn_to_hrn
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter, Mixed
5 from sfa.util.sfatablesRuntime import run_sfatables
6 from sfa.trust.credential import Credential
7
8 class CreateSliver(Method):
9     """
10     Allocate resources to a slice.  This operation is expected to
11     start the allocated resources asynchornously after the operation
12     has successfully completed.  Callers can check on the status of
13     the resources using SliverStatus.
14
15     @param slice_urn (string) URN of slice to allocate to
16     @param credentials ([string]) of credentials
17     @param rspec (string) rspec to allocate
18     
19     """
20     interfaces = ['aggregate', 'slicemgr']
21     accepts = [
22         Parameter(str, "Slice URN"),
23         Mixed(Parameter(str, "Credential string"),
24               Parameter(type([str]), "List of credentials")),
25         Parameter(str, "RSpec"),
26         Parameter(type([]), "List of user information"),
27         Parameter(str, "call_id"),
28         ]
29     returns = Parameter(str, "Allocated RSpec")
30
31     def call(self, slice_xrn, creds, rspec, users, call_id=""):
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         # make sure users info is specified
41         if not users:
42             msg = "'users' musst be specified and cannot be null. You may need to update your client." 
43             raise SfaInvalidArgument(name='users', extra=msg)  
44
45         # flter rspec through sfatables
46         if self.api.interface in ['aggregate']:
47             chain_name = 'INCOMING'
48         elif self.api.interface in ['slicemgr']:
49             chain_name = 'FORWARD-INCOMING'
50         self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
51         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
52
53         return self.api.manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id)