36126c2687816e024a0454b014800218ad1aa811
[sfa.git] / sfa / managers / aggregate_manager.py
1 import socket
2 import datetime
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
8
9 class AggregateManager:
10
11     def __init__ (self, config): pass
12     
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)
20         version_generic = {
21             'interface':'aggregate',
22             'sfa': 2,
23             'geni_api': 2,
24             'geni_api_versions': geni_api_versions, 
25             'hrn':xrn.get_hrn(),
26             'urn':xrn.get_urn(),
27             'geni_handles_speaksfor': True,     # supports 'speaks for' credentials  
28             }
29         version.update(version_generic)
30         testbed_version = self.driver.aggregate_version()
31         version.update(testbed_version)
32         return version
33     
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)
38
39     def ListResources(self, api, creds, options):
40         call_id = options.get('call_id')
41         if Callids().already_handled(call_id): return ""
42
43         # get slice's hrn from options
44         slice_xrn = options.get('geni_slice_urn', None)
45         # pass None if no slice is specified
46         if not slice_xrn:
47             slice_hrn, slice_urn = None, None
48         else:
49             xrn = Xrn(slice_xrn)
50             slice_urn=xrn.get_urn()
51             slice_hrn=xrn.get_hrn()
52         return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
53     
54     def SliverStatus (self, api, xrn, creds, options):
55         call_id = options.get('call_id')
56         if Callids().already_handled(call_id): return {}
57     
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)
62     
63     def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
64         """
65         Create the sliver[s] (slice) at this aggregate.    
66         Verify HRN and initialize the slice record in PLC if necessary.
67         """
68         call_id = options.get('call_id')
69         if Callids().already_handled(call_id): return ""
70     
71         xrn = Xrn(xrn, 'slice')
72         slice_urn=xrn.get_urn()
73         slice_hrn=xrn.get_hrn()
74
75         return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
76     
77     def DeleteSliver(self, api, xrn, creds, options):
78         call_id = options.get('call_id')
79         if Callids().already_handled(call_id): return True
80
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)
85
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
89         
90         xrn = Xrn(xrn, 'slice')
91         slice_urn=xrn.get_urn()
92         slice_hrn=xrn.get_hrn()
93
94         if options.get('geni_extend_alap'):
95             now = datetime.datetime.now()
96             requested = utcparse(expiration_time)
97             max = adjust_datetime(now, days=30)
98             if requested > max:
99                 expiration_time = max
100      
101         return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
102     
103     ### these methods could use an options extension for at least call_id
104     def start_slice(self, api, xrn, creds):
105         xrn = Xrn(xrn)
106         slice_urn=xrn.get_urn()
107         slice_hrn=xrn.get_hrn()
108         return self.driver.start_slice (slice_urn, slice_hrn, creds)
109      
110     def stop_slice(self, api, xrn, creds):
111         xrn = Xrn(xrn)
112         slice_urn=xrn.get_urn()
113         slice_hrn=xrn.get_hrn()
114         return self.driver.stop_slice (slice_urn, slice_hrn, creds)
115
116     def reset_slice(self, api, xrn):
117         xrn = Xrn(xrn)
118         slice_urn=xrn.get_urn()
119         slice_hrn=xrn.get_hrn()
120         return self.driver.reset_slice (slice_urn, slice_hrn)
121
122     def GetTicket(self, api, xrn, creds, rspec, users, options):
123     
124         xrn = Xrn(xrn)
125         slice_urn=xrn.get_urn()
126         slice_hrn=xrn.get_hrn()
127
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)
131