Move VPPAPIDumper into its own class.
Create a 'dump' command that calls it and exits vppcfg. Add help strings to each of the commands.
This commit is contained in:
@ -11,19 +11,19 @@
|
|||||||
|
|
||||||
for i in hippo[0-9]*.yaml; do
|
for i in hippo[0-9]*.yaml; do
|
||||||
echo "Clearing: Moving to hippo-empty.yaml"
|
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
|
[ -s /tmp/vppcfg-exec-empty ] && vppctl exec /tmp/vppcfg-exec-empty
|
||||||
|
|
||||||
for j in hippo[0-9]*.yaml; do
|
for j in hippo[0-9]*.yaml; do
|
||||||
echo " - Moving to $i .. "
|
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
|
[ -s /tmp/vppcfg-exec_$i ] && vppctl exec /tmp/vppcfg-exec_$i
|
||||||
|
|
||||||
echo " - Moving from $i to $j"
|
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}
|
[ -s /tmp/vppcfg-exec_${i}_${j} ] && vppctl exec /tmp/vppcfg-exec_${i}_${j}
|
||||||
|
|
||||||
echo " - Checking that from $j to $j is empty"
|
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
|
||||||
done
|
done
|
||||||
|
@ -233,12 +233,6 @@ class VPPApi():
|
|||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def dump(self):
|
|
||||||
self.dump_interfaces()
|
|
||||||
self.dump_bridgedomains()
|
|
||||||
self.dump_phys()
|
|
||||||
self.dump_subints()
|
|
||||||
|
|
||||||
def get_sub_interfaces(self):
|
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]
|
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
|
return subints
|
||||||
@ -273,6 +267,17 @@ class VPPApi():
|
|||||||
return lcp
|
return lcp
|
||||||
return None
|
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):
|
def dump_phys(self):
|
||||||
phys = self.get_phys()
|
phys = self.get_phys()
|
||||||
for ifname in phys:
|
for ifname in phys:
|
||||||
@ -280,17 +285,15 @@ class VPPApi():
|
|||||||
self.logger.info("%s idx=%d" % (iface.interface_name, iface.sw_if_index))
|
self.logger.info("%s idx=%d" % (iface.interface_name, iface.sw_if_index))
|
||||||
|
|
||||||
def dump_subints(self):
|
def dump_subints(self):
|
||||||
self.logger.info("*** QinX ***")
|
|
||||||
subints = self.get_qinx_interfaces()
|
subints = self.get_qinx_interfaces()
|
||||||
for ifname in subints:
|
for ifname in subints:
|
||||||
iface = self.cache['interface_names'][ifname]
|
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=2 idx=%d encap=%s" % (iface.interface_name, iface.sw_if_index, self.get_encapsulation(iface)))
|
||||||
|
|
||||||
self.logger.info("*** .1q/.1ad ***")
|
|
||||||
subints = self.get_dot1x_interfaces()
|
subints = self.get_dot1x_interfaces()
|
||||||
for ifname in subints:
|
for ifname in subints:
|
||||||
iface = self.cache['interface_names'][ifname]
|
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):
|
def dump_bridgedomains(self):
|
||||||
for bd_id, bridge in self.cache['bridgedomains'].items():
|
for bd_id, bridge in self.cache['bridgedomains'].items():
|
||||||
|
35
vppcfg
35
vppcfg
@ -19,6 +19,7 @@ import yaml
|
|||||||
import logging
|
import logging
|
||||||
from config import Validator
|
from config import Validator
|
||||||
from vpp.reconciler import Reconciler
|
from vpp.reconciler import Reconciler
|
||||||
|
from vpp.vppapi import VPPApiDumper
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import argparse
|
import argparse
|
||||||
@ -29,29 +30,43 @@ except ImportError:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
|
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('-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('-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('-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""")
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(dest='command')
|
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""")
|
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()
|
args = parser.parse_args()
|
||||||
|
if not args.command:
|
||||||
|
parser.print_help()
|
||||||
|
print("\nPlease see vppcfg <command> -h for per-command arguments")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
if args.debug:
|
if args.debug:
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
if args.quiet:
|
if args.quiet:
|
||||||
level = logging.WARNING
|
level = logging.WARNING
|
||||||
logging.basicConfig(format='[%(levelname)-8s] %(name)s.%(funcName)s: %(message)s', level=level)
|
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:
|
try:
|
||||||
with open(args.config, "r") as f:
|
with open(args.config, "r") as f:
|
||||||
|
Reference in New Issue
Block a user