2ad3f9cc92138cfdabcb77365e7921592d954804
[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             }
28         version.update(version_generic)
29         testbed_version = self.driver.aggregate_version()
30         version.update(testbed_version)
31         return version
32     
33     def ListSlices(self, api, creds, options):
34         call_id = options.get('call_id')
35         if Callids().already_handled(call_id): return []
36         return self.driver.list_slices (creds, options)
37
38     def ListResources(self, api, creds, options):
39         call_id = options.get('call_id')
40         if Callids().already_handled(call_id): return ""
41
42         # get slice's hrn from options
43         slice_xrn = options.get('geni_slice_urn', None)
44         # pass None if no slice is specified
45         if not slice_xrn:
46             slice_hrn, slice_urn = None, None
47         else:
48             xrn = Xrn(slice_xrn)
49             slice_urn=xrn.get_urn()
50             slice_hrn=xrn.get_hrn()
51         return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
52     
53     def SliverStatus (self, api, xrn, creds, options):
54         call_id = options.get('call_id')
55         if Callids().already_handled(call_id): return {}
56     
57         xrn = Xrn(xrn,'slice')
58         slice_urn=xrn.get_urn()
59         slice_hrn=xrn.get_hrn()
60         return self.driver.sliver_status (slice_urn, slice_hrn)
61     
62     def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
63         """
64         Create the sliver[s] (slice) at this aggregate.    
65         Verify HRN and initialize the slice record in PLC if necessary.
66         """
67         call_id = options.get('call_id')
68         if Callids().already_handled(call_id): return ""
69     
70         xrn = Xrn(xrn, 'slice')
71         slice_urn=xrn.get_urn()
72         slice_hrn=xrn.get_hrn()
73
74         return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
75     
76     def DeleteSliver(self, api, xrn, creds, options):
77         call_id = options.get('call_id')
78         if Callids().already_handled(call_id): return True
79
80         xrn = Xrn(xrn, 'slice')
81         slice_urn=xrn.get_urn()
82         slice_hrn=xrn.get_hrn()
83         return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
84
85     def RenewSliver(self, api, xrn, creds, expiration_time, options):
86         call_id = options.get('call_id')
87         if Callids().already_handled(call_id): return True
88         
89         xrn = Xrn(xrn, 'slice')
90         slice_urn=xrn.get_urn()
91         slice_hrn=xrn.get_hrn()
92
93         if options.get('geni_extend_alap'):
94             now = datetime.datetime.now()
95             requested = utcparse(expiration_time)
96             max = adjust_datetime(now, days=30)
97             if requested > max:
98                 expiration_time = max
99      
100         return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
101     
102     ### these methods could use an options extension for at least call_id
103     def start_slice(self, api, xrn, creds):
104         xrn = Xrn(xrn)
105         slice_urn=xrn.get_urn()
106         slice_hrn=xrn.get_hrn()
107         return self.driver.start_slice (slice_urn, slice_hrn, creds)
108      
109     def stop_slice(self, api, xrn, creds):
110         xrn = Xrn(xrn)
111         slice_urn=xrn.get_urn()
112         slice_hrn=xrn.get_hrn()
113         return self.driver.stop_slice (slice_urn, slice_hrn, creds)
114
115     def reset_slice(self, api, xrn):
116         xrn = Xrn(xrn)
117         slice_urn=xrn.get_urn()
118         slice_hrn=xrn.get_hrn()
119         return self.driver.reset_slice (slice_urn, slice_hrn)
120
121     def GetTicket(self, api, xrn, creds, rspec, users, options):
122     
123         xrn = Xrn(xrn)
124         slice_urn=xrn.get_urn()
125         slice_hrn=xrn.get_hrn()
126
127         # xxx sounds like GetTicket is dead, but if that gets resurrected we might wish
128         # to pass 'users' over to the driver as well
129         return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)
130