network: Fix changing addressing method (GH #307)

When changing the addressing method from manual to automatic, the IP
addresses where removed from connection object without removing the
Gateway property.  This causes a networkmanager error.

Create new SettingIP4Config object to avoid the need to reset all
propertys when changing methods
This commit is contained in:
Daniel Steglich 2015-11-28 14:15:05 +00:00 committed by Sunil Mohan Adapa
parent 3e8a6f553a
commit ff412c2af1

View File

@ -293,10 +293,8 @@ def _update_common_settings(connection, connection_uuid, name, type_,
def _update_ipv4_settings(connection, ipv4_method, ipv4_address):
"""Edit IPv4 settings for network manager connections."""
settings = connection.get_setting_ip4_config()
if not settings:
settings = nm.SettingIP4Config.new()
connection.add_setting(settings)
settings = nm.SettingIP4Config.new()
connection.add_setting(settings)
settings.set_property(nm.SETTING_IP_CONFIG_METHOD, ipv4_method)
if ipv4_method == nm.SETTING_IP4_CONFIG_METHOD_MANUAL and ipv4_address:
@ -307,8 +305,6 @@ def _update_ipv4_settings(connection, ipv4_method, ipv4_address):
settings.add_address(address)
settings.set_property(nm.SETTING_IP_CONFIG_GATEWAY, '0.0.0.0')
else:
settings.clear_addresses()
def _update_ethernet_settings(connection, connection_uuid, name, interface,