from sfa.rspecs.sfa_rspec import SfaRSpec
from sfa.rspecs.rspec_converter import RSpecConverter
from sfa.rspecs.rspec_parser import parse_rspec
+from sfa.rspecs.rspec_version import RSpecVersion
+from sfa.rspecs.pl_rspec_version import supported_rspecs
from sfa.util.policy import Policy
from sfa.util.prefixTree import prefixTree
from sfa.util.sfaticket import *
import sfa.util.xmlrpcprotocol as xmlrpcprotocol
import sfa.plc.peers as peers
from sfa.util.version import version_core
-from sfa.rspecs.rspec_version import RSpecVersion
-from sfa.rspecs.pl_rspec_version import supported_rspecs
from sfa.util.callids import Callids
# we have specialized xmlrpclib.ServerProxy to remember the input url
def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
- def _CreateSliver(server, xrn, credentail, rspec, users, call_id):
- # get aggregate version
- version = server.GetVersion()
- if 'sfa' in version:
- # just send the whole rspec to SFA AM/SM
- server.CreateSliver(xrn, credential, rspec, users, call_id)
- elif 'geni_api' in version:
- pass
- # convert to pg rspec
+ def _CreateSliver(aggregate, xrn, credential, rspec, users, call_id):
+ # Need to call GetVersion at an aggregate to determine the supported
+ # rspec type/format beofre calling CreateSliver at an Aggregate.
+ # The Aggregate's verion info is cached
+ server = api.aggregates[aggregate]
+ # get cached aggregate version
+ aggregate_version_key = 'version_'+ aggregate
+ aggregate_version = api.cache.get(aggregate_version_key)
+ if not aggregate_version:
+ # get current aggregate version anc cache it for 24 hours
+ aggregate_version = server.GetVersion()
+ api.cache.add(aggregate_version_key, aggregate_version, 60 * 60 * 24)
+
+ if 'sfa' not in aggregate_version and 'geni_api' in aggregate_version:
+ # sfa aggregtes support both sfa and pg rspecs, no need to convert
+ # if aggregate supports sfa rspecs. othewise convert to pg rspec
+ rspec = RSpecConverter.to_pg_rspec(rspec)
+
+ return server.CreateSliver(xrn, credential, rspec, users, call_id)
if Callids().already_handled(call_id): return ""
continue
# Just send entire RSpec to each aggregate
- server = api.aggregates[aggregate]
- threads.run(_CreateSliver, server, xrn, credential, rspec.toxml(), users, call_id)
+ threads.run(_CreateSliver, aggregate, xrn, credential, rspec.toxml(), users, call_id)
results = threads.get_results()
rspec = SfaRSpec()