from sfa.util.version import version_core
from sfa.util.xrn import Xrn
from sfa.util.callids import Callids
+from sfa.util.sfalogging import logger
class AggregateManager:
def ListSlices(self, api, creds, options):
call_id = options.get('call_id')
if Callids().already_handled(call_id): return []
+
+ # look in cache first
+ if self.driver.cache:
+ slices = self.driver.cache.get('slices')
+ if slices:
+ logger.debug("%s.list_slices returns from cache" % (self.driver.__module__))
+ return slices
+
+ # call driver
+ slices = self.driver.list_slices(creds, options)
+
+ # cache the result
+ if self.driver.cache:
+ logger.debug ("%s.list_slices stores value in cache" % (self.driver.__module__))
+ self.driver.cache.add('slices', instance_urns)
+
return self.driver.list_slices (creds, options)
def ListResources(self, api, creds, options):
call_id = options.get('call_id')
if Callids().already_handled(call_id): return ""
- # get slice's hrn from options
- slice_xrn = options.get('geni_slice_urn', None)
- # pass None if no slice is specified
- if not slice_xrn:
- slice_hrn, slice_urn = None, None
- else:
- xrn = Xrn(slice_xrn)
- slice_urn=xrn.get_urn()
- slice_hrn=xrn.get_hrn()
- return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
+ version_manager = VersionManager()
+ # get the rspec's return format from options
+ rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
+ version_string = "rspec_%s" % (rspec_version)
+
+ #panos adding the info option to the caching key (can be improved)
+ if options.get('info'):
+ version_string = version_string + "_"+options.get('info', 'default')
+
+ # Adding the list_leases option to the caching key
+ if options.get('list_leases'):
+ version_string = version_string + "_"+options.get('list_leases', 'default')
+
+ # Adding geni_available to caching key
+ if options.get('geni_available'):
+ version_string = version_string + "_" + str(options.get('geni_available'))
+
+ # look in cache first
+ cached_requested = options.get('cached', True)
+ if cached_requested and self.driver.cache and not slice_hrn:
+ rspec = self.driver.cache.get(version_string)
+ if rspec:
+ logger.debug("%s.ListResources returning cached advertisement" % (self.driver.__module__))
+ return rspec
+
+ rspec = self.driver.list_resources (creds, options)
+ if self.driver.cache:
+ logger.debug("%s.ListResources stores advertisement in cache" % (self.driver.__module__))
+ self.driver.cache.add(version_string, rspec)
+ return self.driver.list_resources (creds, options)
+
+ def Describe(self, api, creds, urns, options):
+ call_id = options.get('call_id')
+ if Callids().already_handled(call_id): return ""
+
+ return self.driver.describe (creds, urns, options)
+
def SliverStatus (self, api, xrn, creds, options):
call_id = options.get('call_id')
class ListResources(Method):
"""
- Returns information about available resources or resources allocated to this slice
+ Returns information about available resources
@param credential list
@param options dictionary
@return string
else:
raise SfaInvalidArgument('Must specify an rspec version option. geni_rspec_version cannot be null')
- # get slice's hrn from options
- xrn = options.get('geni_slice_urn', '')
- (hrn, _) = urn_to_hrn(xrn)
-
# Find the valid credentials
- valid_creds = self.api.auth.checkCredentials(creds, 'listnodes', hrn)
+ valid_creds = self.api.auth.checkCredentials(creds, 'listnodes')
# get hrn of the original caller
origin_hrn = options.get('origin_hrn', None)
elif self.api.interface in ['slicemgr']:
chain_name = 'FORWARD-OUTGOING'
self.api.logger.debug("ListResources: sfatables on chain %s"%chain_name)
- filtered_rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
+ filtered_rspec = run_sfatables(chain_name, '', origin_hrn, rspec)
if options.has_key('geni_compressed') and options['geni_compressed'] == True:
filtered_rspec = zlib.compress(filtered_rspec).encode('base64')
return {}
def list_slices (self, creds, options):
- # look in cache first
- if self.cache:
- slices = self.cache.get('slices')
- if slices:
- logger.debug("OpenStackDriver.list_slices returns from cache")
- return slices
-
# get data from db
instance_urns = []
instances = self.shell.nova_manager.servers.findall()
for instance in instances:
if instance.name not in instance_urns:
instance_urns.append(OSXrn(instance.name, type='slice').urn)
-
- # cache the result
- if self.cache:
- logger.debug ("OpenStackDriver.list_slices stores value in cache")
- self.cache.add('slices', instance_urns)
-
return instance_urns
# first 2 args are None in case of resource discovery
- def list_resources (self, slice_urn, slice_hrn, creds, options):
- cached_requested = options.get('cached', True)
-
- version_manager = VersionManager()
- # get the rspec's return format from options
- rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
- version_string = "rspec_%s" % (rspec_version)
-
- #panos adding the info option to the caching key (can be improved)
- if options.get('info'):
- version_string = version_string + "_"+options.get('info', 'default')
-
- # look in cache first
- if cached_requested and self.cache and not slice_hrn:
- rspec = self.cache.get(version_string)
- if rspec:
- logger.debug("OpenStackDriver.ListResources: returning cached advertisement")
- return rspec
-
- #panos: passing user-defined options
- #print "manager options = ",options
+ def list_resources (self, creds, options):
aggregate = OSAggregate(self)
- rspec = aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version,
- options=options)
-
- # cache the result
- if self.cache and not slice_hrn:
- logger.debug("OpenStackDriver.ListResources: stores advertisement in cache")
- self.cache.add(version_string, rspec)
-
+ rspec = aggregate.get_rspec(version=rspec_version, options=options)
return rspec
+
+ def describe(self, creds, urns, options):
+ return {}
def sliver_status (self, slice_urn, slice_hrn):
# find out where this slice is currently running
#
from sfa.util.faults import MissingSfaInfo, UnknownSfaType, \
RecordNotFound, SfaNotImplemented, SliverDoesNotExist
-
from sfa.util.sfalogging import logger
from sfa.util.defaultdict import defaultdict
from sfa.util.sfatime import utcparse, datetime_to_string, datetime_to_epoch
# used to be used in get_ticket
#from sfa.trust.sfaticket import SfaTicket
-
from sfa.rspecs.version_manager import VersionManager
from sfa.rspecs.rspec import RSpec
# the driver interface, mostly provides default behaviours
from sfa.managers.driver import Driver
-
from sfa.planetlab.plshell import PlShell
import sfa.planetlab.peers as peers
from sfa.planetlab.plaggregate import PlAggregate
return {}
def list_slices (self, creds, options):
- # look in cache first
- if self.cache:
- slices = self.cache.get('slices')
- if slices:
- logger.debug("PlDriver.list_slices returns from cache")
- return slices
-
# get data from db
slices = self.shell.GetSlices({'peer_id': None}, ['name'])
slice_hrns = [slicename_to_hrn(self.hrn, slice['name']) for slice in slices]
slice_urns = [hrn_to_urn(slice_hrn, 'slice') for slice_hrn in slice_hrns]
-
- # cache the result
- if self.cache:
- logger.debug ("PlDriver.list_slices stores value in cache")
- self.cache.add('slices', slice_urns)
-
return slice_urns
# first 2 args are None in case of resource discovery
- def list_resources (self, slice_urn, slice_hrn, creds, options):
- cached_requested = options.get('cached', True)
-
- version_manager = VersionManager()
- # get the rspec's return format from options
- rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
- version_string = "rspec_%s" % (rspec_version)
-
- #panos adding the info option to the caching key (can be improved)
- if options.get('info'):
- version_string = version_string + "_"+options.get('info', 'default')
-
- # Adding the list_leases option to the caching key
- if options.get('list_leases'):
- version_string = version_string + "_"+options.get('list_leases', 'default')
-
- # Adding geni_available to caching key
- if options.get('geni_available'):
- version_string = version_string + "_" + str(options.get('geni_available'))
-
- # look in cache first
- if cached_requested and self.cache and not slice_hrn:
- rspec = self.cache.get(version_string)
- if rspec:
- logger.debug("PlDriver.ListResources: returning cached advertisement")
- return rspec
-
- #panos: passing user-defined options
- #print "manager options = ",options
+ def list_resources (self, creds, options):
aggregate = PlAggregate(self)
- rspec = aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version,
- options=options)
-
- # cache the result
- if self.cache and not slice_hrn:
- logger.debug("PlDriver.ListResources: stores advertisement in cache")
- self.cache.add(version_string, rspec)
-
+ rspec = aggregate.get_rspec(version=rspec_version, options=options)
return rspec
+
+ def describe(self, creds, urns, options):
+ return {}
def sliver_status (self, slice_urn, slice_hrn):
# find out where this slice is currently running