summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-07-17 17:17:34 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-07-17 17:17:34 +0000
commitb07e491d2b69a25ab6dc5e56f6ba8b84d54867a9 (patch)
treedc16085a584cf4b0a40e4926cd16ead50456b2ed
parent90e3ade7c3bba5542bf2c39dc4adb44fab9cd8ff (diff)
downloadvyos-cloud-init-b07e491d2b69a25ab6dc5e56f6ba8b84d54867a9.tar.gz
vyos-cloud-init-b07e491d2b69a25ab6dc5e56f6ba8b84d54867a9.zip
tools: add '--debug' to tools/net-convert.py
In order to see some of the WARNING messages added by bug 1774666 I wanted logging output of tools/net-convert. This does: a.) add '--debug' and make it print the network state and read yaml only if --debug is provided. b.) set up basic logging so warnings goes to console by default and debug goes to console if --debug is provided.
-rwxr-xr-xtools/net-convert.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/tools/net-convert.py b/tools/net-convert.py
index 68559cbf..d1a4a646 100755
--- a/tools/net-convert.py
+++ b/tools/net-convert.py
@@ -4,11 +4,13 @@
import argparse
import json
import os
+import sys
import yaml
from cloudinit.sources.helpers import openstack
from cloudinit.net import eni
+from cloudinit import log
from cloudinit.net import netplan
from cloudinit.net import network_state
from cloudinit.net import sysconfig
@@ -29,14 +31,23 @@ def main():
metavar="name,mac",
action='append',
help="interface name to mac mapping")
+ parser.add_argument("--debug", action='store_true',
+ help='enable debug logging to stderr.')
parser.add_argument("--output-kind", "-ok",
choices=['eni', 'netplan', 'sysconfig'],
required=True)
args = parser.parse_args()
+ if not args.directory.endswith("/"):
+ args.directory += "/"
+
if not os.path.isdir(args.directory):
os.makedirs(args.directory)
+ if args.debug:
+ log.setupBasicLogging(level=log.DEBUG)
+ else:
+ log.setupBasicLogging(level=log.WARN)
if args.mac:
known_macs = {}
for item in args.mac:
@@ -53,8 +64,10 @@ def main():
pre_ns = yaml.load(net_data)
if 'network' in pre_ns:
pre_ns = pre_ns.get('network')
- print("Input YAML")
- print(yaml.dump(pre_ns, default_flow_style=False, indent=4))
+ if args.debug:
+ sys.stderr.write('\n'.join(
+ ["Input YAML",
+ yaml.dump(pre_ns, default_flow_style=False, indent=4), ""]))
ns = network_state.parse_net_config_data(pre_ns)
else:
pre_ns = openstack.convert_net_json(
@@ -65,8 +78,10 @@ def main():
raise RuntimeError("No valid network_state object created from"
"input data")
- print("\nInternal State")
- print(yaml.dump(ns, default_flow_style=False, indent=4))
+ if args.debug:
+ sys.stderr.write('\n'.join([
+ "", "Internal State",
+ yaml.dump(ns, default_flow_style=False, indent=4), ""]))
if args.output_kind == "eni":
r_cls = eni.Renderer
elif args.output_kind == "netplan":
@@ -75,6 +90,11 @@ def main():
r_cls = sysconfig.Renderer
r = r_cls()
+ sys.stderr.write(''.join([
+ "Read input format '%s' from '%s'.\n" % (
+ args.kind, args.network_data.name),
+ "Wrote output format '%s' to '%s'\n" % (
+ args.output_kind, args.directory)]) + "\n")
r.render_network_state(network_state=ns, target=args.directory)