Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -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=[])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel this is error prone. can we do this check this outside sonic-cfggen?

like [ -f $file ] && sonic-cfggen -y $file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we are doing now.

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")
Expand Down Expand Up @@ -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))

Expand Down