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 'geni_request_rspec_versions': request_rspec_versions,
26 'geni_ad_rspec_versions': ad_rspec_versions,
29 def get_rspec_version_string(self, rspec_version, options={}):
30 version_string = "rspec_%s" % (rspec_version)
32 #panos adding the info option to the caching key (can be improved)
33 if options.get('info'):
34 version_string = version_string + "_"+options.get('info', 'default')
36 # Adding the list_leases option to the caching key
37 if options.get('list_leases'):
38 version_string = version_string + "_"+options.get('list_leases', 'default')
40 # Adding geni_available to caching key
41 if options.get('geni_available'):
42 version_string = version_string + "_" + str(options.get('geni_available'))
46 def GetVersion(self, api, options):
47 xrn=Xrn(api.hrn, type='authority')
48 version = version_core()
49 cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
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': cred_types,
62 version.update(version_generic)
63 version.update(self.rspec_versions())
64 testbed_version = self.driver.aggregate_version()
65 version.update(testbed_version)
68 def ListResources(self, api, creds, options):
69 call_id = options.get('call_id')
70 if Callids().already_handled(call_id): return ""
72 # get the rspec's return format from options
73 version_manager = VersionManager()
74 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
75 version_string = self.get_rspec_version_string(rspec_version, options)
78 cached_requested = options.get('cached', True)
79 if cached_requested and self.driver.cache:
80 rspec = self.driver.cache.get(version_string)
82 logger.debug("%s.ListResources returning cached advertisement" % (self.driver.__module__))
85 rspec = self.driver.list_resources (rspec_version, options)
87 logger.debug("%s.ListResources stores advertisement in cache" % (self.driver.__module__))
88 self.driver.cache.add(version_string, rspec)
91 def Describe(self, api, creds, urns, options):
92 call_id = options.get('call_id')
93 if Callids().already_handled(call_id): return ""
95 version_manager = VersionManager()
96 rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
97 return self.driver.describe(urns, rspec_version, options)
100 def Status (self, api, urns, creds, options):
101 call_id = options.get('call_id')
102 if Callids().already_handled(call_id): return {}
103 return self.driver.status (urns, options=options)
106 def Allocate(self, api, xrn, creds, rspec_string, options):
108 Allocate resources as described in a request RSpec argument
109 to a slice with the named URN.
111 call_id = options.get('call_id')
112 if Callids().already_handled(call_id): return ""
113 return self.driver.allocate(xrn, rspec_string, options)
115 def Provision(self, api, xrns, creds, options):
117 Create the sliver[s] (slice) at this aggregate.
118 Verify HRN and initialize the slice record in PLC if necessary.
120 call_id = options.get('call_id')
121 if Callids().already_handled(call_id): return ""
122 return self.driver.provision(xrns, options)
124 def Delete(self, api, xrns, creds, options):
125 call_id = options.get('call_id')
126 if Callids().already_handled(call_id): return True
127 return self.driver.delete(xrns, options)
129 def Renew(self, api, xrns, creds, expiration_time, options):
130 call_id = options.get('call_id')
131 if Callids().already_handled(call_id): return True
132 return self.driver.renew(xrns, expiration_time, options)
134 def PerformOperationalAction(self, api, xrns, creds, action, options={}):
135 call_id = options.get('call_id')
136 if Callids().already_handled(call_id): return True
137 return self.driver.perform_operational_action(xrns, action, options)
139 def Shutdown(self, api, xrn, creds, options={}):
140 call_id = options.get('call_id')
141 if Callids().already_handled(call_id): return True
142 return self.driver.shutdown(xrn, options)