@@ -938,16 +938,25 @@ def load_mgmt_config(filename):
938
938
config_data = parse_device_desc_xml (filename )
939
939
hostname = config_data ['DEVICE_METADATA' ]['localhost' ]['hostname' ]
940
940
_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 )
951
960
click .echo ("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`." )
952
961
953
962
@config .command ("load_minigraph" )
0 commit comments