summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2017-03-19 08:39:01 -0500
committerScott Moser <smoser@brickies.net>2017-03-20 15:59:03 -0400
commitef18b8ac4cf7e3dfd98830fbdb298380a192a0fc (patch)
tree19806d975057906806bd4e62b795e77a7a6af3c4 /tools
parent9040e78feb7c1bcf3a1dab0ee163efaa0d21612c (diff)
downloadvyos-cloud-init-ef18b8ac4cf7e3dfd98830fbdb298380a192a0fc.tar.gz
vyos-cloud-init-ef18b8ac4cf7e3dfd98830fbdb298380a192a0fc.zip
cloudinit.net: add network config v2 parsing and rendering
Network configuration version 2 format is implemented in a package called netplan (nplan)[1] which allows consolidated network config for multiple network controllers. - Add a new netplan renderer - Update default policy, placing eni and sysconfig first This requires explicit policy to enable netplan over eni on systems which have both (Yakkety, Zesty, UC16) - Allow any network state (parsed from any format cloud-init supports) to render to v2 if system supports netplan. - Move eni's _subnet_is_ipv6 to common code for use by other renderers - Make sysconfig renderer always emit /etc/syconfig/network configuration - Update cloud-init.service systemd unit to also wait on systemd-networkd-wait-online.service 1. https://lists.ubuntu.com/archives/ubuntu-devel/2016-July/039464.html
Diffstat (limited to 'tools')
-rwxr-xr-xtools/net-convert.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/tools/net-convert.py b/tools/net-convert.py
new file mode 100755
index 00000000..870da639
--- /dev/null
+++ b/tools/net-convert.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python3
+# This file is part of cloud-init. See LICENSE file for license information.
+
+import argparse
+import json
+import os
+import yaml
+
+from cloudinit.sources.helpers import openstack
+
+from cloudinit.net import eni
+from cloudinit.net import network_state
+from cloudinit.net import netplan
+from cloudinit.net import sysconfig
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--network-data", "-p", type=open,
+ metavar="PATH", required=True)
+ parser.add_argument("--kind", "-k",
+ choices=['eni', 'network_data.json', 'yaml'],
+ required=True)
+ parser.add_argument("-d", "--directory",
+ metavar="PATH",
+ help="directory to place output in",
+ required=True)
+ parser.add_argument("-m", "--mac",
+ metavar="name,mac",
+ action='append',
+ help="interface name to mac mapping")
+ parser.add_argument("--output-kind", "-ok",
+ choices=['eni', 'netplan', 'sysconfig'],
+ required=True)
+ args = parser.parse_args()
+
+ if not os.path.isdir(args.directory):
+ os.makedirs(args.directory)
+
+ if args.mac:
+ known_macs = {}
+ for item in args.mac:
+ iface_name, iface_mac = item.split(",", 1)
+ known_macs[iface_mac] = iface_name
+ else:
+ known_macs = None
+
+ net_data = args.network_data.read()
+ if args.kind == "eni":
+ pre_ns = eni.convert_eni_data(net_data)
+ ns = network_state.parse_net_config_data(pre_ns)
+ elif args.kind == "yaml":
+ 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))
+ ns = network_state.parse_net_config_data(pre_ns)
+ else:
+ pre_ns = openstack.convert_net_json(
+ json.loads(net_data), known_macs=known_macs)
+ ns = network_state.parse_net_config_data(pre_ns)
+
+ if not ns:
+ 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.output_kind == "eni":
+ r_cls = eni.Renderer
+ elif args.output_kind == "netplan":
+ r_cls = netplan.Renderer
+ else:
+ r_cls = sysconfig.Renderer
+
+ r = r_cls()
+ r.render_network_state(ns, target=args.directory)
+
+
+if __name__ == '__main__':
+ main()
+
+# vi: ts=4 expandtab