first draft for the federica driver
[sfa.git] / sfa / federica / fddriver.py
1 from sfa.util.sfalogging import logger
2
3 # this is probably too big to swallow but for a starting point..
4 from sfa.plc.pldriver import PlDriver
5
6 from sfa.fd.fdshell import FdShell
7
8 # hardwired for now
9 # this could/should be obtained by issuing getRSpecVersion
10 federica_version_string="RSpecV2"
11
12 class FdDriver (PlDriver):
13
14     def __init__ (self,config): 
15         PlDriver.__init__ (self, config)
16         self.shell=FdShell(config)
17
18     def aggregate_version (self):
19         return { 'federica_version_string' : federica_version_string, }
20
21     def testbed_name (self):
22         return "federica"
23
24     def list_slices (self, creds, options):
25         return self.shell.listSlices()
26
27     def sliver_status (self, slice_urn, slice_hrn):
28         return "fddriver.sliver_status: undefined/todo for slice %s"%slice_hrn
29
30     def list_resources (self, slice_urn, slice_hrn, creds, options):
31         # right now rspec_version is ignored on the federica side
32         # we normally derive it from options
33         # look in cache if client has requested so
34         cached_requested = options.get('cached', True) 
35         # global advertisement
36         if not slice_hrn:
37             # self.cache is initialized unless the global config has it turned off
38             if cached_requested and self.cache:
39                 rspec = self.cache.get(federica_version_string)
40                 if rspec:
41                     logger.debug("FdDriver.ListResources: returning cached advertisement")
42                     return rspec 
43             # otherwise, need to get it
44             rspec = self.shell.listAvailableResources (federica_version_string)
45             # cache it for future use
46             if self.cache:
47                 logger.debug("FdDriver.ListResources: stores advertisement in cache")
48                 self.cache.add(federica_version_string, rspec)
49             return rspec
50         # about a given slice : don't cache
51         else:
52 # that's what the final version would look like
53             return self.shell.listSliceResources(federica_version_string, slice_urn)
54 # # just to see how the ad shows up in sface
55 # # caching it for convenience as it's the ad anyways
56 #             if cached_requested and self.cache:
57 #                 rspec = self.cache.get(federica_version_string)
58 #                 if rspec:
59 #                     logger.debug("FdDriver.ListResources: returning cached advertisement")
60 #                     return rspec 
61 #             
62 #             return self.shell.listAvailableResources(federica_version_string)
63
64 #String createSlice(String credentials, String sliceUrn, String rspecVersion, String rspecString):
65     def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
66         # right now version_string is ignored on the federica side
67         # we normally derive it from options
68         return  self.shell.createSlice(creds, slice_urn, federica_version_string, rspec_string)
69
70 #String deleteSlice(String credentials, String rspecVersion, String sliceUrn):
71     def delete_sliver (self, slice_urn, slice_hrn, creds, options):
72         # right now version_string is ignored on the federica side
73         # we normally derive it from options
74         # xxx not sure if that's currentl supported at all
75         return self.shell.deleteSlice(creds, federica_version_string, slice_urn)
76
77     # for the the following methods we use what is provided by the default driver class
78     #def renew_sliver (self, slice_urn, slice_hrn, creds, expiration_time, options):
79     #def start_slice (self, slice_urn, slice_xrn, creds):
80     #def stop_slice (self, slice_urn, slice_xrn, creds):
81     #def reset_slice (self, slice_urn, slice_xrn, creds):
82     #def get_ticket (self, slice_urn, slice_xrn, creds, rspec, options):