Merge "Tools: Improve Stability."
[vswitchperf.git] / core / loader / loader.py
1 # Copyright 2015-2017 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """Loader module definition.
16 """
17
18 from conf import settings
19 from core.loader.loader_servant import LoaderServant
20 from tools.collectors.collector import ICollector
21 from tools.load_gen.load_gen import ILoadGenerator
22 from tools.pkt_fwd.pkt_fwd import IPktFwd
23 from tools.pkt_gen.trafficgen import ITrafficGenerator
24 from vswitches.vswitch import IVSwitch
25 from vnfs.vnf.vnf import IVnf
26 from pods.pod.pod import IPod
27
28 # pylint: disable=too-many-public-methods
29 class Loader(object):
30     """Loader class - main object context holder.
31     """
32     _trafficgen_loader = None
33     _metrics_loader = None
34     _vswitch_loader = None
35     _vnf_loader = None
36     _loadgen_loader = None
37
38     def __init__(self):
39         """Loader ctor - initialization method.
40
41         All data is read from configuration each time Loader instance is
42         created. It is up to creator to maintain object life cycle if this
43         behavior is unwanted.
44         """
45         self._trafficgen_loader = LoaderServant(
46             settings.getValue('TRAFFICGEN_DIR'),
47             settings.getValue('TRAFFICGEN'),
48             ITrafficGenerator)
49
50         self._metrics_loader = LoaderServant(
51             settings.getValue('COLLECTOR_DIR'),
52             settings.getValue('COLLECTOR'),
53             ICollector)
54
55         self._loadgen_loader = LoaderServant(
56             settings.getValue('LOADGEN_DIR'),
57             settings.getValue('LOADGEN'),
58             ILoadGenerator)
59
60         self._vswitch_loader = LoaderServant(
61             settings.getValue('VSWITCH_DIR'),
62             settings.getValue('VSWITCH'),
63             IVSwitch)
64
65         self._vnf_loader = LoaderServant(
66             settings.getValue('VNF_DIR'),
67             settings.getValue('VNF'),
68             IVnf)
69
70         self._pktfwd_loader = LoaderServant(
71             settings.getValue('PKTFWD_DIR'),
72             settings.getValue('PKTFWD'),
73             IPktFwd)
74
75         self._pod_loader = LoaderServant(
76             settings.getValue('POD_DIR'),
77             settings.getValue('POD'),
78             IPod)
79
80     def get_trafficgen(self):
81         """Returns a new instance configured traffic generator.
82
83         :return: ITrafficGenerator implementation if available, None otherwise.
84         """
85         return self._trafficgen_loader.get_class()()
86
87     def get_trafficgen_class(self):
88         """Returns type of currently configured traffic generator.
89
90         :return: Type of ITrafficGenerator implementation if available.
91             None otherwise.
92         """
93         return self._trafficgen_loader.get_class()
94
95     def get_trafficgens(self):
96         """Returns dictionary of all available traffic generators.
97
98         :return: Dictionary of traffic generators.
99             - key: name of the class which implements ITrafficGenerator,
100             - value: Type of traffic generator which implements
101               ITrafficGenerator.
102         """
103         return self._trafficgen_loader.get_classes()
104
105     def get_trafficgens_printable(self):
106         """Returns all available traffic generators in printable format.
107
108         :return: String containing printable list of traffic generators.
109         """
110         return self._trafficgen_loader.get_classes_printable()
111
112     def get_collector(self):
113         """Returns instance of currently configured collector implementation.
114
115         :return: ICollector implementation if available, None otherwise.
116         """
117         return self._metrics_loader.get_class()()
118
119     def get_collector_class(self):
120         """Returns type of currently configured collector implementation.
121
122         :return: Type of ICollector implementation if available.
123             None otherwise.
124         """
125         return self._metrics_loader.get_class()
126
127     def get_collectors(self):
128         """Returns dictionary of all available collectors.
129
130         :return: Dictionary of collectors.
131             - key: name of the class which implements ICollector,
132             - value: Type of collector which implements ICollector.
133         """
134         return self._metrics_loader.get_classes()
135
136     def get_collectors_printable(self):
137         """Returns all available collectors in printable format.
138
139         :return: String containing printable list of collectors.
140         """
141         return self._metrics_loader.get_classes_printable()
142
143     def get_loadgen_class(self):
144         """Returns type of currently configured loadgen implementation.
145
146         :return: Type of ILoadGenerator implementation if available.
147             None otherwise.
148         """
149         return self._loadgen_loader.get_class()
150
151     def get_loadgens(self):
152         """Returns dictionary of all available loadgens
153
154         :return: Dictionary of loadgens
155             - key: name of the class which implements ILoadGenerator
156             - value: Type of class which implements ILoadGenerator
157         """
158         return self._loadgen_loader.get_classes()
159
160     def get_loadgens_printable(self):
161         """Returns all available loadgens in printable format
162
163         :return: String containing printable list of loadgens
164         """
165         return self._loadgen_loader.get_classes_printable()
166
167     def get_vswitch(self):
168         """Returns instance of currently configured vswitch implementation.
169
170         :return: IVSwitch implementation if available, None otherwise.
171         """
172         return self._vswitch_loader.get_class()()
173
174     def get_vswitch_class(self):
175         """Returns type of currently configured vswitch implementation.
176
177         :return: Type of IVSwitch implementation if available.
178             None otherwise.
179         """
180         return self._vswitch_loader.get_class()
181
182     def get_vswitches(self):
183         """Returns dictionary of all available vswitches.
184
185         :return: Dictionary of vswitches.
186             - key: name of the class which implements IVSwitch,
187             - value: Type of vswitch which implements IVSwitch.
188         """
189         return self._vswitch_loader.get_classes()
190
191     def get_vswitches_printable(self):
192         """Returns all available vswitches in printable format.
193
194         :return: String containing printable list of vswitches.
195         """
196         return self._vswitch_loader.get_classes_printable()
197
198     def get_vnf(self):
199         """Returns instance of currently configured vnf implementation.
200
201         :return: IVnf implementation if available, None otherwise.
202         """
203         return self._vnf_loader.get_class()()
204
205     def get_vnf_class(self):
206         """Returns type of currently configured vnf implementation.
207
208         :return: Type of IVnf implementation if available.
209             None otherwise.
210         """
211         return self._vnf_loader.get_class()
212
213     def get_vnfs(self):
214         """Returns dictionary of all available vnfs.
215
216         :return: Dictionary of vnfs.
217             - key: name of the class which implements IVnf,
218             - value: Type of vnf which implements IVnf.
219         """
220         return self._vnf_loader.get_classes()
221
222     def get_vnfs_printable(self):
223         """Returns all available vnfs in printable format.
224
225         :return: String containing printable list of vnfs.
226         """
227         return self._vnf_loader.get_classes_printable()
228
229     def get_pod(self):
230         """Returns instance of currently configured pod implementation.
231
232         :return: IPod implementation if available, None otherwise.
233         """
234         return self._pod_loader.get_class()()
235
236     def get_pod_class(self):
237         """Returns type of currently configured pod implementation.
238
239         :return: Type of IPod implementation if available.
240             None otherwise.
241         """
242         return self._pod_loader.get_class()
243
244     def get_pods(self):
245         """Returns dictionary of all available pods.
246
247         :return: Dictionary of pods.
248             - key: name of the class which implements IPod,
249             - value: Type of vnf which implements IPod.
250         """
251         return self._pod_loader.get_classes()
252
253     def get_pods_printable(self):
254         """Returns all available pods in printable format.
255
256         :return: String containing printable list of pods.
257         """
258         return self._pod_loader.get_classes_printable()
259
260     def get_pktfwd(self):
261         """Returns instance of currently configured packet forwarder implementation.
262
263         :return: IPktFwd implementation if available, None otherwise.
264         """
265         return self._pktfwd_loader.get_class()()
266
267     def get_pktfwd_class(self):
268         """Returns type of currently configured packet forwarder implementation.
269
270         :return: Type of IPktFwd implementation if available.
271             None otherwise.
272         """
273         return self._pktfwd_loader.get_class()
274
275     def get_pktfwds(self):
276         """Returns dictionary of all available packet forwarders.
277
278         :return: Dictionary of packet forwarders.
279             - key: name of the class which implements IPktFwd,
280             - value: Type of packet forwarder which implements IPktFwd.
281         """
282         return self._pktfwd_loader.get_classes()
283
284     def get_pktfwds_printable(self):
285         """Returns all available packet forwarders in printable format.
286
287         :return: String containing printable list of packet forwarders.
288         """
289         return self._pktfwd_loader.get_classes_printable()