-from copy import copy
-
-def get_version():
- version = {}
- version['geni_api'] = 1
- version['sfa'] = 1
- return version
-
-def slice_status(api, slice_xrn, creds ):
- hrn, type = urn_to_hrn(slice_xrn)
- # find out where this slice is currently running
- api.logger.info(hrn)
- slicename = hrn_to_pl_slicename(hrn)
- api.logger.info("Checking status for %s" % slicename)
- slices = api.plshell.GetSlices(api.plauth, [slicename], ['node_ids','person_ids','name','expires'])
- if len(slices) == 0:
- raise Exception("Slice %s not found (used %s as slicename internally)" % (slice_xrn, slicename))
- slice = slices[0]
-
- nodes = api.plshell.GetNodes(api.plauth, slice['node_ids'],
- ['hostname', 'boot_state', 'last_contact'])
- api.logger.info(slice)
- api.logger.info(nodes)
-
- result = {}
- result['geni_urn'] = slice_xrn
- result['geni_status'] = 'unknown'
- result['pl_login'] = slice['name']
- result['pl_expires'] = slice['expires']
-
- resources = []
-
- for node in nodes:
- res = {}
- res['pl_hostname'] = node['hostname']
- res['pl_boot_state'] = node['boot_state']
- res['pl_last_contact'] = node['last_contact']
- res['geni_urn'] = ''
- res['geni_status'] = 'unknown'
- res['geni_error'] = ''
-
- resources.append(res)
-
- result['geni_resources'] = resources
- return result
-
-def create_slice(api, xrn, creds, rspec, users):
- hrn, type = urn_to_hrn(xrn)
+from sfa.util.version import version_core
+from sfa.util.callids import Callids
+
+# we have specialized xmlrpclib.ServerProxy to remember the input url
+# OTOH it's not clear if we're only dealing with XMLRPCServerProxy instances
+def get_serverproxy_url (server):
+ try:
+ return server.url
+ except:
+ sfa_logger().warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
+ return server._ServerProxy__host + server._ServerProxy__handler
+
+def GetVersion(api):
+ # peers explicitly in aggregates.xml
+ peers =dict ([ (peername,get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems()
+ if peername != api.hrn])
+ xrn=Xrn (api.hrn)
+ supported_rspecs = [dict(pg_rspec_version), dict(sfa_rspec_version)]
+ version_more = {'interface':'slicemgr',
+ 'hrn' : xrn.get_hrn(),
+ 'urn' : xrn.get_urn(),
+ 'peers': peers,
+ 'request_rspec_versions': supported_rspecs,
+ 'ad_rspec_versions': supported_rspecs,
+ 'default_ad_rspec': dict(sfa_rspec_version)
+ }
+ sm_version=version_core(version_more)
+ # local aggregate if present needs to have localhost resolved
+ if api.hrn in api.aggregates:
+ local_am_url=get_serverproxy_url(api.aggregates[api.hrn])
+ sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
+ return sm_version
+
+def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
+
+ 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 ""