From fb09a7ed97707b6a007721ff4b72a904c4204e93 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 9 May 2017 11:11:53 +0800 Subject: refacort deploy.yml and add jsonschema to validate it 1. add adapter type in deploy.yml Do not rely on the pod's name to detemine whether impi or libvirt should be used. 2. increase disk size in deploy.yml The disk sizes should be bigger than 102400 mega-bytes according to the minimum of root_lv_size in upstream openstack/daisycloud-core. 3. add schemas.py Use jsonschema to validate deploy.yml Change-Id: I3f197f93403caece75460147c8df49b95e0ae9d3 Signed-off-by: Alex Yang --- .../bm_environment/zte-baremetal1/deploy.yml | 3 +- deploy/config/schemas.py | 74 ++++++++++++++++++++++ .../config/vm_environment/zte-virtual1/deploy.yml | 5 +- .../config/vm_environment/zte-virtual2/deploy.yml | 5 +- 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 deploy/config/schemas.py (limited to 'deploy/config') diff --git a/deploy/config/bm_environment/zte-baremetal1/deploy.yml b/deploy/config/bm_environment/zte-baremetal1/deploy.yml index 58516e88..d24a9569 100644 --- a/deploy/config/bm_environment/zte-baremetal1/deploy.yml +++ b/deploy/config/bm_environment/zte-baremetal1/deploy.yml @@ -1,3 +1,4 @@ +adapter: ipmi hosts: - name: 'controller01' roles: @@ -16,8 +17,6 @@ hosts: - 'COMPUTER' disks: daisy: 50 - controller: 50 - compute: 50 daisy_passwd: 'r00tme' daisy_ip: '10.20.7.3' daisy_gateway: '10.20.7.1' diff --git a/deploy/config/schemas.py b/deploy/config/schemas.py new file mode 100644 index 00000000..52ded2b4 --- /dev/null +++ b/deploy/config/schemas.py @@ -0,0 +1,74 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from jsonschema import Draft4Validator, FormatChecker + + +MIN_DAISY_DISK_SIZE = 50 +# minimal size of root_lv_size is 102400 mega-bytes +MIN_NODE_DISK_SIZE = 110 + +hosts_schema = { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'name': {'type': 'string', 'minLength': 1}, + 'roles': { + 'type': 'array', + 'items': { + 'type': 'string', + 'enum': ['COMPUTER', 'CONTROLLER_LB', 'CONTROLLER_HA'] + } + } + } + } +} + +disks_schema = { + 'type': 'object', + 'properties': { + 'daisy': {'type': 'integer', 'minimum': MIN_DAISY_DISK_SIZE}, + 'controller': {'type': 'integer', 'minimum': MIN_NODE_DISK_SIZE}, + 'compute': {'type': 'integer', 'minimum': MIN_NODE_DISK_SIZE} + } +} + +schema_mapping = { + 'adapter': {'type': 'string', 'enum': ['ipmi', 'libvirt']}, + 'hosts': hosts_schema, + 'disks': disks_schema, + 'daisy_passwd': {'type': 'string'}, + 'daisy_ip': {'type': 'string', 'format': 'ip-address'}, + 'daisy_gateway': {'type': 'string', 'format': 'ip-address'}, + 'ceph_disk_name': {'type': 'string'}, +} + +deploy_schema = { + 'type': 'object', + 'properties': schema_mapping, + 'required': ['hosts', 'daisy_passwd', 'daisy_ip', 'daisy_gateway'] +} + + +def _validate(data, schema): + v = Draft4Validator(schema, format_checker=FormatChecker()) + errors = sorted(v.iter_errors(data), key=lambda e: e.path) + return errors + + +def item_validate(data, schema_type): + if schema_type not in schema_mapping: + return str('Schema Type %s does not exist' % schema_type) + else: + return _validate(data, schema_mapping.get(schema_type)) + + +def deploy_schema_validate(data): + return _validate(data, deploy_schema) diff --git a/deploy/config/vm_environment/zte-virtual1/deploy.yml b/deploy/config/vm_environment/zte-virtual1/deploy.yml index 14508fae..0b3a2c52 100644 --- a/deploy/config/vm_environment/zte-virtual1/deploy.yml +++ b/deploy/config/vm_environment/zte-virtual1/deploy.yml @@ -1,3 +1,4 @@ +adapter: libvirt hosts: - name: 'all_in_one' roles: @@ -5,8 +6,8 @@ hosts: - 'COMPUTER' disks: daisy: 50 - controller: 50 - compute: 50 + controller: 110 + compute: 110 daisy_passwd: 'r00tme' daisy_ip: '10.20.11.2' daisy_gateway: '10.20.11.1' diff --git a/deploy/config/vm_environment/zte-virtual2/deploy.yml b/deploy/config/vm_environment/zte-virtual2/deploy.yml index f2c8ac11..e086e7cf 100644 --- a/deploy/config/vm_environment/zte-virtual2/deploy.yml +++ b/deploy/config/vm_environment/zte-virtual2/deploy.yml @@ -1,3 +1,4 @@ +adapter: libvirt hosts: - name: 'controller01' roles: @@ -16,8 +17,8 @@ hosts: - 'COMPUTER' disks: daisy: 50 - controller: 50 - compute: 50 + controller: 110 + compute: 110 daisy_passwd: 'r00tme' daisy_ip: '10.20.11.2' daisy_gateway: '10.20.11.1' -- cgit 1.2.3-korg