@@ -446,16 +446,25 @@ def load_mgmt_config(filename):
446
446
config_data = parse_device_desc_xml (filename )
447
447
hostname = config_data ['DEVICE_METADATA' ]['localhost' ]['hostname' ]
448
448
_change_hostname (hostname )
449
- mgmt_conf = netaddr .IPNetwork (config_data ['MGMT_INTERFACE' ].keys ()[0 ][1 ])
450
- gw_addr = config_data ['MGMT_INTERFACE' ].values ()[0 ]['gwaddr' ]
451
- command = "ifconfig eth0 {} netmask {}" .format (str (mgmt_conf .ip ), str (mgmt_conf .netmask ))
452
- run_command (command , display_cmd = True )
453
- command = "ip route add default via {} dev eth0 table default" .format (gw_addr )
454
- run_command (command , display_cmd = True , ignore_error = True )
455
- command = "ip rule add from {} table default" .format (str (mgmt_conf .ip ))
456
- run_command (command , display_cmd = True , ignore_error = True )
457
- command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
458
- run_command (command , display_cmd = True , ignore_error = True )
449
+ for key in list (config_data ['MGMT_INTERFACE' ].keys ()):
450
+ # key: (eth0, ipprefix)
451
+ # value: { gwaddr: ip }
452
+ mgmt_conf = netaddr .IPNetwork (key [1 ])
453
+ gw_addr = config_data ['MGMT_INTERFACE' ][key ]['gwaddr' ]
454
+ if mgmt_conf .version == 4 :
455
+ command = "ifconfig eth0 {} netmask {}" .format (str (mgmt_conf .ip ), str (mgmt_conf .netmask ))
456
+ run_command (command , display_cmd = True )
457
+ else :
458
+ command = "ifconfig eth0 add {}" .format (str (mgmt_conf ))
459
+ # Ignore error for IPv6 configuration command due to it not allows config the same IP twice
460
+ run_command (command , display_cmd = True , ignore_error = True )
461
+ command = "ip{} route add default via {} dev eth0 table default" .format (" -6" if mgmt_conf .version == 6 else "" , gw_addr )
462
+ run_command (command , display_cmd = True , ignore_error = True )
463
+ command = "ip{} rule add from {} table default" .format (" -6" if mgmt_conf .version == 6 else "" , str (mgmt_conf .ip ))
464
+ run_command (command , display_cmd = True , ignore_error = True )
465
+ if len (config_data ['MGMT_INTERFACE' ].keys ()) > 0 :
466
+ command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid"
467
+ run_command (command , display_cmd = True , ignore_error = True )
459
468
click .echo ("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`." )
460
469
461
470
@config .command ()
0 commit comments