ed6b3c683e5f6ae2e03f89b4b12d4b43d479576d
[nfvbench.git] / nfvbench / config_plugin.py
1 #!/usr/bin/env python
2 # Copyright 2016 Cisco Systems, Inc.  All rights reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15 #
16
17 import abc
18 import specs
19
20
21 class ConfigPluginBase(object):
22     """Base class for config plugins. Need to implement public interfaces."""
23     __metaclass__ = abc.ABCMeta
24
25     class InitializationFailure(Exception):
26         pass
27
28     def __init__(self, config):
29         if not config:
30             raise ConfigPluginBase.InitializationFailure(
31                 'Initialization parameters need to be assigned.')
32
33         self.config = config
34
35     @abc.abstractmethod
36     def get_config(self):
37         """Returns updated default configuration file."""
38
39     @abc.abstractmethod
40     def get_openstack_spec(self):
41         """Returns OpenStack specs for host."""
42
43     @abc.abstractmethod
44     def get_run_spec(self, openstack_spec):
45         """Returns RunSpec for given platform."""
46
47     @abc.abstractmethod
48     def validate_config(self, cfg):
49         """Validate config file."""
50
51     @abc.abstractmethod
52     def prepare_results_config(self, cfg):
53         """This function is called before running configuration is copied.
54         Example usage is to remove sensitive information like switch credentials.
55         """
56
57     @abc.abstractmethod
58     def get_version(self):
59         """Returns platform version."""
60
61
62 class ConfigPlugin(ConfigPluginBase):
63     """No-op config plugin class. Does not change anything."""
64
65     def __init__(self, config):
66         ConfigPluginBase.__init__(self, config)
67
68     def get_config(self):
69         """Public interface for updating config file. Just returns given config."""
70         return self.config
71
72     def get_openstack_spec(self):
73         """Returns OpenStack specs for host."""
74         return specs.OpenStackSpec()
75
76     def get_run_spec(self, openstack_spec):
77         """Returns RunSpec for given platform."""
78         return specs.RunSpec(self.config.no_vswitch_access, openstack_spec)
79
80     def validate_config(self, config):
81         pass
82
83     def prepare_results_config(self, cfg):
84         return cfg
85
86     def get_version(self):
87         return {}