Initial commit
This commit is contained in:
48
vppcfg
Executable file
48
vppcfg
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import yaml
|
||||
import logging
|
||||
from validator import Validator
|
||||
|
||||
try:
|
||||
import argparse
|
||||
except ImportError:
|
||||
print("ERROR: install argparse manually: sudo pip install argparse")
|
||||
sys.exit(-2)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
|
||||
parser.add_argument('-c', dest='config', type=str, help="""YAML configuration file for VPP""")
|
||||
parser.add_argument('-s', dest='schema', type=str, default='./schema.yaml', help="""YAML schema validation""")
|
||||
parser.add_argument('-d', dest='debug', action='store_true', help="""Enable debug, default False""")
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.debug:
|
||||
print("Arguments:", args)
|
||||
level = logging.DEBUG
|
||||
else:
|
||||
level = logging.INFO
|
||||
logging.basicConfig(format='[%(levelname)-8s] %(name)s.%(funcName)s: %(message)s', level=level)
|
||||
|
||||
try:
|
||||
with open(args.config, "r") as f:
|
||||
logging.info("Loading configfile %s" % args.config)
|
||||
cfg = yaml.load(f, Loader = yaml.FullLoader)
|
||||
logging.debug("Config: %s" % cfg)
|
||||
except:
|
||||
logging.error("Couldn't read config from %s" % args.config)
|
||||
sys.exit(-1)
|
||||
|
||||
v = Validator(args)
|
||||
rv, msgs = v.validate(cfg)
|
||||
if not rv:
|
||||
for m in msgs:
|
||||
logging.error(m)
|
||||
else:
|
||||
logging.info("Configuration validated successfully")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user