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
8 from sfa.util.sfalogging import logger
10 class CreateSliver(Method):
12 Allocate resources to a slice. This operation is expected to
13 start the allocated resources asynchornously after the operation
14 has successfully completed. Callers can check on the status of
15 the resources using SliverStatus.
17 @param slice_urn (string) URN of slice to allocate to
18 @param credentials ([string]) of credentials
19 @param rspec (string) rspec to allocate
22 interfaces = ['geni_am']
24 Parameter(str, "Slice URN"),
25 Parameter(type([str]), "List of credentials"),
26 Parameter(str, "RSpec"),
27 Parameter(type([]), "List of user information")
29 returns = Parameter(str, "Allocated RSpec")
31 def __run_sfatables(self, manager, rules, hrn, origin_hrn, rspec):
32 if rules.sorted_rule_list:
33 contexts = rules.contexts
34 request_context = manager.fetch_context(hrn, origin_hrn, contexts)
35 rules.set_context(request_context)
36 newrspec = rules.apply(rspec)
42 def call(self, slice_xrn, creds, rspec, users):
43 hrn, type = urn_to_hrn(slice_xrn)
45 self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
47 # Find the valid credentials
48 ValidCreds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
49 origin_hrn = Credential(string=ValidCreds[0]).get_gid_caller().get_hrn()
51 manager_base = 'sfa.managers'
53 if self.api.interface in ['geni_am']:
54 mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
55 manager_module = manager_base + ".geni_am_%s" % mgr_type
56 manager = __import__(manager_module, fromlist=[manager_base])
57 rspec = self.__run_sfatables(manager, SFATablesRules('INCOMING'),
58 hrn, origin_hrn, rspec)
60 return manager.CreateSliver(self.api, slice_xrn, ValidCreds, rspec, users)