def load_mgmt_config(filename): """Reconfigure hostname and mgmt interface based on device description file.""" command = "{} -M {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) run_command(command, display_cmd=True) #FIXME: After config DB daemon for hostname and mgmt interface is implemented, we'll no longer need to do manual configuration here config_data = parse_device_desc_xml(filename) hostname = config_data['DEVICE_METADATA']['localhost']['hostname'] _change_hostname(hostname) mgmt_conf = netaddr.IPNetwork(config_data['MGMT_INTERFACE'].keys()[0][1]) command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask)) 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)
def test_parse_device_desc_xml_mgmt_interface(self): # Regular device_desc.xml with both IPv4 and IPv6 mgmt address result = minigraph.parse_device_desc_xml( self.sample_simple_device_desc) mgmt_intf = result['MGMT_INTERFACE'] self.assertEqual(len(mgmt_intf.keys()), 2) self.assertTrue(('eth0', '10.0.0.100/24') in mgmt_intf.keys()) self.assertTrue(('eth0', 'FC00:1::32/64') in mgmt_intf.keys()) self.assertTrue( ipaddress.ip_address(u'10.0.0.1') == mgmt_intf[( 'eth0', '10.0.0.100/24')]['gwaddr']) self.assertTrue( ipaddress.ip_address(u'fc00:1::1') == mgmt_intf[( 'eth0', 'FC00:1::32/64')]['gwaddr']) # Special device_desc.xml with IPv6 mgmt address only result = minigraph.parse_device_desc_xml( self.sample_simple_device_desc_ipv6_only) mgmt_intf = result['MGMT_INTERFACE'] self.assertEqual(len(mgmt_intf.keys()), 1) self.assertTrue(('eth0', 'FC00:1::32/64') in mgmt_intf.keys()) self.assertTrue( ipaddress.ip_address(u'fc00:1::1') == mgmt_intf[( 'eth0', 'FC00:1::32/64')]['gwaddr'])
def load_mgmt_config(filename): """Reconfigure hostname and mgmt interface based on device description file.""" command = "{} -M {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) run_command(command, display_cmd=True) #FIXME: After config DB daemon for hostname and mgmt interface is implemented, we'll no longer need to do manual configuration here config_data = parse_device_desc_xml(filename) hostname = config_data['DEVICE_METADATA']['localhost']['hostname'] _change_hostname(hostname) mgmt_conf = netaddr.IPNetwork(config_data['MGMT_INTERFACE'].keys()[0][1]) gw_addr = config_data['MGMT_INTERFACE'].values()[0]['gwaddr'] command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask)) run_command(command, display_cmd=True) command = "ip route add default via {} dev eth0 table default".format(gw_addr) run_command(command, display_cmd=True, ignore_error=True) command = "ip rule add from {} table default".format(str(mgmt_conf.ip)) run_command(command, display_cmd=True, ignore_error=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, ignore_error=True) click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")
def load_mgmt_config(filename): """Reconfigure hostname and mgmt interface based on device description file.""" command = "{} -M {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) run_command(command, display_cmd=True) #FIXME: After config DB daemon for hostname and mgmt interface is implemented, we'll no longer need to do manual configuration here config_data = parse_device_desc_xml(filename) hostname = config_data['DEVICE_METADATA']['localhost']['hostname'] _change_hostname(hostname) mgmt_conf = netaddr.IPNetwork(config_data['MGMT_INTERFACE'].keys()[0][1]) gw_addr = config_data['MGMT_INTERFACE'].values()[0]['gwaddr'] command = "ifconfig eth0 {} netmask {}".format(str(mgmt_conf.ip), str(mgmt_conf.netmask)) run_command(command, display_cmd=True) command = "ip route add default via {} dev eth0 table default".format(gw_addr) run_command(command, display_cmd=True, ignore_error=True) command = "ip rule add from {} table default".format(str(mgmt_conf.ip)) run_command(command, display_cmd=True, ignore_error=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, ignore_error=True) click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")