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