2 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 """Configuration Plugin.
18 This module is used to override the configuration with platform specific constraints and extensions
24 class ConfigPluginBase(object, metaclass=abc.ABCMeta):
25 """Base class for config plugins."""
27 class InitializationFailure(Exception):
28 """Used in case of any init failure."""
30 def __init__(self, config):
31 """Save configuration."""
33 raise ConfigPluginBase.InitializationFailure(
34 'Initialization parameters need to be assigned.')
39 """Return updated default configuration file."""
41 def set_config(self, config):
42 """Set a new configuration.
44 This method is called when the config has changed after this instance was initialized.
45 This is needed in the frequent case where the main config is changed in a copy and to
46 prevent this instance to keep pointing to the old copy of the config
51 def get_openstack_spec(self):
52 """Return OpenStack specs for host."""
55 def get_run_spec(self, config, openstack_spec):
56 """Return RunSpec for given platform."""
59 def validate_config(self, cfg, openstack_spec):
60 """Validate config file."""
63 def prepare_results_config(self, cfg):
64 """Insert any plugin specific information to the results.
66 This function is called before running configuration is copied.
67 Example usage is to remove sensitive information like switch credentials.
71 def get_version(self):
72 """Return platform version."""
75 class ConfigPlugin(ConfigPluginBase):
76 """No-op config plugin class. Does not change anything."""
78 def __init__(self, config):
79 """Invoke the base class constructor."""
80 ConfigPluginBase.__init__(self, config)
83 """Public interface for updating config file. Just returns given config."""
86 def get_openstack_spec(self):
87 """Return OpenStack specs for host."""
88 return specs.OpenStackSpec()
90 def get_run_spec(self, config, openstack_spec):
91 """Return RunSpec for given platform."""
92 return specs.RunSpec(config.no_vswitch_access, openstack_spec)
94 def validate_config(self, config, openstack_spec):
95 """Nothing to validate by default."""
97 def prepare_results_config(self, cfg):
98 """Nothing to add the results by default."""
101 def get_version(self):
102 """Return an empty version."""