Skip to content

Commit fcced70

Browse files
committed
[config/load_mgmt_config] Support load IPv6 mgmt IP (sonic-net#2206)
* [config/load_mgmt_config] Support load IPv6 mgmt IP Signed-off-by: Jing Kan [email protected]
1 parent afceda4 commit fcced70

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

config/main.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -938,16 +938,25 @@ def load_mgmt_config(filename):
938938
config_data = parse_device_desc_xml(filename)
939939
hostname = config_data['DEVICE_METADATA']['localhost']['hostname']
940940
_change_hostname(hostname)
941-
mgmt_conf = netaddr.IPNetwork(config_data['MGMT_INTERFACE'].keys()[0][1])
942-
gw_addr = config_data['MGMT_INTERFACE'].values()[0]['gwaddr']
943-
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
944-
run_command(command, display_cmd=True)
945-
command = "ip route add default via {} dev eth0 table default".format(gw_addr)
946-
run_command(command, display_cmd=True, ignore_error=True)
947-
command = "ip rule add from {} table default".format(str(mgmt_conf.ip))
948-
run_command(command, display_cmd=True, ignore_error=True)
949-
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
950-
run_command(command, display_cmd=True, ignore_error=True)
941+
for key in list(config_data['MGMT_INTERFACE'].keys()):
942+
# key: (eth0, ipprefix)
943+
# value: { gwaddr: ip }
944+
mgmt_conf = netaddr.IPNetwork(key[1])
945+
gw_addr = config_data['MGMT_INTERFACE'][key]['gwaddr']
946+
if mgmt_conf.version == 4:
947+
command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask))
948+
run_command(command, display_cmd=True)
949+
else:
950+
command = "ifconfig eth0 add {}".format(str(mgmt_conf))
951+
# Ignore error for IPv6 configuration command due to it not allows config the same IP twice
952+
run_command(command, display_cmd=True, ignore_error=True)
953+
command = "ip{} route add default via {} dev eth0 table default".format(" -6" if mgmt_conf.version == 6 else "", gw_addr)
954+
run_command(command, display_cmd=True, ignore_error=True)
955+
command = "ip{} rule add from {} table default".format(" -6" if mgmt_conf.version == 6 else "", str(mgmt_conf.ip))
956+
run_command(command, display_cmd=True, ignore_error=True)
957+
if len(config_data['MGMT_INTERFACE'].keys()) > 0:
958+
command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
959+
run_command(command, display_cmd=True, ignore_error=True)
951960
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")
952961

953962
@config.command("load_minigraph")

doc/Command-Reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3377,7 +3377,7 @@ running on the device.
33773377
33783378
This command is used to reconfigure hostname and mgmt interface based on device description file.
33793379
This command either uses the optional file specified as arguement or looks for the file "/etc/sonic/device_desc.xml".
3380-
If the file does not exist or if the file does not have valid fields for "hostname" and "ManagementAddress", it fails.
3380+
If the file does not exist or if the file does not have valid fields for "hostname" and "ManagementAddress" (or "ManagementAddressV6"), it fails.
33813381
33823382
When user specifies the optional argument "-y" or "--yes", this command forces the loading without prompting the user for confirmation.
33833383
If the argument is not specified, it prompts the user to confirm whether user really wants to load this configuration file.

0 commit comments

Comments
 (0)