1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env python
# Copyright 2016 Cisco Systems, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Configuration Plugin.
This module is used to override the configuration with platform specific constraints and extensions
"""
import abc
import specs
class ConfigPluginBase(object):
"""Base class for config plugins."""
__metaclass__ = abc.ABCMeta
class InitializationFailure(Exception):
"""Used in case of any init failure."""
pass
def __init__(self, config):
"""Save configuration."""
if not config:
raise ConfigPluginBase.InitializationFailure(
'Initialization parameters need to be assigned.')
self.config = config
@abc.abstractmethod
def get_config(self):
"""Return updated default configuration file."""
def set_config(self, config):
"""Set a new configuration.
This method is called when the config has changed after this instance was initialized.
This is needed in the frequent case where the main config is changed in a copy and to
prevent this instance to keep pointing to the old copy of the config
"""
self.config = config
@abc.abstractmethod
def get_openstack_spec(self):
"""Return OpenStack specs for host."""
@abc.abstractmethod
def get_run_spec(self, config, openstack_spec):
"""Return RunSpec for given platform."""
@abc.abstractmethod
def validate_config(self, cfg, openstack_spec):
"""Validate config file."""
@abc.abstractmethod
def prepare_results_config(self, cfg):
"""Insert any plugin specific information to the results.
This function is called before running configuration is copied.
Example usage is to remove sensitive information like switch credentials.
"""
@abc.abstractmethod
def get_version(self):
"""Return platform version."""
class ConfigPlugin(ConfigPluginBase):
"""No-op config plugin class. Does not change anything."""
def __init__(self, config):
"""Invoke the base class constructor."""
ConfigPluginBase.__init__(self, config)
def get_config(self):
"""Public interface for updating config file. Just returns given config."""
return self.config
def get_openstack_spec(self):
"""Return OpenStack specs for host."""
return specs.OpenStackSpec()
def get_run_spec(self, config, openstack_spec):
"""Return RunSpec for given platform."""
return specs.RunSpec(config.no_vswitch_access, openstack_spec)
def validate_config(self, config, openstack_spec):
"""Nothing to validate by default."""
pass
def prepare_results_config(self, cfg):
"""Nothing to add the results by default."""
return cfg
def get_version(self):
"""Return an empty version."""
return {}
|