Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-cfggen] add option for redis connection #1213

Merged
merged 1 commit into from
Dec 7, 2017
Merged
Changes from all commits
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
9 changes: 7 additions & 2 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def main():
parser.add_argument("-j", "--json", help="json file that contains additional variables", action='append', default=[])
parser.add_argument("-a", "--additional-data", help="addition data, in json string")
parser.add_argument("-d", "--from-db", help="read config from configdb", action='store_true')
parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection")
group = parser.add_mutually_exclusive_group()
group.add_argument("-t", "--template", help="render the data with the template file")
group.add_argument("-v", "--var", help="print the value of a variable, support jinja2 expression")
Expand All @@ -151,6 +152,10 @@ def main():
if platform_info != None:
data['platform'] = platform_info

db_kwargs = {}
if args.redis_unix_sock_file != None:
db_kwargs['unix_socket_path'] = args.redis_unix_sock_file

if args.minigraph != None:
minigraph = args.minigraph
if data.has_key('platform'):
Expand Down Expand Up @@ -180,7 +185,7 @@ def main():
deep_update(data, json.loads(args.additional_data))

if args.from_db:
configdb = ConfigDBConnector()
configdb = ConfigDBConnector(**db_kwargs)
configdb.connect()
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))

Expand All @@ -203,7 +208,7 @@ def main():
print json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder)

if args.write_to_db:
configdb = ConfigDBConnector()
configdb = ConfigDBConnector(**db_kwargs)
configdb.connect(False)
configdb.set_config(FormatConverter.output_to_db(data))

Expand Down