2 from sfa.rspecs.version_manager import VersionManager
3 from sfa.util.version import version_core
4 from sfa.util.xrn import Xrn
5 from sfa.util.callids import Callids
6 from sfa.util.sfalogging import logger
8 class AggregateManager:
10 def __init__ (self, config): pass
12 # essentially a union of the core version, the generic version (this code) and
13 # whatever the driver needs to expose
15 def _rspec_versions(self):
16 version_manager = VersionManager()
17 ad_rspec_versions = []
18 request_rspec_versions = []
19 for rspec_version in version_manager.versions:
20 if rspec_version.content_type in ['*', 'ad']:
21 ad_rspec_versions.append(rspec_version.to_dict())
22 if rspec_version.content_type in ['*', 'request']:
23 request_rspec_versions.append(rspec_version.to_dict())
25 'testbed':self.testbed_name(),
26 'geni_request_rspec_versions': request_rspec_versions,
27 'geni_ad_rspec_versions': ad_rspec_versions,
30 def GetVersion(self, api, options):
32 version = version_core()
34 'testbed': self.driver.testbed_name(),
35 'interface':'aggregate',
39 'geni_api_versions': {'3': 'http://%s:%s' % (socket.gethostname(), api.config.sfa_aggregate_port)},
40 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
41 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
42 'geni_best_effort': 'true',
43 'geni_credential_types': [{
44 'geni_type': 'geni_sfa',
48 version.update(version_generic)
49 testbed_version = self.driver.aggregate_version()
50 version.update(testbed_version)
53 def ListSlices(self, api, creds, options):
54 call_id = options.get('call_id')
55 if Callids().already_handled(call_id): return []
59 slices = self.driver.cache.get('slices')
61 logger.debug("%s.list_slices returns from cache" % (self.driver.__module__))
65 slices = self.driver.list_slices(creds, options)
69 logger.debug ("%s.list_slices stores value in cache" % (self.driver.__module__))
70 self.driver.cache.add('slices', instance_urns)
72 return self.driver.list_slices (creds, options)
74 def ListResources(self, api, creds, options):
75 call_id = options.get('call_id')
76 if Callids().already_handled(call_id): return ""
78 version_manager = VersionManager()
79 # get the rspec's return format from options
80 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
81 version_string = "rspec_%s" % (rspec_version)
83 #panos adding the info option to the caching key (can be improved)
84 if options.get('info'):
85 version_string = version_string + "_"+options.get('info', 'default')
87 # Adding the list_leases option to the caching key
88 if options.get('list_leases'):
89 version_string = version_string + "_"+options.get('list_leases', 'default')
91 # Adding geni_available to caching key
92 if options.get('geni_available'):
93 version_string = version_string + "_" + str(options.get('geni_available'))
96 cached_requested = options.get('cached', True)
97 if cached_requested and self.driver.cache and not slice_hrn:
98 rspec = self.driver.cache.get(version_string)
100 logger.debug("%s.ListResources returning cached advertisement" % (self.driver.__module__))
103 rspec = self.driver.list_resources (creds, options)
104 if self.driver.cache:
105 logger.debug("%s.ListResources stores advertisement in cache" % (self.driver.__module__))
106 self.driver.cache.add(version_string, rspec)
107 return self.driver.list_resources (creds, options)
109 def Describe(self, api, creds, urns, options):
110 call_id = options.get('call_id')
111 if Callids().already_handled(call_id): return ""
113 return self.driver.describe (creds, urns, options)
116 def SliverStatus (self, api, xrn, creds, options):
117 call_id = options.get('call_id')
118 if Callids().already_handled(call_id): return {}
120 xrn = Xrn(xrn,'slice')
121 slice_urn=xrn.get_urn()
122 slice_hrn=xrn.get_hrn()
123 return self.driver.sliver_status (slice_urn, slice_hrn)
125 def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
127 Create the sliver[s] (slice) at this aggregate.
128 Verify HRN and initialize the slice record in PLC if necessary.
130 call_id = options.get('call_id')
131 if Callids().already_handled(call_id): return ""
133 xrn = Xrn(xrn, 'slice')
134 slice_urn=xrn.get_urn()
135 slice_hrn=xrn.get_hrn()
137 return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
139 def DeleteSliver(self, api, xrn, creds, options):
140 call_id = options.get('call_id')
141 if Callids().already_handled(call_id): return True
143 xrn = Xrn(xrn, 'slice')
144 slice_urn=xrn.get_urn()
145 slice_hrn=xrn.get_hrn()
146 return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
148 def RenewSliver(self, api, xrn, creds, expiration_time, options):
149 call_id = options.get('call_id')
150 if Callids().already_handled(call_id): return True
152 xrn = Xrn(xrn, 'slice')
153 slice_urn=xrn.get_urn()
154 slice_hrn=xrn.get_hrn()
155 return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
157 ### these methods could use an options extension for at least call_id
158 def start_slice(self, api, xrn, creds):
160 slice_urn=xrn.get_urn()
161 slice_hrn=xrn.get_hrn()
162 return self.driver.start_slice (slice_urn, slice_hrn, creds)
164 def stop_slice(self, api, xrn, creds):
166 slice_urn=xrn.get_urn()
167 slice_hrn=xrn.get_hrn()
168 return self.driver.stop_slice (slice_urn, slice_hrn, creds)
170 def reset_slice(self, api, xrn):
172 slice_urn=xrn.get_urn()
173 slice_hrn=xrn.get_hrn()
174 return self.driver.reset_slice (slice_urn, slice_hrn)
176 def GetTicket(self, api, xrn, creds, rspec, users, options):
179 slice_urn=xrn.get_urn()
180 slice_hrn=xrn.get_hrn()
182 return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)