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
23 from vnfs.vnf.vnf import IVnf
26 """Loader class - main object context holder.
28 _trafficgen_loader = None
29 _metrics_loader = None
30 _vswitch_loader = None
34 """Loader ctor - initialization method.
36 All data is read from configuration each time Loader instance is
37 created. It is up to creator to maintain object life cycle if this
40 self._trafficgen_loader = LoaderServant(
41 settings.getValue('TRAFFICGEN_DIR'),
42 settings.getValue('TRAFFICGEN'),
45 self._metrics_loader = LoaderServant(
46 settings.getValue('COLLECTOR_DIR'),
47 settings.getValue('COLLECTOR'),
50 self._vswitch_loader = LoaderServant(
51 settings.getValue('VSWITCH_DIR'),
52 settings.getValue('VSWITCH'),
55 self._vnf_loader = LoaderServant(
56 settings.getValue('VNF_DIR'),
57 settings.getValue('VNF'),
60 def get_trafficgen(self):
61 """Returns a new instance configured traffic generator.
63 :return: ITrafficGenerator implementation if available, None otherwise.
65 return self._trafficgen_loader.get_class()()
67 def get_trafficgen_class(self):
68 """Returns type of currently configured traffic generator.
70 :return: Type of ITrafficGenerator implementation if available.
73 return self._trafficgen_loader.get_class()
75 def get_trafficgens(self):
76 """Returns dictionary of all available traffic generators.
78 :return: Dictionary of traffic generators.
79 - key: name of the class which implements ITrafficGenerator,
80 - value: Type of traffic generator which implements
83 return self._trafficgen_loader.get_classes()
85 def get_trafficgens_printable(self):
86 """Returns all available traffic generators in printable format.
88 :return: String containing printable list of traffic generators.
90 return self._trafficgen_loader.get_classes_printable()
92 def get_collector(self):
93 """Returns instance of currently configured collector implementation.
95 :return: ICollector implementation if available, None otherwise.
97 return self._metrics_loader.get_class()()
99 def get_collector_class(self):
100 """Returns type of currently configured collector implementation.
102 :return: Type of ICollector implementation if available.
105 return self._metrics_loader.get_class()
107 def get_collectors(self):
108 """Returns dictionary of all available collectors.
110 :return: Dictionary of collectors.
111 - key: name of the class which implements ICollector,
112 - value: Type of traffic generator which implements ICollector.
114 return self._metrics_loader.get_classes()
116 def get_collectors_printable(self):
117 """Returns all available collectors in printable format.
119 :return: String containing printable list of collectors.
121 return self._metrics_loader.get_classes_printable()
123 def get_vswitch(self):
124 """Returns instance of currently configured vswitch implementation.
126 :return: IVSwitch implementation if available, None otherwise.
128 return self._vswitch_loader.get_class()()
130 def get_vswitch_class(self):
131 """Returns type of currently configured vswitch implementation.
133 :return: Type of IVSwitch implementation if available.
136 return self._vswitch_loader.get_class()
138 def get_vswitches(self):
139 """Returns dictionary of all available vswitches.
141 :return: Dictionary of vswitches.
142 - key: name of the class which implements IVSwitch,
143 - value: Type of traffic generator which implements IVSwitch.
145 return self._vswitch_loader.get_classes()
147 def get_vswitches_printable(self):
148 """Returns all available vswitches in printable format.
150 :return: String containing printable list of vswitches.
152 return self._vswitch_loader.get_classes_printable()
155 """Returns instance of currently configured vnf implementation.
157 :return: IVnf implementation if available, None otherwise.
159 return self._vnf_loader.get_class()()
161 def get_vnf_class(self):
162 """Returns type of currently configured vnf implementation.
164 :return: Type of IVnf implementation if available.
167 return self._vnf_loader.get_class()
170 """Returns dictionary of all available vnfs.
172 :return: Dictionary of vnfs.
173 - key: name of the class which implements IVnf,
174 - value: Type of vnf which implements IVnf.
176 return self._vnf_loader.get_classes()
178 def get_vnfs_printable(self):
179 """Returns all available vnfs in printable format.
181 :return: String containing printable list of vnfs.
183 return self._vnf_loader.get_classes_printable()