Clean up logging a little bit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
build/
|
||||
dist/
|
||||
hippo*.yaml
|
||||
__pycache__
|
||||
|
@ -60,15 +60,10 @@ class IPInterfaceWithPrefixLength(Validator):
|
||||
|
||||
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
|
||||
class Validator(object):
|
||||
def __init__(self, schema):
|
||||
self.logger = logging.getLogger('vppcfg.validator')
|
||||
self.logger.addHandler(NullHandler())
|
||||
self.logger.addHandler(logging.NullHandler())
|
||||
|
||||
self.schema = schema
|
||||
|
||||
@ -131,3 +126,19 @@ class Validator(object):
|
||||
if ret_rv:
|
||||
self.logger.debug("Semantics correctly validated")
|
||||
return ret_rv, ret_msgs
|
||||
|
||||
def valid_config(self, yaml):
|
||||
""" Validate the given YAML configuration in 'yaml' against syntax
|
||||
validation given in the yamale 'schema', and all semantic validators.
|
||||
|
||||
Returns True if the configuration is valid, False otherwise.
|
||||
"""
|
||||
|
||||
rv, msgs = self.validate(yaml)
|
||||
if not rv:
|
||||
for m in msgs:
|
||||
self.logger.error(m)
|
||||
return False
|
||||
|
||||
self.logger.info("Configuration validated successfully")
|
||||
return True
|
||||
|
@ -14,11 +14,6 @@
|
||||
import logging
|
||||
import validator.interface as interface
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
|
||||
def get_by_name(yaml, ifname):
|
||||
""" Return the BondEthernet by name, if it exists. Return None,None otherwise. """
|
||||
try:
|
||||
@ -52,7 +47,7 @@ def validate_bondethernets(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.validator')
|
||||
logger.addHandler(NullHandler())
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'bondethernets' in yaml:
|
||||
return result, msgs
|
||||
|
@ -16,11 +16,6 @@ import validator.interface as interface
|
||||
import validator.lcp as lcp
|
||||
import validator.address as address
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
|
||||
def get_bridgedomains(yaml):
|
||||
""" Return a list of all bridgedomains. """
|
||||
ret = []
|
||||
@ -94,7 +89,7 @@ def validate_bridgedomains(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.validator')
|
||||
logger.addHandler(NullHandler())
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'bridgedomains' in yaml:
|
||||
return result, msgs
|
||||
|
@ -19,10 +19,6 @@ import validator.vxlan_tunnel as vxlan_tunnel
|
||||
import validator.lcp as lcp
|
||||
import validator.address as address
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
def get_qinx_parent_by_name(yaml, ifname):
|
||||
""" Returns the sub-interface which matches a QinAD or QinQ outer tag, or None,None
|
||||
if that sub-interface doesn't exist. """
|
||||
@ -389,7 +385,7 @@ def validate_interfaces(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.validator')
|
||||
logger.addHandler(NullHandler())
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'interfaces' in yaml:
|
||||
return result, msgs
|
||||
|
@ -15,10 +15,6 @@ import logging
|
||||
import validator.lcp as lcp
|
||||
import validator.address as address
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
def get_loopbacks(yaml):
|
||||
""" Return a list of all loopbacks. """
|
||||
ret = []
|
||||
@ -48,7 +44,7 @@ def validate_loopbacks(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.validator')
|
||||
logger.addHandler(NullHandler())
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'loopbacks' in yaml:
|
||||
return result, msgs
|
||||
|
@ -15,11 +15,6 @@ import logging
|
||||
import validator.interface as interface
|
||||
import ipaddress
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
|
||||
def get_by_name(yaml, ifname):
|
||||
""" Return the VXLAN by name, if it exists. Return None otherwise. """
|
||||
try:
|
||||
@ -64,7 +59,7 @@ def validate_vxlan_tunnels(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
logger = logging.getLogger('vppcfg.validator')
|
||||
logger.addHandler(NullHandler())
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
if not 'vxlan_tunnels' in yaml:
|
||||
return result, msgs
|
||||
|
@ -9,22 +9,16 @@ import fnmatch
|
||||
import logging
|
||||
import socket
|
||||
|
||||
|
||||
class NullHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
class VPPApi():
|
||||
def __init__(self, address='/run/vpp/api.sock', clientname='vppcfg'):
|
||||
self.logger = logging.getLogger('%s.vppapi' % clientname)
|
||||
self.logger.addHandler(NullHandler())
|
||||
self.logger = logging.getLogger('vppcfg.vppapi')
|
||||
self.logger.addHandler(logging.NullHandler())
|
||||
|
||||
self.address = address
|
||||
self.connected = False
|
||||
self.clientname = clientname
|
||||
self.vpp = None
|
||||
self.config = {}
|
||||
self.clearconfig()
|
||||
self.config = self.clearconfig()
|
||||
|
||||
|
||||
def connect(self):
|
||||
@ -66,7 +60,7 @@ class VPPApi():
|
||||
return True
|
||||
|
||||
def clearconfig(self):
|
||||
self.config = {"lcps": {}, "interfaces": {}, "interface_addresses": {},
|
||||
return {"lcps": {}, "interfaces": {}, "interface_addresses": {},
|
||||
"bondethernets": {}, "bondethernet_members": {},
|
||||
"bridgedomains": {}, "vxlan_tunnels": {}, "l2xcs": {}}
|
||||
|
||||
|
12
vppcfg
12
vppcfg
@ -35,6 +35,7 @@ def main():
|
||||
parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help="""Be quiet (only log warnings/errors), default False""")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
level = logging.INFO
|
||||
if args.debug:
|
||||
level = logging.DEBUG
|
||||
@ -51,13 +52,10 @@ def main():
|
||||
logging.error("Couldn't read config from %s" % args.config)
|
||||
sys.exit(-1)
|
||||
|
||||
v = Validator(schema=args.schema)
|
||||
rv, msgs = v.validate(cfg)
|
||||
if not rv:
|
||||
for m in msgs:
|
||||
logging.error(m)
|
||||
else:
|
||||
logging.info("Configuration validated successfully")
|
||||
validator = Validator(schema=args.schema)
|
||||
if not validator.valid_config(cfg):
|
||||
logging.error("Configuration is not valid, bailing")
|
||||
sys.exit(-2)
|
||||
|
||||
vpp = VPPApi()
|
||||
vpp.readconfig()
|
||||
|
Reference in New Issue
Block a user