1 from sfa.util.sfalogging import logger
2 from sfa.util.faults import SfaFault
4 # this is probably too big to swallow but for a starting point..
5 from sfa.plc.pldriver import PlDriver
7 from sfa.federica.fdshell import FdShell
10 # this could/should be obtained by issuing getRSpecVersion
11 federica_version_string="RSpecV2"
13 class FdDriver (PlDriver):
15 def __init__ (self,config):
16 PlDriver.__init__ (self, config)
17 self.shell=FdShell(config)
19 # the agreement with the federica driver is for them to expose results in a way
20 # compliant with the avpi v2 return code, i.e. a dict with 'code' 'value' 'output'
21 # essentially, either 'code'==0, then 'value' is set to the actual result
22 # otherwise, 'code' is set to an error code and 'output' holds an error message
23 def response (self, from_xmlrpc):
24 if isinstance (from_xmlrpc, dict) and 'code' in from_xmlrpc:
25 if from_xmlrpc['code']==0:
26 return from_xmlrpc['value']
28 raise SfaFault(from_xmlrpc['code'],from_xmlrpc['output'])
30 logger.warning("unexpected result from federica xmlrpc api")
33 def aggregate_version (self):
34 return { 'federica_version_string' : federica_version_string, }
36 def testbed_name (self):
39 def list_slices (self, creds, options):
40 return self.response(self.shell.listSlices())
42 def sliver_status (self, slice_urn, slice_hrn):
43 return "fddriver.sliver_status: undefined/todo for slice %s"%slice_hrn
45 def list_resources (self, slice_urn, slice_hrn, creds, options):
46 # right now rspec_version is ignored on the federica side
47 # we normally derive it from options
48 # look in cache if client has requested so
49 cached_requested = options.get('cached', True)
50 # global advertisement
52 # self.cache is initialized unless the global config has it turned off
53 if cached_requested and self.cache:
54 # using federica_version_string as the key into the cache
55 rspec = self.cache.get(federica_version_string)
57 logger.debug("FdDriver.ListResources: returning cached advertisement")
58 return self.response(rspec)
59 # otherwise, need to get it
60 rspec = self.shell.listAvailableResources (federica_version_string)
61 # cache it for future use
63 logger.debug("FdDriver.ListResources: stores advertisement in cache")
64 self.cache.add(federica_version_string, rspec)
65 return self.response(rspec)
66 # about a given slice : don't cache
68 # that's what the final version would look like
69 return self.response(self.shell.listSliceResources(federica_version_string, slice_urn))
70 # # just to see how the ad shows up in sface
71 # # caching it for convenience as it's the ad anyways
72 # if cached_requested and self.cache:
73 # rspec = self.cache.get(federica_version_string)
75 # logger.debug("FdDriver.ListResources: returning cached advertisement")
78 # return self.shell.listAvailableResources(federica_version_string)
80 #String createSlice(String credentials, String sliceUrn, String rspecVersion, String rspecString):
81 def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
82 # right now version_string is ignored on the federica side
83 # we normally derive it from options
84 return self.response(self.shell.createSlice(creds, slice_urn, federica_version_string, rspec_string))
86 #String deleteSlice(String credentials, String sliceUrn):
87 def delete_sliver (self, slice_urn, slice_hrn, creds, options):
88 # right now version_string is ignored on the federica side
89 # we normally derive it from options
90 # xxx not sure if that's currentl supported at all
91 return self.response(self.shell.deleteSlice(creds, slice_urn))
93 # for the the following methods we use what is provided by the default driver class
94 #def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
95 #def start_slice (self, slice_urn, slice_xrn, creds):
96 #def stop_slice (self, slice_urn, slice_xrn, creds):
97 #def reset_slice (self, slice_urn, slice_xrn, creds):
98 #def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):