better support for reporting available api versions
[sfa.git] / sfa / managers / aggregate_manager.py
1 import socket
2 from sfa.util.version import version_core
3 from sfa.util.xrn import Xrn
4 from sfa.util.callids import Callids
5 from sfa.server.api_versions import ApiVersions
6
7 class AggregateManager:
8
9     def __init__ (self, config): pass
10     
11     # essentially a union of the core version, the generic version (this code) and
12     # whatever the driver needs to expose
13     def GetVersion(self, api, options):
14         xrn=Xrn(api.hrn)
15         version = version_core()
16         geni_api_versions = ApiVersions().get_versions()
17         geni_api_versions.append({'2': 'http://%s:%s' % (api.config.SFA_AGGREGATE_HOST, api.config.SFA_AGGREGATE_PORT)})
18         version_generic = {
19             'interface':'aggregate',
20             'sfa': 2,
21             'geni_api': 2,
22             'geni_api_versions': geni_api_versions, 
23             'hrn':xrn.get_hrn(),
24             'urn':xrn.get_urn(),
25             }
26         version.update(version_generic)
27         testbed_version = self.driver.aggregate_version()
28         version.update(testbed_version)
29         return version
30     
31     def ListSlices(self, api, creds, options):
32         call_id = options.get('call_id')
33         if Callids().already_handled(call_id): return []
34         return self.driver.list_slices (creds, options)
35
36     def ListResources(self, api, creds, options):
37         call_id = options.get('call_id')
38         if Callids().already_handled(call_id): return ""
39
40         # get slice's hrn from options
41         slice_xrn = options.get('geni_slice_urn', None)
42         # pass None if no slice is specified
43         if not slice_xrn:
44             slice_hrn, slice_urn = None, None
45         else:
46             xrn = Xrn(slice_xrn)
47             slice_urn=xrn.get_urn()
48             slice_hrn=xrn.get_hrn()
49         return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
50     
51     def SliverStatus (self, api, xrn, creds, options):
52         call_id = options.get('call_id')
53         if Callids().already_handled(call_id): return {}
54     
55         xrn = Xrn(xrn,'slice')
56         slice_urn=xrn.get_urn()
57         slice_hrn=xrn.get_hrn()
58         return self.driver.sliver_status (slice_urn, slice_hrn)
59     
60     def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
61         """
62         Create the sliver[s] (slice) at this aggregate.    
63         Verify HRN and initialize the slice record in PLC if necessary.
64         """
65         call_id = options.get('call_id')
66         if Callids().already_handled(call_id): return ""
67     
68         xrn = Xrn(xrn, 'slice')
69         slice_urn=xrn.get_urn()
70         slice_hrn=xrn.get_hrn()
71
72         return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
73     
74     def DeleteSliver(self, api, xrn, creds, options):
75         call_id = options.get('call_id')
76         if Callids().already_handled(call_id): return True
77
78         xrn = Xrn(xrn, 'slice')
79         slice_urn=xrn.get_urn()
80         slice_hrn=xrn.get_hrn()
81         return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
82
83     def RenewSliver(self, api, xrn, creds, expiration_time, options):
84         call_id = options.get('call_id')
85         if Callids().already_handled(call_id): return True
86         
87         xrn = Xrn(xrn, 'slice')
88         slice_urn=xrn.get_urn()
89         slice_hrn=xrn.get_hrn()
90         return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
91     
92     ### these methods could use an options extension for at least call_id
93     def start_slice(self, api, xrn, creds):
94         xrn = Xrn(xrn)
95         slice_urn=xrn.get_urn()
96         slice_hrn=xrn.get_hrn()
97         return self.driver.start_slice (slice_urn, slice_hrn, creds)
98      
99     def stop_slice(self, api, xrn, creds):
100         xrn = Xrn(xrn)
101         slice_urn=xrn.get_urn()
102         slice_hrn=xrn.get_hrn()
103         return self.driver.stop_slice (slice_urn, slice_hrn, creds)
104
105     def reset_slice(self, api, xrn):
106         xrn = Xrn(xrn)
107         slice_urn=xrn.get_urn()
108         slice_hrn=xrn.get_hrn()
109         return self.driver.reset_slice (slice_urn, slice_hrn)
110
111     def GetTicket(self, api, xrn, creds, rspec, users, options):
112     
113         xrn = Xrn(xrn)
114         slice_urn=xrn.get_urn()
115         slice_hrn=xrn.get_hrn()
116
117         # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish
118         # to pass 'users' over to the driver as well
119         return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)
120