Skip to content

Commit

Permalink
Flush DB first when loading from minigraph (sonic-net#114)
Browse files Browse the repository at this point in the history
* Flush DB first when loading from minigraph and add a config reload command to flush db and reload from json.
  • Loading branch information
taoyl-ms authored Oct 3, 2017
1 parent 63f05ad commit b27d4f9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ def load(filename):
command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)

@cli.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Clear current and reload all config?')
@click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True))
def reload(filename):
"""Clear current configuration and import a previous saved config DB dump file."""
config_db = ConfigDBConnector()
config_db.connect()
client = config_db.redis_clients[config_db.CONFIG_DB]
client.flushdb()
command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename)
run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, True)

@cli.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload mgmt config?')
Expand All @@ -135,14 +149,20 @@ def load_mgmt_config(filename):
run_command(command, display_cmd=True)
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
run_command(command, display_cmd=True)
print "Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`."

@cli.command()
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload config from minigraph?')
def load_minigraph():
"""Reconfigure based on minigraph."""
config_db = ConfigDBConnector()
config_db.connect()
client = config_db.redis_clients[config_db.CONFIG_DB]
client.flushdb()
command = "{} -m --write-to-db".format(SONIC_CFGGEN_PATH)
run_command(command, display_cmd=True)
client.set(config_db.INIT_INDICATOR, True)
command = "{} -m -v \"DEVICE_METADATA['localhost']['hostname']\"".format(SONIC_CFGGEN_PATH)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
p.wait()
Expand All @@ -159,7 +179,7 @@ def load_minigraph():
run_command("service lldp restart", display_cmd=True)
run_command("service snmp restart", display_cmd=True)
run_command("service dhcp_relay restart", display_cmd=True)

print "Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`."
#
# 'bgp' group
#
Expand Down

0 comments on commit b27d4f9

Please sign in to comment.