1 # Copyright 2015-2017 Intel Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """Loader module definition.
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
28 # pylint: disable=too-many-public-methods
30 """Loader class - main object context holder.
32 _trafficgen_loader = None
33 _metrics_loader = None
34 _vswitch_loader = None
36 _loadgen_loader = None
39 """Loader ctor - initialization method.
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
45 self._trafficgen_loader = LoaderServant(
46 settings.getValue('TRAFFICGEN_DIR'),
47 settings.getValue('TRAFFICGEN'),
50 self._metrics_loader = LoaderServant(
51 settings.getValue('COLLECTOR_DIR'),
52 settings.getValue('COLLECTOR'),
55 self._loadgen_loader = LoaderServant(
56 settings.getValue('LOADGEN_DIR'),
57 settings.getValue('LOADGEN'),
60 self._vswitch_loader = LoaderServant(
61 settings.getValue('VSWITCH_DIR'),
62 settings.getValue('VSWITCH'),
65 self._vnf_loader = LoaderServant(
66 settings.getValue('VNF_DIR'),
67 settings.getValue('VNF'),
70 self._pktfwd_loader = LoaderServant(
71 settings.getValue('PKTFWD_DIR'),
72 settings.getValue('PKTFWD'),
75 self._pod_loader = LoaderServant(
76 settings.getValue('POD_DIR'),
77 settings.getValue('POD'),
80 def get_trafficgen(self):
81 """Returns a new instance configured traffic generator.
83 :return: ITrafficGenerator implementation if available, None otherwise.
85 return self._trafficgen_loader.get_class()()
87 def get_trafficgen_class(self):
88 """Returns type of currently configured traffic generator.
90 :return: Type of ITrafficGenerator implementation if available.
93 return self._trafficgen_loader.get_class()
95 def get_trafficgens(self):
96 """Returns dictionary of all available traffic generators.
98 :return: Dictionary of traffic generators.
99 - key: name of the class which implements ITrafficGenerator,
100 - value: Type of traffic generator which implements
103 return self._trafficgen_loader.get_classes()
105 def get_trafficgens_printable(self):
106 """Returns all available traffic generators in printable format.
108 :return: String containing printable list of traffic generators.
110 return self._trafficgen_loader.get_classes_printable()
112 def get_collector(self):
113 """Returns instance of currently configured collector implementation.
115 :return: ICollector implementation if available, None otherwise.
117 return self._metrics_loader.get_class()()
119 def get_collector_class(self):
120 """Returns type of currently configured collector implementation.
122 :return: Type of ICollector implementation if available.
125 return self._metrics_loader.get_class()
127 def get_collectors(self):
128 """Returns dictionary of all available collectors.
130 :return: Dictionary of collectors.
131 - key: name of the class which implements ICollector,
132 - value: Type of collector which implements ICollector.
134 return self._metrics_loader.get_classes()
136 def get_collectors_printable(self):
137 """Returns all available collectors in printable format.
139 :return: String containing printable list of collectors.
141 return self._metrics_loader.get_classes_printable()
143 def get_loadgen_class(self):
144 """Returns type of currently configured loadgen implementation.
146 :return: Type of ILoadGenerator implementation if available.
149 return self._loadgen_loader.get_class()
151 def get_loadgens(self):
152 """Returns dictionary of all available loadgens
154 :return: Dictionary of loadgens
155 - key: name of the class which implements ILoadGenerator
156 - value: Type of class which implements ILoadGenerator
158 return self._loadgen_loader.get_classes()
160 def get_loadgens_printable(self):
161 """Returns all available loadgens in printable format
163 :return: String containing printable list of loadgens
165 return self._loadgen_loader.get_classes_printable()
167 def get_vswitch(self):
168 """Returns instance of currently configured vswitch implementation.
170 :return: IVSwitch implementation if available, None otherwise.
172 return self._vswitch_loader.get_class()()
174 def get_vswitch_class(self):
175 """Returns type of currently configured vswitch implementation.
177 :return: Type of IVSwitch implementation if available.
180 return self._vswitch_loader.get_class()
182 def get_vswitches(self):
183 """Returns dictionary of all available vswitches.
185 :return: Dictionary of vswitches.
186 - key: name of the class which implements IVSwitch,
187 - value: Type of vswitch which implements IVSwitch.
189 return self._vswitch_loader.get_classes()
191 def get_vswitches_printable(self):
192 """Returns all available vswitches in printable format.
194 :return: String containing printable list of vswitches.
196 return self._vswitch_loader.get_classes_printable()
199 """Returns instance of currently configured vnf implementation.
201 :return: IVnf implementation if available, None otherwise.
203 return self._vnf_loader.get_class()()
205 def get_vnf_class(self):
206 """Returns type of currently configured vnf implementation.
208 :return: Type of IVnf implementation if available.
211 return self._vnf_loader.get_class()
214 """Returns dictionary of all available vnfs.
216 :return: Dictionary of vnfs.
217 - key: name of the class which implements IVnf,
218 - value: Type of vnf which implements IVnf.
220 return self._vnf_loader.get_classes()
222 def get_vnfs_printable(self):
223 """Returns all available vnfs in printable format.
225 :return: String containing printable list of vnfs.
227 return self._vnf_loader.get_classes_printable()
230 """Returns instance of currently configured pod implementation.
232 :return: IPod implementation if available, None otherwise.
234 return self._pod_loader.get_class()()
236 def get_pod_class(self):
237 """Returns type of currently configured pod implementation.
239 :return: Type of IPod implementation if available.
242 return self._pod_loader.get_class()
245 """Returns dictionary of all available pods.
247 :return: Dictionary of pods.
248 - key: name of the class which implements IPod,
249 - value: Type of vnf which implements IPod.
251 return self._pod_loader.get_classes()
253 def get_pods_printable(self):
254 """Returns all available pods in printable format.
256 :return: String containing printable list of pods.
258 return self._pod_loader.get_classes_printable()
260 def get_pktfwd(self):
261 """Returns instance of currently configured packet forwarder implementation.
263 :return: IPktFwd implementation if available, None otherwise.
265 return self._pktfwd_loader.get_class()()
267 def get_pktfwd_class(self):
268 """Returns type of currently configured packet forwarder implementation.
270 :return: Type of IPktFwd implementation if available.
273 return self._pktfwd_loader.get_class()
275 def get_pktfwds(self):
276 """Returns dictionary of all available packet forwarders.
278 :return: Dictionary of packet forwarders.
279 - key: name of the class which implements IPktFwd,
280 - value: Type of packet forwarder which implements IPktFwd.
282 return self._pktfwd_loader.get_classes()
284 def get_pktfwds_printable(self):
285 """Returns all available packet forwarders in printable format.
287 :return: String containing printable list of packet forwarders.
289 return self._pktfwd_loader.get_classes_printable()