From 3d70b715d55dde24c7e5591f39b5cc7190be2caf Mon Sep 17 00:00:00 2001 From: Wataru Ishida Date: Thu, 7 Dec 2017 14:45:03 +0900 Subject: [PATCH] [sonic-cfggen] add option for redis connection (#1213) Signed-off-by: Wataru Ishida --- src/sonic-config-engine/sonic-cfggen | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 9f1323dab2..bb778ddefb 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -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") @@ -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'): @@ -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())) @@ -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))