-from sfa.util.faults import *
-from sfa.util.namespace import *
+from sfa.util.faults import SfaInvalidArgument, InvalidRSpec
+from sfa.util.xrn import urn_to_hrn
from sfa.util.method import Method
-from sfa.util.parameter import Parameter
-from sfatables.runtime import SFATablesRules
-import sys
+from sfa.util.sfatablesRuntime import run_sfatables
from sfa.trust.credential import Credential
-from sfa.util.sfalogging import logger
+from sfa.storage.parameter import Parameter, Mixed
+from sfa.rspecs.rspec import RSpec
class CreateSliver(Method):
"""
@param rspec (string) rspec to allocate
"""
- interfaces = ['geni_am']
+ interfaces = ['aggregate', 'slicemgr']
accepts = [
Parameter(str, "Slice URN"),
- Parameter(type([str]), "List of credentials"),
+ Mixed(Parameter(str, "Credential string"),
+ Parameter(type([str]), "List of credentials")),
Parameter(str, "RSpec"),
- Parameter(type([]), "List of user information")
+ Parameter(type([]), "List of user information"),
+ Parameter(dict, "options"),
]
returns = Parameter(str, "Allocated RSpec")
- def __run_sfatables(self, manager, rules, hrn, origin_hrn, rspec):
- if rules.sorted_rule_list:
- contexts = rules.contexts
- request_context = manager.fetch_context(hrn, origin_hrn, contexts)
- rules.set_context(request_context)
- newrspec = rules.apply(rspec)
- else:
- newrspec = rspec
- return newrspec
-
-
- def call(self, slice_xrn, creds, rspec, users):
+ def call(self, slice_xrn, creds, rspec, users, options):
hrn, type = urn_to_hrn(slice_xrn)
self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
# Find the valid credentials
- ValidCreds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
- origin_hrn = Credential(string=ValidCreds[0]).get_gid_caller().get_hrn()
-
- manager_base = 'sfa.managers'
-
- if self.api.interface in ['geni_am']:
- mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
- manager_module = manager_base + ".geni_am_%s" % mgr_type
- manager = __import__(manager_module, fromlist=[manager_base])
- rspec = self.__run_sfatables(manager, SFATablesRules('INCOMING'),
- hrn, origin_hrn, rspec)
-
- return manager.CreateSliver(self.api, slice_xrn, ValidCreds, rspec, users)
- return ''
-
+ valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', hrn)
+ origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
+
+ # make sure users info is specified
+ if not users:
+ msg = "'users' must be specified and cannot be null. You may need to update your client."
+ raise SfaInvalidArgument(name='users', extra=msg)
+
+ # flter rspec through sfatables
+ if self.api.interface in ['aggregate']:
+ chain_name = 'INCOMING'
+ elif self.api.interface in ['slicemgr']:
+ chain_name = 'FORWARD-INCOMING'
+ self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
+ rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
+ slivers = RSpec(rspec).version.get_nodes_with_slivers()
+ if not slivers:
+ raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers")
+ result = self.api.manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, options)
+ return result