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.planetlab.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 #### avail. methods on the federica side as of 2012/02/13
14 # listAvailableResources(String credentials, String rspecVersion)
15 # listSliceResources(String credentials, String rspecVersion, String sliceUrn)
16 # createSlice(String credentials, String sliceUrn, String rspecVersion, String rspecString)
17 # deleteSlice(String credentials, String sliceUrn)
21 # Result: {'code': 0, 'value': RSpec} if success
22 # {'code': code_id, 'output': Error message} if error
24 class FdDriver (PlDriver):
26 def __init__ (self,config):
27 PlDriver.__init__ (self, config)
28 self.shell=FdShell(config)
30 # the agreement with the federica driver is for them to expose results in a way
31 # compliant with the avpi v2 return code, i.e. a dict with 'code' 'value' 'output'
32 # essentially, either 'code'==0, then 'value' is set to the actual result
33 # otherwise, 'code' is set to an error code and 'output' holds an error message
34 def response (self, from_xmlrpc):
35 if isinstance (from_xmlrpc, dict) and 'code' in from_xmlrpc:
36 if from_xmlrpc['code']==0:
37 return from_xmlrpc['value']
39 raise SfaFault(from_xmlrpc['code'],from_xmlrpc['output'])
41 logger.warning("unexpected result from federica xmlrpc api")
44 def aggregate_version (self):
46 federica_version_string_api = self.response(self.shell.getRSpecVersion())
47 result ['federica_version_string_api']=federica_version_string_api
48 if federica_version_string_api != federica_version_string:
49 result['WARNING']="hard-wired rspec version %d differs from what the API currently exposes"%\
50 federica_version_string
53 def testbed_name (self):
56 def list_slices (self, creds, options):
57 return self.response(self.shell.listSlices())
59 def sliver_status (self, slice_urn, slice_hrn):
60 return "fddriver.sliver_status: undefined/todo for slice %s"%slice_hrn
62 def list_resources (self, slice_urn, slice_hrn, creds, options):
63 # right now rspec_version is ignored on the federica side
64 # we normally derive it from options
65 # look in cache if client has requested so
66 cached_requested = options.get('cached', True)
67 # global advertisement
69 # self.cache is initialized unless the global config has it turned off
70 if cached_requested and self.cache:
71 # using federica_version_string as the key into the cache
72 rspec = self.cache.get(federica_version_string)
74 logger.debug("FdDriver.ListResources: returning cached advertisement")
75 return self.response(rspec)
76 # otherwise, need to get it
77 # java code expects creds as a String
78 # rspec = self.shell.listAvailableResources (creds, federica_version_string)
79 rspec = self.shell.listAvailableResources ("", federica_version_string)
80 # rspec = self.shell.listAvailableResources (federica_version_string)
81 # cache it for future use
83 logger.debug("FdDriver.ListResources: stores advertisement in cache")
84 self.cache.add(federica_version_string, rspec)
85 return self.response(rspec)
86 # about a given slice : don't cache
88 # java code expects creds as a String
89 # return self.response(self.shell.listSliceResources(creds, federica_version_string, slice_urn))
90 return self.response(self.shell.listSliceResources("", federica_version_string, slice_urn))
92 def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
93 # right now version_string is ignored on the federica side
94 # we normally derive it from options
95 # java code expects creds as a String
96 # return self.response(self.shell.createSlice(creds, slice_urn, federica_version_string, rspec_string))
97 return self.response(self.shell.createSlice("", slice_urn, federica_version_string, rspec_string))
99 def delete_sliver (self, slice_urn, slice_hrn, creds, options):
100 # right now version_string is ignored on the federica side
101 # we normally derive it from options
102 # xxx not sure if that's currentl supported at all
103 # java code expects creds as a String
104 # return self.response(self.shell.deleteSlice(creds, slice_urn))
105 return self.response(self.shell.deleteSlice("", slice_urn))
107 # for the the following methods we use what is provided by the default driver class
108 #def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
109 #def start_slice (self, slice_urn, slice_xrn, creds):
110 #def stop_slice (self, slice_urn, slice_xrn, creds):
111 #def reset_slice (self, slice_urn, slice_xrn, creds):
112 #def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):