From 0bb23f06dc12422b032ec081caf99ef6d2218fef Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 17 Aug 2017 19:01:29 +0800 Subject: Modify schemas.py 1. add schemas for elements added recently in deploy.yml 2. remove daisy_ip from required list, prepare for generate it auto 3. add main() function to make this file useful in bash Change-Id: Ic7a3a87305f96b064260967862f976e33cdea294 Signed-off-by: Alex Yang --- deploy/config/schemas.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/deploy/config/schemas.py b/deploy/config/schemas.py index d2fd7ef6..3096d017 100644 --- a/deploy/config/schemas.py +++ b/deploy/config/schemas.py @@ -8,6 +8,8 @@ ############################################################################## from jsonschema import Draft4Validator, FormatChecker +import sys +import yaml MIN_DAISY_DISK_SIZE = 50 @@ -28,8 +30,19 @@ hosts_schema = { 'enum': ['COMPUTER', 'CONTROLLER_LB', 'CONTROLLER_HA'] } }, - 'template': {'type': 'string', 'minLength': 1} - } + 'template': {'type': 'string', 'minLength': 1}, + 'ipmi_ip': {'type': 'string', 'format': 'ip-address'}, + 'ipmi_user': {'type': 'string'}, + 'ipmi_pass': {'type': 'string'}, + 'mac_addresses': { + 'type': 'array', + 'items': { + 'type': 'string', + 'pattern': '^([0-9a-fA-F]{2})((:[0-9a-fA-F]{2}){5})$' + } + } + }, + 'required': ['roles'] } } @@ -51,12 +64,13 @@ schema_mapping = { 'daisy_ip': {'type': 'string', 'format': 'ip-address'}, 'daisy_gateway': {'type': 'string', 'format': 'ip-address'}, 'ceph_disk_name': {'type': 'string'}, + 'modules': {'type': ['array', 'null']} } deploy_schema = { 'type': 'object', 'properties': schema_mapping, - 'required': ['hosts', 'daisy_passwd', 'daisy_ip', 'daisy_gateway'] + 'required': ['hosts', 'daisy_passwd', 'daisy_gateway'] } @@ -75,3 +89,19 @@ def item_validate(data, schema_type): def deploy_schema_validate(data): return _validate(data, deploy_schema) + + +def _main(): + if 2 != len(sys.argv): + sys.exit(1) + try: + data = yaml.safe_load(open(sys.argv[1], 'r')) + errors = deploy_schema_validate(data) + except Exception as e: + errors = 'Exception occured: ' + str(e) + if errors: + sys.exit(errors) + + +if __name__ == '__main__': + _main() -- cgit 1.2.3-korg