109 lines
3.0 KiB
Python
109 lines
3.0 KiB
Python
# 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.
|
|
|
|
import logging
|
|
import voluptuous as v
|
|
import yaml
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class ConfigValidator:
|
|
"""Check the layout and certain configuration options"""
|
|
|
|
def __init__(self, config_file):
|
|
self.config_file = config_file
|
|
|
|
def validate(self):
|
|
label_min_ram = v.Schema({v.Required('min-ram'): int}, extra=True)
|
|
|
|
label_flavor_name = v.Schema({v.Required('flavor-name'): str},
|
|
extra=True)
|
|
|
|
pool_label_main = {
|
|
v.Required('name'): str,
|
|
v.Required('diskimage'): str,
|
|
'min-ram': int,
|
|
'flavor-name': str,
|
|
'key-name': str,
|
|
}
|
|
|
|
pool_label = v.All(pool_label_main,
|
|
v.Any(label_min_ram, label_flavor_name))
|
|
|
|
pool = {
|
|
'name': str,
|
|
'networks': [str],
|
|
'max-servers': int,
|
|
'labels': [pool_label],
|
|
'availability-zones': [str],
|
|
}
|
|
|
|
provider_diskimage = {
|
|
'name': str,
|
|
'pause': bool,
|
|
'meta': dict,
|
|
'config-drive': bool,
|
|
}
|
|
|
|
provider = {
|
|
'name': str,
|
|
'region-name': str,
|
|
v.Required('cloud'): str,
|
|
'max-concurrency': int,
|
|
'boot-timeout': int,
|
|
'launch-timeout': int,
|
|
'launch-retries': int,
|
|
'nodepool-id': str,
|
|
'rate': float,
|
|
'hostname-format': str,
|
|
'image-name-format': str,
|
|
'clean-floating-ips': bool,
|
|
'pools': [pool],
|
|
'diskimages': [provider_diskimage],
|
|
}
|
|
|
|
label = {
|
|
'name': str,
|
|
'min-ready': int,
|
|
}
|
|
|
|
diskimage = {
|
|
'name': str,
|
|
'pause': bool,
|
|
'elements': [str],
|
|
'formats': [str],
|
|
'release': v.Any(str, int),
|
|
'rebuild-age': int,
|
|
'env-vars': {str: str},
|
|
}
|
|
|
|
top_level = {
|
|
'elements-dir': str,
|
|
'images-dir': str,
|
|
'zookeeper-servers': [{
|
|
'host': str,
|
|
'port': int,
|
|
'chroot': str,
|
|
}],
|
|
'providers': [provider],
|
|
'labels': [label],
|
|
'diskimages': [diskimage],
|
|
}
|
|
|
|
log.info("validating %s" % self.config_file)
|
|
config = yaml.load(open(self.config_file))
|
|
|
|
# validate the overall schema
|
|
schema = v.Schema(top_level)
|
|
schema(config)
|