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 from sfa.rspecs.rspec import RSpec
9 class CreateSliver(Method):
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.
16 @param slice_urn (string) URN of slice to allocate to
17 @param credentials ([string]) of credentials
18 @param rspec (string) rspec to allocate
21 interfaces = ['aggregate', 'slicemgr']
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 Parameter(str, "call_id"),
30 returns = Parameter(str, "Allocated RSpec")
32 def call(self, slice_xrn, creds, rspec, users, call_id=""):
33 hrn, type = urn_to_hrn(slice_xrn)
35 self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
37 # Find the valid credentials
38 valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
39 origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
41 # make sure users info is specified
43 msg = "'users' musst be specified and cannot be null. You may need to update your client."
44 raise SfaInvalidArgument(name='users', extra=msg)
46 # flter rspec through sfatables
47 if self.api.interface in ['aggregate']:
48 chain_name = 'INCOMING'
49 elif self.api.interface in ['slicemgr']:
50 chain_name = 'FORWARD-INCOMING'
51 self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
52 rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
53 slivers = RSpec(rspec).version.get_nodes_with_slivers()
55 result = self.api.manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id)