From: Thierry Parmentelat Date: Tue, 7 Feb 2012 11:29:21 +0000 (+0100) Subject: first draft for the federica driver X-Git-Tag: sfa-2.1-2~4 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=d8782631d2609a4e86bc381dea2862728a0b0a8a first draft for the federica driver --- diff --git a/sfa/federica/__init__.py b/sfa/federica/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sfa/federica/fddriver.py b/sfa/federica/fddriver.py new file mode 100644 index 00000000..bfd48276 --- /dev/null +++ b/sfa/federica/fddriver.py @@ -0,0 +1,82 @@ +from sfa.util.sfalogging import logger + +# this is probably too big to swallow but for a starting point.. +from sfa.plc.pldriver import PlDriver + +from sfa.fd.fdshell import FdShell + +# hardwired for now +# this could/should be obtained by issuing getRSpecVersion +federica_version_string="RSpecV2" + +class FdDriver (PlDriver): + + def __init__ (self,config): + PlDriver.__init__ (self, config) + self.shell=FdShell(config) + + def aggregate_version (self): + return { 'federica_version_string' : federica_version_string, } + + def testbed_name (self): + return "federica" + + def list_slices (self, creds, options): + return self.shell.listSlices() + + def sliver_status (self, slice_urn, slice_hrn): + return "fddriver.sliver_status: undefined/todo for slice %s"%slice_hrn + + def list_resources (self, slice_urn, slice_hrn, creds, options): + # right now rspec_version is ignored on the federica side + # we normally derive it from options + # look in cache if client has requested so + cached_requested = options.get('cached', True) + # global advertisement + if not slice_hrn: + # self.cache is initialized unless the global config has it turned off + if cached_requested and self.cache: + rspec = self.cache.get(federica_version_string) + if rspec: + logger.debug("FdDriver.ListResources: returning cached advertisement") + return rspec + # otherwise, need to get it + rspec = self.shell.listAvailableResources (federica_version_string) + # cache it for future use + if self.cache: + logger.debug("FdDriver.ListResources: stores advertisement in cache") + self.cache.add(federica_version_string, rspec) + return rspec + # about a given slice : don't cache + else: +# that's what the final version would look like + return self.shell.listSliceResources(federica_version_string, slice_urn) +# # just to see how the ad shows up in sface +# # caching it for convenience as it's the ad anyways +# if cached_requested and self.cache: +# rspec = self.cache.get(federica_version_string) +# if rspec: +# logger.debug("FdDriver.ListResources: returning cached advertisement") +# return rspec +# +# return self.shell.listAvailableResources(federica_version_string) + +#String createSlice(String credentials, String sliceUrn, String rspecVersion, String rspecString): + def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options): + # right now version_string is ignored on the federica side + # we normally derive it from options + return self.shell.createSlice(creds, slice_urn, federica_version_string, rspec_string) + +#String deleteSlice(String credentials, String rspecVersion, String sliceUrn): + def delete_sliver (self, slice_urn, slice_hrn, creds, options): + # right now version_string is ignored on the federica side + # we normally derive it from options + # xxx not sure if that's currentl supported at all + return self.shell.deleteSlice(creds, federica_version_string, slice_urn) + + # for the the following methods we use what is provided by the default driver class + #def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options): + #def start_slice (self, slice_urn, slice_xrn, creds): + #def stop_slice (self, slice_urn, slice_xrn, creds): + #def reset_slice (self, slice_urn, slice_xrn, creds): + #def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options): diff --git a/sfa/federica/fdshell.py b/sfa/federica/fdshell.py new file mode 100644 index 00000000..d362c7fd --- /dev/null +++ b/sfa/federica/fdshell.py @@ -0,0 +1,43 @@ +import xmlrpclib + +from sfa.util.sfalogging import logger + +class FdShell: + """ + A simple xmlrpc shell to a federica API server + This class can receive the XMLRPC calls to the federica testbed + For safety this is limited to a set of hard-coded calls + """ + + direct_calls = [ 'listAvailableResources', + 'listSliceResources', + 'createSlice', + 'deleteSlice', + ] + + def __init__ ( self, config ) : + # xxx to be configurable + SFA_FEDERICA_URL = "http://%s:%s@%s:%s/"%\ + (config.SFA_FEDERICA_USER,config.SFA_FEDERICA_PASSWORD, + config.SFA_FEDERICA_HOSTNAME,config.SFA_FEDERICA_PORT) + url=SFA_FEDERICA_URL + # xxx not sure if java xmlrpc has support for None + # self.proxy = xmlrpclib.Server(url, verbose = False, allow_none = True) + # xxx turn on verbosity + self.proxy = xmlrpclib.Server(url, verbose = True) + + def __getattr__(self, name): + def func(*args, **kwds): + if name not in FdShell.direct_calls: + raise Exception, "Illegal method call %s for FEDERICA driver"%(name) + # xxx get credentials from the config ? + # right now basic auth data goes into the URL + # the API still provides for a first credential arg though + credential='xxx-unused-xxx' + logger.info("Issuing %s args=%s kwds=%s to federica"%\ + (name,args,kwds)) + result=getattr(self.proxy, "AggregateManager.%s"%name)(credential, *args, **kwds) + logger.debug('FdShell %s (%s) returned ... '%(name,name)) + return result + return func + diff --git a/sfa/generic/fd.py b/sfa/generic/fd.py new file mode 100644 index 00000000..2ba52fd0 --- /dev/null +++ b/sfa/generic/fd.py @@ -0,0 +1,11 @@ +# +from sfa.generic.pl import pl + +import sfa.federica.fddriver + +class fd (pl): + +# the max flavour behaves like pl, except for +# the aggregate + def driver_class (self) : + return sfa.federica.fddriver.FdDriver