1 # Copyright 2015 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.pkt_gen.trafficgen import ITrafficGenerator
21 from tools.collectors.collector import ICollector
22 from vswitches.vswitch import IVSwitch
25 """Loader class - main object context holder.
27 _trafficgen_loader = None
28 _metrics_loader = None
29 _vswitch_loader = None
32 """Loader ctor - initialization method.
34 All data is read from configuration each time Loader instance is
35 created. It is up to creator to maintain object life cycle if this
38 self._trafficgen_loader = LoaderServant(
39 settings.getValue('TRAFFICGEN_DIR'),
40 settings.getValue('TRAFFICGEN'),
43 self._metrics_loader = LoaderServant(
44 settings.getValue('COLLECTOR_DIR'),
45 settings.getValue('COLLECTOR'),
48 self._vswitch_loader = LoaderServant(
49 settings.getValue('VSWITCH_DIR'),
50 settings.getValue('VSWITCH'),
53 def get_trafficgen(self):
54 """Returns a new instance configured traffic generator.
56 :return: ITrafficGenerator implementation if available, None otherwise.
58 return self._trafficgen_loader.get_class()()
60 def get_trafficgen_class(self):
61 """Returns type of currently configured traffic generator.
63 :return: Type of ITrafficGenerator implementation if available.
66 return self._trafficgen_loader.get_class()
68 def get_trafficgens(self):
69 """Returns dictionary of all available traffic generators.
71 :return: Dictionary of traffic generators.
72 - key: name of the class which implements ITrafficGenerator,
73 - value: Type of traffic generator which implements
76 return self._trafficgen_loader.get_classes()
78 def get_trafficgens_printable(self):
79 """Returns all available traffic generators in printable format.
81 :return: String containing printable list of traffic generators.
83 return self._trafficgen_loader.get_classes_printable()
85 def get_collector(self):
86 """Returns instance of currently configured collector implementation.
88 :return: ICollector implementation if available, None otherwise.
90 return self._metrics_loader.get_class()()
92 def get_collector_class(self):
93 """Returns type of currently configured collector implementation.
95 :return: Type of ICollector implementation if available.
98 return self._metrics_loader.get_class()
100 def get_collectors(self):
101 """Returns dictionary of all available collectors.
103 :return: Dictionary of collectors.
104 - key: name of the class which implements ICollector,
105 - value: Type of traffic generator which implements ICollector.
107 return self._metrics_loader.get_classes()
109 def get_collectors_printable(self):
110 """Returns all available collectors in printable format.
112 :return: String containing printable list of collectors.
114 return self._metrics_loader.get_classes_printable()
116 def get_vswitch(self):
117 """Returns instance of currently configured vswitch implementation.
119 :return: IVSwitch implementation if available, None otherwise.
121 return self._vswitch_loader.get_class()()
123 def get_vswitch_class(self):
124 """Returns type of currently configured vswitch implementation.
126 :return: Type of IVSwitch implementation if available.
129 return self._vswitch_loader.get_class()
131 def get_vswitches(self):
132 """Returns dictionary of all available vswitches.
134 :return: Dictionary of vswitches.
135 - key: name of the class which implements IVSwitch,
136 - value: Type of traffic generator which implements IVSwitch.
138 return self._vswitch_loader.get_classes()
140 def get_vswitches_printable(self):
141 """Returns all available vswitches in printable format.
143 :return: String containing printable list of vswitches.
145 return self._vswitch_loader.get_classes_printable()
147 def get_vnf_class(self):
148 """Returns a new instance of the configured VNF
150 Currently always returns None
152 #TODO: Load the VNF class