From 98a0a5a9652a87581f6b77e0e946c8ce2854da09 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Tue, 20 Jun 2017 21:59:01 +0000 Subject: [PATCH 1/2] [sonic-cfggen] Support multiple -y option and an optional -Y option --- src/sonic-config-engine/sonic-cfggen | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 822f02d7fcc2..06c73b5f3a2b 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -49,7 +49,8 @@ def main(): parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.") parser.add_argument("-m", "--minigraph", help="minigraph xml file") parser.add_argument("-p", "--port-config", help="port config file, used with -m") - parser.add_argument("-y", "--yaml", help="yaml file that contains addtional variables") + parser.add_argument("-y", "--yaml", help="yaml file that contains addtional variables", action='append', default=[]) + parser.add_argument("-Y", "--optional-yaml", help="optional yaml file that contains addtional variables", action='append', default=[]) parser.add_argument("-a", "--additional-data", help="addition data, in json string") group = parser.add_mutually_exclusive_group() group.add_argument("-t", "--template", help="render the data with the template file") @@ -79,11 +80,17 @@ def main(): else: data.update(parse_xml(minigraph)) - if args.yaml != None: - with open(args.yaml, 'r') as stream: + for yaml_file in args.yaml: + with open(yaml_file, 'r') as stream: additional_data = yaml.load(stream) data.update(additional_data) + for optional_yaml in args.optional_yaml: + if os.path.isfile(optional_yaml): + with open(optional_yaml, 'r') as stream: + additional_data = yaml.load(stream) + data.update(additional_data) + if args.additional_data != None: data.update(json.loads(args.additional_data)) From dbfa6e3eb780bbfd7083b686eb0e66f40ea84150 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Wed, 21 Jun 2017 18:28:13 +0000 Subject: [PATCH 2/2] Remove optional-yml --- src/sonic-config-engine/sonic-cfggen | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 06c73b5f3a2b..c0ce51d4bf80 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -50,7 +50,6 @@ def main(): parser.add_argument("-m", "--minigraph", help="minigraph xml file") parser.add_argument("-p", "--port-config", help="port config file, used with -m") parser.add_argument("-y", "--yaml", help="yaml file that contains addtional variables", action='append', default=[]) - parser.add_argument("-Y", "--optional-yaml", help="optional yaml file that contains addtional variables", action='append', default=[]) parser.add_argument("-a", "--additional-data", help="addition data, in json string") group = parser.add_mutually_exclusive_group() group.add_argument("-t", "--template", help="render the data with the template file") @@ -85,12 +84,6 @@ def main(): additional_data = yaml.load(stream) data.update(additional_data) - for optional_yaml in args.optional_yaml: - if os.path.isfile(optional_yaml): - with open(optional_yaml, 'r') as stream: - additional_data = yaml.load(stream) - data.update(additional_data) - if args.additional_data != None: data.update(json.loads(args.additional_data))