3 from sfa.util.version import version_core
4 from sfa.util.xrn import Xrni
5 from sfa.util.sfatime import utcpase, adjust_datetime
6 from sfa.util.callids import Callids
7 from sfa.server.api_versions import ApiVersions
9 class AggregateManager:
11 def __init__ (self, config): pass
13 # essentially a union of the core version, the generic version (this code) and
14 # whatever the driver needs to expose
15 def GetVersion(self, api, options):
16 xrn=Xrn(api.hrn, type='authority+am')
17 version = version_core()
18 geni_api_versions = ApiVersions().get_versions()
19 geni_api_versions['2'] = 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)
21 'interface':'aggregate',
24 'geni_api_versions': geni_api_versions,
27 'geni_handles_speaksfor': True, # supports 'speaks for' credentials
29 version.update(version_generic)
30 testbed_version = self.driver.aggregate_version()
31 version.update(testbed_version)
34 def ListSlices(self, api, creds, options):
35 call_id = options.get('call_id')
36 if Callids().already_handled(call_id): return []
37 return self.driver.list_slices (creds, options)
39 def ListResources(self, api, creds, options):
40 call_id = options.get('call_id')
41 if Callids().already_handled(call_id): return ""
43 # get slice's hrn from options
44 slice_xrn = options.get('geni_slice_urn', None)
45 # pass None if no slice is specified
47 slice_hrn, slice_urn = None, None
50 slice_urn=xrn.get_urn()
51 slice_hrn=xrn.get_hrn()
52 return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
54 def SliverStatus (self, api, xrn, creds, options):
55 call_id = options.get('call_id')
56 if Callids().already_handled(call_id): return {}
58 xrn = Xrn(xrn,'slice')
59 slice_urn=xrn.get_urn()
60 slice_hrn=xrn.get_hrn()
61 return self.driver.sliver_status (slice_urn, slice_hrn)
63 def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
65 Create the sliver[s] (slice) at this aggregate.
66 Verify HRN and initialize the slice record in PLC if necessary.
68 call_id = options.get('call_id')
69 if Callids().already_handled(call_id): return ""
71 xrn = Xrn(xrn, 'slice')
72 slice_urn=xrn.get_urn()
73 slice_hrn=xrn.get_hrn()
75 return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
77 def DeleteSliver(self, api, xrn, creds, options):
78 call_id = options.get('call_id')
79 if Callids().already_handled(call_id): return True
81 xrn = Xrn(xrn, 'slice')
82 slice_urn=xrn.get_urn()
83 slice_hrn=xrn.get_hrn()
84 return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
86 def RenewSliver(self, api, xrn, creds, expiration_time, options):
87 call_id = options.get('call_id')
88 if Callids().already_handled(call_id): return True
90 xrn = Xrn(xrn, 'slice')
91 slice_urn=xrn.get_urn()
92 slice_hrn=xrn.get_hrn()
94 if options.get('geni_extend_alap'):
95 now = datetime.datetime.now()
96 requested = utcparse(expiration_time)
97 max = adjust_datetime(now, days=int(api.config.SFA_MAX_SLICE_RENEW))
101 return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
103 ### these methods could use an options extension for at least call_id
104 def start_slice(self, api, xrn, creds):
106 slice_urn=xrn.get_urn()
107 slice_hrn=xrn.get_hrn()
108 return self.driver.start_slice (slice_urn, slice_hrn, creds)
110 def stop_slice(self, api, xrn, creds):
112 slice_urn=xrn.get_urn()
113 slice_hrn=xrn.get_hrn()
114 return self.driver.stop_slice (slice_urn, slice_hrn, creds)
116 def reset_slice(self, api, xrn):
118 slice_urn=xrn.get_urn()
119 slice_hrn=xrn.get_hrn()
120 return self.driver.reset_slice (slice_urn, slice_hrn)
122 def GetTicket(self, api, xrn, creds, rspec, users, options):
125 slice_urn=xrn.get_urn()
126 slice_hrn=xrn.get_hrn()
128 # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish
129 # to pass 'users' over to the driver as well
130 return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)