refactored GetVersion()
[sfa.git] / sfa / managers / aggregate_manager.py
1 import soctet
2 from sfa.rspecs.version_manager import VersionManager
3 from sfa.util.version import version_core
4 from sfa.util.xrn import Xrn
5 from sfa.util.callids import Callids
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
14     def _rspec_versions(self):
15         version_manager = VersionManager()
16         ad_rspec_versions = []
17         request_rspec_versions = []
18         for rspec_version in version_manager.versions:
19             if rspec_version.content_type in ['*', 'ad']:
20                 ad_rspec_versions.append(rspec_version.to_dict())
21             if rspec_version.content_type in ['*', 'request']:
22                 request_rspec_versions.append(rspec_version.to_dict())
23         return {
24             'testbed':self.testbed_name(),
25             'geni_request_rspec_versions': request_rspec_versions,
26             'geni_ad_rspec_versions': ad_rspec_versions,
27             }
28
29     def GetVersion(self, api, options):
30         xrn=Xrn(api.hrn)
31         version = version_core()
32         version_generic = {
33             'testbed': self.driver.testbed_name(),
34             'interface':'aggregate',
35             'hrn':xrn.get_hrn(),
36             'urn':xrn.get_urn(),
37             'geni_api': 3,
38             'geni_api_versions': {'3': 'http://%s:%s' % (socket.gethostname(), api.config.sfa_aggregate_port)},
39             'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
40             'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
41             'geni_best_effort': 'true',
42             'geni_credential_types': [{
43                 'geni_type': 'geni_sfa',
44                 'geni_version': 3,
45             }],
46         }
47         version.update(version_generic)
48         testbed_version = self.driver.aggregate_version()
49         version.update(testbed_version)
50         return version
51     
52     def ListSlices(self, api, creds, options):
53         call_id = options.get('call_id')
54         if Callids().already_handled(call_id): return []
55         return self.driver.list_slices (creds, options)
56
57     def ListResources(self, api, creds, options):
58         call_id = options.get('call_id')
59         if Callids().already_handled(call_id): return ""
60
61         # get slice's hrn from options
62         slice_xrn = options.get('geni_slice_urn', None)
63         # pass None if no slice is specified
64         if not slice_xrn:
65             slice_hrn, slice_urn = None, None
66         else:
67             xrn = Xrn(slice_xrn)
68             slice_urn=xrn.get_urn()
69             slice_hrn=xrn.get_hrn()
70         return self.driver.list_resources (slice_urn, slice_hrn, creds, options)
71     
72     def SliverStatus (self, api, xrn, creds, options):
73         call_id = options.get('call_id')
74         if Callids().already_handled(call_id): return {}
75     
76         xrn = Xrn(xrn,'slice')
77         slice_urn=xrn.get_urn()
78         slice_hrn=xrn.get_hrn()
79         return self.driver.sliver_status (slice_urn, slice_hrn)
80     
81     def CreateSliver(self, api, xrn, creds, rspec_string, users, options):
82         """
83         Create the sliver[s] (slice) at this aggregate.    
84         Verify HRN and initialize the slice record in PLC if necessary.
85         """
86         call_id = options.get('call_id')
87         if Callids().already_handled(call_id): return ""
88     
89         xrn = Xrn(xrn, 'slice')
90         slice_urn=xrn.get_urn()
91         slice_hrn=xrn.get_hrn()
92
93         return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options)
94     
95     def DeleteSliver(self, api, xrn, creds, options):
96         call_id = options.get('call_id')
97         if Callids().already_handled(call_id): return True
98
99         xrn = Xrn(xrn, 'slice')
100         slice_urn=xrn.get_urn()
101         slice_hrn=xrn.get_hrn()
102         return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
103
104     def RenewSliver(self, api, xrn, creds, expiration_time, options):
105         call_id = options.get('call_id')
106         if Callids().already_handled(call_id): return True
107         
108         xrn = Xrn(xrn, 'slice')
109         slice_urn=xrn.get_urn()
110         slice_hrn=xrn.get_hrn()
111         return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
112     
113     ### these methods could use an options extension for at least call_id
114     def start_slice(self, api, xrn, creds):
115         xrn = Xrn(xrn)
116         slice_urn=xrn.get_urn()
117         slice_hrn=xrn.get_hrn()
118         return self.driver.start_slice (slice_urn, slice_hrn, creds)
119      
120     def stop_slice(self, api, xrn, creds):
121         xrn = Xrn(xrn)
122         slice_urn=xrn.get_urn()
123         slice_hrn=xrn.get_hrn()
124         return self.driver.stop_slice (slice_urn, slice_hrn, creds)
125
126     def reset_slice(self, api, xrn):
127         xrn = Xrn(xrn)
128         slice_urn=xrn.get_urn()
129         slice_hrn=xrn.get_hrn()
130         return self.driver.reset_slice (slice_urn, slice_hrn)
131
132     def GetTicket(self, api, xrn, creds, rspec, users, options):
133     
134         xrn = Xrn(xrn)
135         slice_urn=xrn.get_urn()
136         slice_hrn=xrn.get_hrn()
137
138         return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options)
139