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 get_rspec_version_string(self, rspec_version, options={}):
31 version_string = "rspec_%s" % (rspec_version)
33 #panos adding the info option to the caching key (can be improved)
34 if options.get('info'):
35 version_string = version_string + "_"+options.get('info', 'default')
37 # Adding the list_leases option to the caching key
38 if options.get('list_leases'):
39 version_string = version_string + "_"+options.get('list_leases', 'default')
41 # Adding geni_available to caching key
42 if options.get('geni_available'):
43 version_string = version_string + "_" + str(options.get('geni_available'))
47 def GetVersion(self, api, options):
49 version = version_core()
51 'testbed': self.driver.testbed_name(),
52 'interface':'aggregate',
56 'geni_api_versions': {'3': 'http://%s:%s' % (socket.gethostname(), api.config.sfa_aggregate_port)},
57 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
58 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
59 'geni_best_effort': 'true',
60 'geni_credential_types': [{
61 'geni_type': 'geni_sfa',
65 version.update(version_generic)
66 testbed_version = self.driver.aggregate_version()
67 version.update(testbed_version)
70 def ListSlices(self, api, creds, options):
71 call_id = options.get('call_id')
72 if Callids().already_handled(call_id): return []
76 slices = self.driver.cache.get('slices')
78 logger.debug("%s.list_slices returns from cache" % (self.driver.__module__))
82 slices = self.driver.list_slices(creds, options)
86 logger.debug ("%s.list_slices stores value in cache" % (self.driver.__module__))
87 self.driver.cache.add('slices', instance_urns)
89 return self.driver.list_slices (creds, options)
91 def ListResources(self, api, creds, options):
92 call_id = options.get('call_id')
93 if Callids().already_handled(call_id): return ""
95 # get the rspec's return format from options
96 version_manager = VersionManager()
97 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
98 version_string = self.get_rspec_version_string(rspec_version, options)
100 # look in cache first
101 cached_requested = options.get('cached', True)
102 if cached_requested and self.driver.cache and not slice_hrn:
103 rspec = self.driver.cache.get(version_string)
105 logger.debug("%s.ListResources returning cached advertisement" % (self.driver.__module__))
108 rspec = self.driver.list_resources (creds, version, options)
109 if self.driver.cache:
110 logger.debug("%s.ListResources stores advertisement in cache" % (self.driver.__module__))
111 self.driver.cache.add(version_string, rspec)
114 def Describe(self, api, creds, urns, options):
115 call_id = options.get('call_id')
116 if Callids().already_handled(call_id): return ""
118 # get the rspec's return format from options
119 version_manager = VersionManager()
120 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
121 return self.driver.describe(creds, urns, rspec, options)
124 def SliverStatus (self, api, xrn, creds, options):
125 call_id = options.get('call_id')
126 if Callids().already_handled(call_id): return {}
128 xrn = Xrn(xrn,'slice')
129 slice_urn=xrn.get_urn()
130 slice_hrn=xrn.get_hrn()
131 return self.driver.sliver_status (slice_urn, slice_hrn)
133 def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
135 Create the sliver[s] (slice) at this aggregate.
136 Verify HRN and initialize the slice record in PLC if necessary.
138 call_id = options.get('call_id')
139 if Callids().already_handled(call_id): return ""
141 xrn = Xrn(xrn, 'slice')
142 slice_urn=xrn.get_urn()
143 slice_hrn=xrn.get_hrn()
145 return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
147 def DeleteSliver(self, api, xrn, creds, options):
148 call_id = options.get('call_id')
149 if Callids().already_handled(call_id): return True
151 xrn = Xrn(xrn, 'slice')
152 slice_urn=xrn.get_urn()
153 slice_hrn=xrn.get_hrn()
154 return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
156 def RenewSliver(self, api, xrn, creds, expiration_time, options):
157 call_id = options.get('call_id')
158 if Callids().already_handled(call_id): return True
160 xrn = Xrn(xrn, 'slice')
161 slice_urn=xrn.get_urn()
162 slice_hrn=xrn.get_hrn()
163 return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
165 ### these methods could use an options extension for at least call_id
166 def start_slice(self, api, xrn, creds):
168 slice_urn=xrn.get_urn()
169 slice_hrn=xrn.get_hrn()
170 return self.driver.start_slice (slice_urn, slice_hrn, creds)
172 def stop_slice(self, api, xrn, creds):
174 slice_urn=xrn.get_urn()
175 slice_hrn=xrn.get_hrn()
176 return self.driver.stop_slice (slice_urn, slice_hrn, creds)
178 def reset_slice(self, api, xrn):
180 slice_urn=xrn.get_urn()
181 slice_hrn=xrn.get_hrn()
182 return self.driver.reset_slice (slice_urn, slice_hrn)
184 def GetTicket(self, api, xrn, creds, rspec, users, options):
187 slice_urn=xrn.get_urn()
188 slice_hrn=xrn.get_hrn()
190 return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)