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

Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
This commit is contained in:
Wataru Ishida 2017-12-07 14:45:03 +09:00 committed by lguohan
parent eb086818d7
commit 3d70b715d5

View File

@ -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))