[sonic-cfggen]: Support multiple input yaml files with -y option (#729)

This commit is contained in:
Taoyu Li 2017-06-21 23:49:15 -07:00 committed by Shuotian Cheng
parent 629362cad7
commit a8e3d9745f

View File

@ -49,7 +49,7 @@ def main():
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.") 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("-m", "--minigraph", help="minigraph xml file")
parser.add_argument("-p", "--port-config", help="port config file, used with -m") 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("-a", "--additional-data", help="addition data, in json string") parser.add_argument("-a", "--additional-data", help="addition data, in json string")
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument("-t", "--template", help="render the data with the template file") group.add_argument("-t", "--template", help="render the data with the template file")
@ -79,8 +79,8 @@ def main():
else: else:
data.update(parse_xml(minigraph)) data.update(parse_xml(minigraph))
if args.yaml != None: for yaml_file in args.yaml:
with open(args.yaml, 'r') as stream: with open(yaml_file, 'r') as stream:
additional_data = yaml.load(stream) additional_data = yaml.load(stream)
data.update(additional_data) data.update(additional_data)