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