diff --git a/intest/intest.sh b/intest/intest.sh index b15349a..d28967d 100755 --- a/intest/intest.sh +++ b/intest/intest.sh @@ -11,19 +11,19 @@ for i in hippo[0-9]*.yaml; do echo "Clearing: Moving to hippo-empty.yaml" - ../vppcfg -s ../schema.yaml -c hippo-empty.yaml plan -o /tmp/vppcfg-exec-empty + ../vppcfg plan -s ../schema.yaml -c hippo-empty.yaml -o /tmp/vppcfg-exec-empty [ -s /tmp/vppcfg-exec-empty ] && vppctl exec /tmp/vppcfg-exec-empty for j in hippo[0-9]*.yaml; do echo " - Moving to $i .. " - ../vppcfg -s ../schema.yaml -c $i plan -o /tmp/vppcfg-exec_$i + ../vppcfg plan -s ../schema.yaml -c $i -o /tmp/vppcfg-exec_$i [ -s /tmp/vppcfg-exec_$i ] && vppctl exec /tmp/vppcfg-exec_$i echo " - Moving from $i to $j" - ../vppcfg -s ../schema.yaml -c $j plan -o /tmp/vppcfg-exec_${i}_${j} + ../vppcfg plan -s ../schema.yaml -c $j -o /tmp/vppcfg-exec_${i}_${j} [ -s /tmp/vppcfg-exec_${i}_${j} ] && vppctl exec /tmp/vppcfg-exec_${i}_${j} echo " - Checking that from $j to $j is empty" - ../vppcfg -s ../schema.yaml -c $j plan -o /tmp/vppcfg-exec_${j}_${j}_null + ../vppcfg plan -s ../schema.yaml -c $j -o /tmp/vppcfg-exec_${j}_${j}_null done done diff --git a/vpp/vppapi.py b/vpp/vppapi.py index c0ed287..4c9e5f9 100644 --- a/vpp/vppapi.py +++ b/vpp/vppapi.py @@ -233,12 +233,6 @@ class VPPApi(): ret = False return ret - def dump(self): - self.dump_interfaces() - self.dump_bridgedomains() - self.dump_phys() - self.dump_subints() - def get_sub_interfaces(self): subints = [self.cache['interfaces'][x].interface_name for x in self.cache['interfaces'] if self.cache['interfaces'][x].sub_id>0 and self.cache['interfaces'][x].sub_number_of_tags > 0] return subints @@ -273,6 +267,17 @@ class VPPApi(): return lcp return None +class VPPApiDumper(VPPApi): + def __init__(self, address='/run/vpp/api.sock', clientname='vppcfg'): + VPPApi.__init__(self, address, clientname) + self.readconfig() + + def dump(self): + self.dump_phys() + self.dump_interfaces() + self.dump_subints() + self.dump_bridgedomains() + def dump_phys(self): phys = self.get_phys() for ifname in phys: @@ -280,17 +285,15 @@ class VPPApi(): self.logger.info("%s idx=%d" % (iface.interface_name, iface.sw_if_index)) def dump_subints(self): - self.logger.info("*** QinX ***") subints = self.get_qinx_interfaces() for ifname in subints: iface = self.cache['interface_names'][ifname] - self.logger.info("%s idx=%d encap=%s" % (iface.interface_name, iface.sw_if_index, self.get_encapsulation(iface))) - - self.logger.info("*** .1q/.1ad ***") + self.logger.info("%s tags=2 idx=%d encap=%s" % (iface.interface_name, iface.sw_if_index, self.get_encapsulation(iface))) + subints = self.get_dot1x_interfaces() for ifname in subints: iface = self.cache['interface_names'][ifname] - self.logger.info("%s idx=%d encap=%s" % (iface.interface_name, iface.sw_if_index, self.get_encapsulation(iface))) + self.logger.info("%s tags=1 idx=%d encap=%s" % (iface.interface_name, iface.sw_if_index, self.get_encapsulation(iface))) def dump_bridgedomains(self): for bd_id, bridge in self.cache['bridgedomains'].items(): diff --git a/vppcfg b/vppcfg index d3df2d8..8228413 100755 --- a/vppcfg +++ b/vppcfg @@ -19,6 +19,7 @@ import yaml import logging from config import Validator from vpp.reconciler import Reconciler +from vpp.vppapi import VPPApiDumper try: import argparse @@ -29,29 +30,43 @@ except ImportError: def main(): parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument('-s', '--schema', dest='schema', type=str, default='./schema.yaml', help="""YAML schema validation file""") - parser.add_argument('-d', '--debug', dest='debug', action='store_true', help="""Enable debug logging, default False""") - parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help="""Be quiet (only warnings/errors), default False""") - parser.add_argument('-f', '--force', dest='force', action='store_true', help="""Force progress despite warnings, default False""") - parser.add_argument('-c', '--config', dest='config', required=True, type=str, help="""YAML configuration file for vppcfg""") + parser.add_argument('-d', '--debug', dest='debug', action='store_true', help="""enable debug logging, default False""") + parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help="""be quiet (only warnings/errors), default False""") + parser.add_argument('-f', '--force', dest='force', action='store_true', help="""force progress despite warnings, default False""") subparsers = parser.add_subparsers(dest='command') - check_p = subparsers.add_parser('check') + check_p = subparsers.add_parser('check', help="check given YAML config for validity (no VPP)") + check_p.add_argument('-s', '--schema', dest='schema', type=str, default='./schema.yaml', help="""YAML schema validation file""") + check_p.add_argument('-c', '--config', dest='config', required=True, type=str, help="""YAML configuration file for vppcfg""") - plan_p = subparsers.add_parser('plan') + dump_p = subparsers.add_parser('dump', help="dump current running VPP configuration (VPP readonly)") + + plan_p = subparsers.add_parser('plan', help="plan changes from current VPP dataplane to target config (VPP readonly)") + plan_p.add_argument('-s', '--schema', dest='schema', type=str, default='./schema.yaml', help="""YAML schema validation file""") + plan_p.add_argument('-c', '--config', dest='config', required=True, type=str, help="""YAML configuration file for vppcfg""") plan_p.add_argument('-o', '--output', dest='outfile', required=False, default='-', type=str, help="""Output file for VPP CLI commands, default stdout""") - apply_p = subparsers.add_parser('apply') + apply_p = subparsers.add_parser('apply', help="apply changes from current VPP dataplane to target config") + apply_p.add_argument('-s', '--schema', dest='schema', type=str, default='./schema.yaml', help="""YAML schema validation file""") + apply_p.add_argument('-c', '--config', dest='config', required=True, type=str, help="""YAML configuration file for vppcfg""") args = parser.parse_args() + if not args.command: + parser.print_help() + print("\nPlease see vppcfg -h for per-command arguments") + sys.exit(0) + level = logging.INFO if args.debug: level = logging.DEBUG if args.quiet: level = logging.WARNING logging.basicConfig(format='[%(levelname)-8s] %(name)s.%(funcName)s: %(message)s', level=level) - if not args.command: - args.command="check" ## Default check-only + + if args.command=="dump": + d = VPPApiDumper() + d.dump() + sys.exit(0) try: with open(args.config, "r") as f: