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.sfatablesRuntime import run_sfatables
6 from sfa.trust.credential import Credential
8 from sfa.storage.parameter import Parameter, Mixed
10 from sfa.rspecs.rspec import RSpec
12 class CreateSliver(Method):
14 Allocate resources to a slice. This operation is expected to
15 start the allocated resources asynchornously after the operation
16 has successfully completed. Callers can check on the status of
17 the resources using SliverStatus.
19 @param slice_urn (string) URN of slice to allocate to
20 @param credentials ([string]) of credentials
21 @param rspec (string) rspec to allocate
24 interfaces = ['aggregate', 'slicemgr']
26 Parameter(str, "Slice URN"),
27 Mixed(Parameter(str, "Credential string"),
28 Parameter(type([str]), "List of credentials")),
29 Parameter(str, "RSpec"),
30 Parameter(type([]), "List of user information"),
31 Parameter(dict, "options"),
33 returns = Parameter(str, "Allocated RSpec")
35 def call(self, slice_xrn, creds, rspec, users, options={}):
36 hrn, type = urn_to_hrn(slice_xrn)
38 self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
40 # Find the valid credentials
41 valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
42 origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
44 # make sure users info is specified
46 msg = "'users' musst be specified and cannot be null. You may need to update your client."
47 raise SfaInvalidArgument(name='users', extra=msg)
49 # flter rspec through sfatables
50 if self.api.interface in ['aggregate']:
51 chain_name = 'INCOMING'
52 elif self.api.interface in ['slicemgr']:
53 chain_name = 'FORWARD-INCOMING'
54 self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
55 rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
56 slivers = RSpec(rspec).version.get_nodes_with_slivers()
58 result = self.api.manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, options)