networks: Refactor common settings updation

Since IPv4 address settings are not relavent for PPPoE and the command
settings take them, split the common setting updation into basic
settings and IPv4 settings.
This commit is contained in:
Sunil Mohan Adapa 2015-08-22 20:49:17 +05:30
parent 21ee2de998
commit e7214b7586

View File

@ -129,13 +129,15 @@ def get_active_connection(connection_uuid):
raise ConnectionNotFound(connection_uuid) raise ConnectionNotFound(connection_uuid)
def _update_common_settings(connection, connection_uuid, name, type_, def _update_common_settings(connection, connection_uuid, name, type_, interface,
interface, zone, ipv4_method, ipv4_address): zone):
"""Create/edit basic settings for network manager connections.""" """Create/edit basic settings for network manager connections.
Return newly created connection object if connection is None.
"""
if not connection: if not connection:
connection = nm.SimpleConnection.new() connection = nm.SimpleConnection.new()
# Connection
settings = connection.get_setting_connection() settings = connection.get_setting_connection()
if not settings: if not settings:
settings = nm.SettingConnection.new() settings = nm.SettingConnection.new()
@ -147,7 +149,11 @@ def _update_common_settings(connection, connection_uuid, name, type_,
settings.set_property(nm.SETTING_CONNECTION_INTERFACE_NAME, interface) settings.set_property(nm.SETTING_CONNECTION_INTERFACE_NAME, interface)
settings.set_property(nm.SETTING_CONNECTION_ZONE, zone) settings.set_property(nm.SETTING_CONNECTION_ZONE, zone)
# IPv4 return connection
def _update_ipv4_settings(connection, ipv4_method, ipv4_address):
"""Edit IPv4 settings for network manager connections."""
settings = connection.get_setting_ip4_config() settings = connection.get_setting_ip4_config()
if not settings: if not settings:
settings = nm.SettingIP4Config.new() settings = nm.SettingIP4Config.new()
@ -165,8 +171,6 @@ def _update_common_settings(connection, connection_uuid, name, type_,
else: else:
settings.clear_addresses() settings.clear_addresses()
return connection
def _update_ethernet_settings(connection, connection_uuid, name, interface, def _update_ethernet_settings(connection, connection_uuid, name, interface,
zone, ipv4_method, ipv4_address): zone, ipv4_method, ipv4_address):
@ -174,8 +178,8 @@ def _update_ethernet_settings(connection, connection_uuid, name, interface,
type_ = '802-3-ethernet' type_ = '802-3-ethernet'
connection = _update_common_settings(connection, connection_uuid, name, connection = _update_common_settings(connection, connection_uuid, name,
type_, interface, zone, ipv4_method, type_, interface, zone)
ipv4_address) _update_ipv4_settings(connection, ipv4_method, ipv4_address)
# Ethernet # Ethernet
settings = connection.get_setting_wired() settings = connection.get_setting_wired()
@ -192,8 +196,7 @@ def _update_pppoe_settings(connection, connection_uuid, name, interface, zone,
type_ = 'pppoe' type_ = 'pppoe'
connection = _update_common_settings(connection, connection_uuid, name, connection = _update_common_settings(connection, connection_uuid, name,
type_, interface, zone, 'auto', type_, interface, zone)
'0.0.0.0')
#pppoe #pppoe
settings = connection.get_setting_pppoe() settings = connection.get_setting_pppoe()
@ -270,8 +273,8 @@ def _update_wifi_settings(connection, connection_uuid, name, interface, zone,
key_mgmt = 'wpa-psk' key_mgmt = 'wpa-psk'
connection = _update_common_settings(connection, connection_uuid, name, connection = _update_common_settings(connection, connection_uuid, name,
type_, interface, zone, ipv4_method, type_, interface, zone)
ipv4_address) _update_ipv4_settings(connection, ipv4_method, ipv4_address)
# Wireless # Wireless
settings = connection.get_setting_wireless() settings = connection.get_setting_wireless()