From b6bda2fe154d067084a99733f42663252ff9b399 Mon Sep 17 00:00:00 2001 From: Dan Radez Date: Mon, 19 Sep 2016 15:06:43 -0400 Subject: Handling file loads and tmp dirs differently Change-Id: I602279b30b035cfc667e4ee9b83905a638440abb Signed-off-by: Dan Radez --- lib/python/apex/common/utils.py | 2 +- lib/python/apex/deploy_settings.py | 2 +- lib/python/apex/inventory.py | 2 +- lib/python/apex/network_environment.py | 2 +- lib/python/apex/network_settings.py | 2 +- lib/python/apex_python_utils.py | 11 +++++++++-- 6 files changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/python') diff --git a/lib/python/apex/common/utils.py b/lib/python/apex/common/utils.py index fe34096d..d623638c 100644 --- a/lib/python/apex/common/utils.py +++ b/lib/python/apex/common/utils.py @@ -19,5 +19,5 @@ def str2bool(var): def parse_yaml(yaml_file): with open(yaml_file) as f: - parsed_dict = yaml.load(f) + parsed_dict = yaml.safe_load(f) return parsed_dict diff --git a/lib/python/apex/deploy_settings.py b/lib/python/apex/deploy_settings.py index b70efdac..c27eecf9 100644 --- a/lib/python/apex/deploy_settings.py +++ b/lib/python/apex/deploy_settings.py @@ -40,7 +40,7 @@ class DeploySettings(dict): init_dict = {} if type(filename) is str: with open(filename, 'r') as deploy_settings_file: - init_dict = yaml.load(deploy_settings_file) + init_dict = yaml.safe_load(deploy_settings_file) else: # assume input is a dict to build from init_dict = filename diff --git a/lib/python/apex/inventory.py b/lib/python/apex/inventory.py index f4a33b28..aa219680 100644 --- a/lib/python/apex/inventory.py +++ b/lib/python/apex/inventory.py @@ -24,7 +24,7 @@ class Inventory(dict): init_dict = {} if type(source) is str: with open(source, 'r') as network_settings_file: - yaml_dict = yaml.load(network_settings_file) + yaml_dict = yaml.safe_load(network_settings_file) # collapse node identifiers from the structure init_dict['nodes'] = list(map(lambda n: n[1], yaml_dict['nodes'].items())) diff --git a/lib/python/apex/network_environment.py b/lib/python/apex/network_environment.py index 175f408f..15fe873f 100644 --- a/lib/python/apex/network_environment.py +++ b/lib/python/apex/network_environment.py @@ -59,7 +59,7 @@ class NetworkEnvironment(dict): init_dict = {} if type(filename) is str: with open(filename, 'r') as net_env_fh: - init_dict = yaml.load(net_env_fh) + init_dict = yaml.safe_load(net_env_fh) super().__init__(init_dict) try: diff --git a/lib/python/apex/network_settings.py b/lib/python/apex/network_settings.py index ca91b8cf..8e39afd6 100644 --- a/lib/python/apex/network_settings.py +++ b/lib/python/apex/network_settings.py @@ -42,7 +42,7 @@ class NetworkSettings(dict): init_dict = {} if type(filename) is str: with open(filename, 'r') as network_settings_file: - init_dict = yaml.load(network_settings_file) + init_dict = yaml.safe_load(network_settings_file) else: # assume input is a dict to build from init_dict = filename diff --git a/lib/python/apex_python_utils.py b/lib/python/apex_python_utils.py index ebc49dc5..9d6110bb 100755 --- a/lib/python/apex_python_utils.py +++ b/lib/python/apex_python_utils.py @@ -43,7 +43,9 @@ def parse_net_settings(args): net_env = NetworkEnvironment(settings, args.net_env_file, args.compute_pre_config, args.controller_pre_config) - dump_yaml(dict(net_env), '/tmp/network-environment.yaml') + target = args.target_dir.split('/') + target.append('network-environment.yaml') + dump_yaml(dict(net_env), '/'.join(target)) settings.dump_bash() @@ -108,7 +110,7 @@ def build_nic_template(args): netsets = NetworkSettings(args.net_settings_file, args.network_isolation) - env = Environment(loader=FileSystemLoader(template_dir)) + env = Environment(loader=FileSystemLoader(template_dir), autoescape=True) template = env.get_template(template) # gather vlan values into a dict @@ -148,6 +150,11 @@ def get_parser(): default="network-environment.yaml", dest='net_env_file', help='path to network environment file') + net_settings.add_argument('-td', '--target-dir', + default="/tmp", + dest='target_dir', + help='directory to write the' + 'network-environment.yaml file') net_settings.add_argument('--compute-pre-config', default=False, action='store_true', -- cgit 1.2.3-korg