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
7 from sfa.util.faults import SfaInvalidArgument, InvalidRSpecVersion
8 from sfa.server.api_versions import ApiVersions
11 class AggregateManager:
13 def __init__ (self, config): pass
15 # essentially a union of the core version, the generic version (this code) and
16 # whatever the driver needs to expose
18 def rspec_versions(self):
19 version_manager = VersionManager()
20 ad_rspec_versions = []
21 request_rspec_versions = []
22 for rspec_version in version_manager.versions:
23 if rspec_version.content_type in ['*', 'ad']:
24 ad_rspec_versions.append(rspec_version.to_dict())
25 if rspec_version.content_type in ['*', 'request']:
26 request_rspec_versions.append(rspec_version.to_dict())
28 'geni_request_rspec_versions': request_rspec_versions,
29 'geni_ad_rspec_versions': ad_rspec_versions,
32 def get_rspec_version_string(self, rspec_version, options={}):
33 version_string = "rspec_%s" % (rspec_version)
35 #panos adding the info option to the caching key (can be improved)
36 if options.get('info'):
37 version_string = version_string + "_"+options.get('info', 'default')
39 # Adding the list_leases option to the caching key
40 if options.get('list_leases'):
41 version_string = version_string + "_"+options.get('list_leases', 'default')
43 # Adding geni_available to caching key
44 if options.get('geni_available'):
45 version_string = version_string + "_" + str(options.get('geni_available'))
49 def GetVersion(self, api, options):
50 xrn=Xrn(api.hrn, type='authority+am')
51 version = version_core()
52 cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
53 geni_api_versions = ApiVersions().get_versions()
54 geni_api_versions['3'] = 'http://%s:%s' % (api.config.sfa_aggregate_host, api.config.sfa_aggregate_port)
56 'testbed': api.driver.testbed_name(),
57 'interface':'aggregate',
62 'geni_api_versions': geni_api_versions,
63 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
64 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
65 'geni_credential_types': cred_types,
67 version.update(version_generic)
68 version.update(self.rspec_versions())
69 testbed_version = api.driver.aggregate_version()
70 version.update(testbed_version)
73 def ListResources(self, api, creds, options):
74 call_id = options.get('call_id')
75 if Callids().already_handled(call_id): return ""
77 # get the rspec's return format from options
78 version_manager = VersionManager()
79 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
80 version_string = self.get_rspec_version_string(rspec_version, options)
83 cached_requested = options.get('cached', True)
84 if cached_requested and api.driver.cache:
85 rspec = api.driver.cache.get(version_string)
87 logger.debug("%s.ListResources returning cached advertisement" % (api.driver.__module__))
90 rspec = api.driver.list_resources (rspec_version, options)
92 logger.debug("%s.ListResources stores advertisement in cache" % (api.driver.__module__))
93 api.driver.cache.add(version_string, rspec)
96 def Describe(self, api, creds, urns, options):
97 call_id = options.get('call_id')
98 if Callids().already_handled(call_id): return ""
100 version_manager = VersionManager()
101 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
102 return api.driver.describe(urns, rspec_version, options)
105 def Status (self, api, urns, creds, options):
106 call_id = options.get('call_id')
107 if Callids().already_handled(call_id): return {}
108 return api.driver.status (urns, options=options)
111 def Allocate(self, api, xrn, creds, rspec_string, expiration, options):
113 Allocate resources as described in a request RSpec argument
114 to a slice with the named URN.
116 call_id = options.get('call_id')
117 if Callids().already_handled(call_id): return ""
118 return api.driver.allocate(xrn, rspec_string, expiration, options)
120 def Provision(self, api, xrns, creds, options):
122 Create the sliver[s] (slice) at this aggregate.
123 Verify HRN and initialize the slice record in PLC if necessary.
125 call_id = options.get('call_id')
126 if Callids().already_handled(call_id): return ""
128 # make sure geni_rspec_version is specified in options
129 if 'geni_rspec_version' not in options:
130 msg = 'geni_rspec_version is required and must be set in options struct'
131 raise SfaInvalidArgument(msg, 'geni_rspec_version')
132 # make sure we support the requested rspec version
133 version_manager = VersionManager()
134 rspec_version = version_manager.get_version(options['geni_rspec_version'])
135 if not rspec_version:
136 raise InvalidRSpecVersion(options['geni_rspec_version'])
138 return api.driver.provision(xrns, options)
140 def Delete(self, api, xrns, creds, options):
141 call_id = options.get('call_id')
142 if Callids().already_handled(call_id): return True
143 return api.driver.delete(xrns, options)
145 def Renew(self, api, xrns, creds, expiration_time, options):
146 call_id = options.get('call_id')
147 if Callids().already_handled(call_id): return True
148 return api.driver.renew(xrns, expiration_time, options)
150 def PerformOperationalAction(self, api, xrns, creds, action, options={}):
151 call_id = options.get('call_id')
152 if Callids().already_handled(call_id): return True
153 return api.driver.perform_operational_action(xrns, action, options)
155 def Shutdown(self, api, xrn, creds, options={}):
156 call_id = options.get('call_id')
157 if Callids().already_handled(call_id): return True
158 return api.driver.shutdown(xrn, options)