def update_settings_with_ksdata(devname, networkdata): new_values = [] # ipv4 settings method4 = "auto" if networkdata.bootProto == "static": method4 = "manual" new_values.append(["ipv4", "method", method4, "s"]) if method4 == "manual": addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip) gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway) prefix4 = netmask2prefix(networkdata.netmask) new_values.append( ["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"]) # ipv6 settings if networkdata.noipv6: method6 = "ignore" else: if networkdata.ipv6 == "auto": method6 = "auto" elif networkdata.ipv6 == "dhcp": method6 = "dhcp" else: method6 = "manual" new_values.append(["ipv6", "method", method6, "s"]) if method6 == "manual": addr6, _slash, prefix6 = networkdata.ipv6.partition("/") if prefix6: prefix6 = int(prefix6) else: prefix6 = 64 addr6 = nm.nm_ipv6_to_dbus_ay(addr6) if networkdata.ipv6gateway: gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway) else: gateway6 = [0] * 16 new_values.append( ["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"]) # nameservers nss4 = [] nss6 = [] if networkdata.nameserver: for ns in networkdata.nameserver.split(","): if ":" in ns: nss6.append(nm.nm_ipv6_to_dbus_ay(ns)) else: nss4.append(nm.nm_ipv4_to_dbus_int(ns)) new_values.append(["ipv4", "dns", nss4, "au"]) new_values.append(["ipv6", "dns", nss6, "aay"]) # onboot new_values.append(['connection', 'autoconnect', networkdata.onboot, None]) nm.nm_update_settings_of_device(devname, new_values)
def _get_ip_setting_values_from_ksdata(networkdata): values = [] # ipv4 settings method4 = "auto" if networkdata.bootProto == "static": method4 = "manual" values.append(["ipv4", "method", method4, "s"]) if method4 == "manual": addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip) gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway) prefix4 = netmask2prefix(networkdata.netmask) values.append( ["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"]) # ipv6 settings if networkdata.noipv6: method6 = "ignore" else: if not networkdata.ipv6: method6 = "auto" elif networkdata.ipv6 == "auto": method6 = "auto" elif networkdata.ipv6 == "dhcp": method6 = "dhcp" else: method6 = "manual" values.append(["ipv6", "method", method6, "s"]) if method6 == "manual": addr6, _slash, prefix6 = networkdata.ipv6.partition("/") if prefix6: prefix6 = int(prefix6) else: prefix6 = 64 addr6 = nm.nm_ipv6_to_dbus_ay(addr6) if networkdata.ipv6gateway: gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway) else: gateway6 = [0] * 16 values.append( ["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"]) # nameservers nss4 = [] nss6 = [] if networkdata.nameserver: for ns in networkdata.nameserver.split(","): if ":" in ns: nss6.append(nm.nm_ipv6_to_dbus_ay(ns)) else: nss4.append(nm.nm_ipv4_to_dbus_int(ns)) values.append(["ipv4", "dns", nss4, "au"]) values.append(["ipv6", "dns", nss6, "aay"]) return values
def ipv6_address_convert_test(self): addresses = ["::", "ef:ef:eeef:ef:ef:eeef:efff:ef"] for address in addresses: self.assertEqual(nm.nm_dbus_ay_to_ipv6(nm.nm_ipv6_to_dbus_ay(address)), address) self.assertEqual(nm.nm_ipv6_to_dbus_ay("ef:ef:eeef:ef:ef:eeef:efff:ef"), [0, 239, 0, 239, 238, 239, 0, 239, 0, 239, 238, 239, 239, 255, 0, 239])
def update_settings_with_ksdata(devname, networkdata): new_values = [] # ipv4 settings method4 = "auto" if networkdata.bootProto == "static": method4 = "manual" new_values.append(["ipv4", "method", method4, "s"]) if method4 == "manual": addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip) gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway) prefix4 = netmask2prefix(networkdata.netmask) new_values.append(["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"]) # ipv6 settings if networkdata.noipv6: method6 = "ignore" else: if networkdata.ipv6 == "auto": method6 = "auto" elif networkdata.ipv6 == "dhcp": method6 = "dhcp" else: method6 = "manual" new_values.append(["ipv6", "method", method6, "s"]) if method6 == "manual": addr6, _slash, prefix6 = networkdata.ipv6.partition("/") if prefix6: prefix6 = int(prefix6) else: prefix6 = 64 addr6 = nm.nm_ipv6_to_dbus_ay(addr6) if networkdata.ipv6gateway: gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway) else: gateway6 = [0] * 16 new_values.append(["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"]) # nameservers nss4 = [] nss6 = [] if networkdata.nameserver: for ns in networkdata.nameserver.split(","): if ":" in ns: nss6.append(nm.nm_ipv6_to_dbus_ay(ns)) else: nss4.append(nm.nm_ipv4_to_dbus_int(ns)) new_values.append(["ipv4", "dns", nss4, "au"]) new_values.append(["ipv6", "dns", nss6, "aay"]) # onboot new_values.append(['connection', 'autoconnect', networkdata.onboot, None]) nm.nm_update_settings_of_device(devname, new_values)
def _get_ip_setting_values_from_ksdata(networkdata): values = [] # ipv4 settings method4 = "auto" if networkdata.bootProto == "static": method4 = "manual" values.append(["ipv4", "method", method4, "s"]) if method4 == "manual": addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip) gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway) prefix4 = netmask2prefix(networkdata.netmask) values.append(["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"]) # ipv6 settings if networkdata.noipv6: method6 = "ignore" else: if not networkdata.ipv6: method6 = "auto" elif networkdata.ipv6 == "auto": method6 = "auto" elif networkdata.ipv6 == "dhcp": method6 = "dhcp" else: method6 = "manual" values.append(["ipv6", "method", method6, "s"]) if method6 == "manual": addr6, _slash, prefix6 = networkdata.ipv6.partition("/") if prefix6: prefix6 = int(prefix6) else: prefix6 = 64 addr6 = nm.nm_ipv6_to_dbus_ay(addr6) if networkdata.ipv6gateway: gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway) else: gateway6 = [0] * 16 values.append(["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"]) # nameservers nss4 = [] nss6 = [] if networkdata.nameserver: for ns in networkdata.nameserver.split(","): if ":" in ns: nss6.append(nm.nm_ipv6_to_dbus_ay(ns)) else: nss4.append(nm.nm_ipv4_to_dbus_int(ns)) values.append(["ipv4", "dns", nss4, "au"]) values.append(["ipv6", "dns", nss6, "aay"]) return values
def ipv6_address_convert_test(self): addresses = ["::", "ef:ef:eeef:ef:ef:eeef:efff:ef"] for address in addresses: self.assertEqual( nm.nm_dbus_ay_to_ipv6(nm.nm_ipv6_to_dbus_ay(address)), address) self.assertEqual( nm.nm_ipv6_to_dbus_ay("ef:ef:eeef:ef:ef:eeef:efff:ef"), [ 0, 239, 0, 239, 238, 239, 0, 239, 0, 239, 238, 239, 239, 255, 0, 239 ])