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
25 class FdDriver (PlDriver):
27 def __init__(self, api):
28 PlDriver.__init__(self, api)
30 self.shell = FdShell(config)
32 # the agreement with the federica driver is for them to expose results in a way
33 # compliant with the avpi v2 return code, i.e. a dict with 'code' 'value' 'output'
34 # essentially, either 'code'==0, then 'value' is set to the actual result
35 # otherwise, 'code' is set to an error code and 'output' holds an error
37 def response(self, from_xmlrpc):
38 if isinstance(from_xmlrpc, dict) and 'code' in from_xmlrpc:
39 if from_xmlrpc['code'] == 0:
40 return from_xmlrpc['value']
42 raise SfaFault(from_xmlrpc['code'], from_xmlrpc['output'])
44 logger.warning("unexpected result from federica xmlrpc api")
47 def aggregate_version(self):
49 federica_version_string_api = self.response(
50 self.shell.getRSpecVersion())
51 result['federica_version_string_api'] = federica_version_string_api
52 if federica_version_string_api != federica_version_string:
53 result['WARNING'] = "hard-wired rspec version %d differs from what the API currently exposes" %\
54 federica_version_string
57 def testbed_name(self):
60 def list_slices(self, creds, options):
61 # the issue is that federica returns the list of slice's urn in a string format
62 # this is why this dirty hack is needed until federica fixes it.
63 slices_str = self.shell.listSlices()['value'][1:-1]
64 slices_list = slices_str.split(", ")
67 def sliver_status(self, slice_urn, slice_hrn):
68 return "fddriver.sliver_status: undefined/todo for slice %s" % slice_hrn
70 def list_resources(self, slice_urn, slice_hrn, creds, options):
71 # right now rspec_version is ignored on the federica side
72 # we normally derive it from options
73 # look in cache if client has requested so
74 cached_requested = options.get('cached', True)
75 # global advertisement
77 # self.cache is initialized unless the global config has it turned
79 if cached_requested and self.cache:
80 # using federica_version_string as the key into the cache
81 rspec = self.cache.get(federica_version_string)
84 "FdDriver.ListResources: returning cached advertisement")
85 return self.response(rspec)
86 # otherwise, need to get it
87 # java code expects creds as a String
88 # rspec = self.shell.listAvailableResources (creds, federica_version_string)
89 rspec = self.shell.listAvailableResources(
90 "", federica_version_string)
91 # rspec = self.shell.listAvailableResources (federica_version_string)
92 # cache it for future use
95 "FdDriver.ListResources: stores advertisement in cache")
96 self.cache.add(federica_version_string, rspec)
97 return self.response(rspec)
98 # about a given slice : don't cache
100 # java code expects creds as a String
101 # return self.response(self.shell.listSliceResources(creds,
102 # federica_version_string, slice_urn))
103 return self.response(self.shell.listSliceResources("", federica_version_string, slice_urn))
105 def create_sliver(self, slice_urn, slice_hrn, creds, rspec_string, users, options):
106 # right now version_string is ignored on the federica side
107 # we normally derive it from options
108 # java code expects creds as a String
109 # return self.response(self.shell.createSlice(creds, slice_urn,
110 # federica_version_string, rspec_string))
111 return self.response(self.shell.createSlice("", slice_urn, federica_version_string, rspec_string))
113 def delete_sliver(self, slice_urn, slice_hrn, creds, options):
114 # right now version_string is ignored on the federica side
115 # we normally derive it from options
116 # xxx not sure if that's currentl supported at all
117 # java code expects creds as a String
118 # return self.response(self.shell.deleteSlice(creds, slice_urn))
119 return self.response(self.shell.deleteSlice("", slice_urn))
121 # for the the following methods we use what is provided by the default driver class
122 # def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
123 # def start_slice (self, slice_urn, slice_xrn, creds):
124 # def stop_slice (self, slice_urn, slice_xrn, creds):
125 # def reset_slice (self, slice_urn, slice_xrn, creds):
126 # def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):