From 68fc16c4fc98d26bbb58cda6ce7945c2ac6d79bc Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Tue, 31 May 2016 17:40:11 -0400 Subject: Migrates network environment parsing to python Change-Id: Ibaf20a2960a9f4b5e3f256fbed12a61d7606a967 Signed-off-by: Tim Rozet --- lib/python/apex-python-utils.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'lib/python/apex-python-utils.py') diff --git a/lib/python/apex-python-utils.py b/lib/python/apex-python-utils.py index 4eee4f75..6c76cb13 100755 --- a/lib/python/apex-python-utils.py +++ b/lib/python/apex-python-utils.py @@ -12,6 +12,7 @@ import sys import apex import logging import os +import yaml from jinja2 import Environment, FileSystemLoader @@ -26,10 +27,24 @@ def parse_net_settings(args): - network_isolation: bool enable or disable network_isolation """ - settings = apex.NetworkSettings(args.file, + settings = apex.NetworkSettings(args.net_settings_file, args.network_isolation) + net_env = apex.NetworkEnvironment(settings, args.net_env_file) + dump_yaml(net_env.get_netenv_settings(), '/tmp/network-environment.yaml') settings.dump_bash() + +def dump_yaml(data, file): + """ + Dumps data to a file as yaml + :param data: yaml to be written to file + :param file: filename to write to + :return: + """ + with open(file, "w") as fh: + yaml.dump(data, fh, default_flow_style=False) + + def parse_deploy_settings(args): settings = apex.DeploySettings(args.file) settings.dump_bash() @@ -84,11 +99,17 @@ def parse_args(): net_settings = subparsers.add_parser('parse-net-settings', help='Parse network settings file') - net_settings.add_argument('-f', '--file', default='network-settings.yaml', + net_settings.add_argument('-s', '--net-settings-file', + default='network-settings.yaml', + dest='net_settings_file', help='path to network settings file') net_settings.add_argument('-i', '--network-isolation', type=bool, default=True, dest='network_isolation', help='network isolation') + net_settings.add_argument('-e', '--net-env-file', + default="network-environment.yaml", + dest='net_env_file', + help='path to network environment file') net_settings.set_defaults(func=parse_net_settings) get_int_ip = subparsers.add_parser('find-ip', -- cgit 1.2.3-korg