Skip to content

Commit 54ebfc8

Browse files
zhenggen-xulguohan
authored andcommitted
Add a "-l/--load-sysinfo" option for "config reload" to merge the system info on device (sonic-net#324)
The information includes: -- platform string -- system mac -- port configuration: alias, lanes, speed, index This is useful when we first load the configuration from config_db.json generated outside which does not have the information on the device. The default behaviour is not changed, so it won't impact the system unless you use this option. This can be used for ZTP to config the box the first time and avoid any addtional work which could cause inconsistency.
1 parent 34810df commit 54ebfc8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

config/main.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,33 @@ def load(filename, yes):
276276

277277
@cli.command()
278278
@click.option('-y', '--yes', is_flag=True)
279+
@click.option('-l', '--load-sysinfo', is_flag=True, help='load system default information (mac, portmap etc) first.')
279280
@click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True))
280-
def reload(filename, yes):
281+
def reload(filename, yes, load_sysinfo):
281282
"""Clear current configuration and import a previous saved config DB dump file."""
282283
if not yes:
283284
click.confirm('Clear current config and reload config from the file %s?' % filename, abort=True)
285+
286+
if load_sysinfo:
287+
command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename)
288+
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
289+
cfg_hwsku, err = proc.communicate()
290+
if err:
291+
click.echo("Could not get the HWSKU from config file, exiting")
292+
sys.exit(1)
293+
else:
294+
cfg_hwsku = cfg_hwsku.strip()
295+
284296
#Stop services before config push
285297
_stop_services()
286298
config_db = ConfigDBConnector()
287299
config_db.connect()
288300
client = config_db.redis_clients[config_db.CONFIG_DB]
289301
client.flushdb()
302+
if load_sysinfo:
303+
command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku)
304+
run_command(command, display_cmd=True)
305+
290306
command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename)
291307
run_command(command, display_cmd=True)
292308
client.set(config_db.INIT_INDICATOR, 1)

0 commit comments

Comments
 (0)