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
5 from sfatables.runtime import SFATablesRules
7 from sfa.trust.credential import Credential
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 = ['geni_am']
23 Parameter(str, "Slice URN"),
24 Parameter(type([str]), "List of credentials"),
25 Parameter(str, "RSpec")
27 returns = Parameter(str, "Allocated RSpec")
29 def __run_sfatables(self, manager, rules, hrn, origin_hrn, rspec):
30 if rules.sorted_rule_list:
31 contexts = rules.contexts
32 request_context = manager.fetch_context(hrn, origin_hrn, contexts)
33 rules.set_context(request_context)
34 newrspec = rules.apply(rspec)
40 def call(self, slice_xrn, creds, rspec):
41 hrn, type = urn_to_hrn(slice_xrn)
43 self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
45 # Validate that at least one of the credentials is good enough
49 self.api.auth.check(cred, 'createslice')
50 origin_hrn = Credential(string=cred).get_gid_caller().get_hrn()
54 error = sys.exc_info()[:2]
58 raise InsufficientRights('CreateSliver: Access denied: %s -- %s' % (error[0],error[1]))
61 manager_base = 'sfa.managers'
63 if self.api.interface in ['geni_am']:
64 mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
65 manager_module = manager_base + ".geni_am_%s" % mgr_type
66 manager = __import__(manager_module, fromlist=[manager_base])
67 rspec = self.__run_sfatables(manager, SFATablesRules('INCOMING'),
68 hrn, origin_hrn, rspec)
69 return manager.CreateSliver(self.api, slice_xrn, creds, rspec)