mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 15:16:33 +00:00
Allow to set user DNS through API with auto mode
Currently it is only possible to set DNS servers when in static mode. However, there are use cases to set DNS servers when in auto mode as well, e.g. if no local DNS server is provided by the DHCP, or the provided DNS turns out to be non-working.
This commit is contained in:
parent
91a8fae9b5
commit
5e7b5c1862
@ -102,15 +102,8 @@ def get_connection_from_interface(
|
|||||||
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "auto")
|
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "auto")
|
||||||
elif interface.ipv4setting.method == InterfaceMethod.DISABLED:
|
elif interface.ipv4setting.method == InterfaceMethod.DISABLED:
|
||||||
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "disabled")
|
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "disabled")
|
||||||
else:
|
elif interface.ipv4setting.method == InterfaceMethod.STATIC:
|
||||||
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "manual")
|
ipv4[CONF_ATTR_IPV4_METHOD] = Variant("s", "manual")
|
||||||
ipv4[CONF_ATTR_IPV4_DNS] = Variant(
|
|
||||||
"au",
|
|
||||||
[
|
|
||||||
socket.htonl(int(ip_address))
|
|
||||||
for ip_address in interface.ipv4setting.nameservers
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
address_data = []
|
address_data = []
|
||||||
for address in interface.ipv4setting.address:
|
for address in interface.ipv4setting.address:
|
||||||
@ -123,6 +116,19 @@ def get_connection_from_interface(
|
|||||||
|
|
||||||
ipv4[CONF_ATTR_IPV4_ADDRESS_DATA] = Variant("aa{sv}", address_data)
|
ipv4[CONF_ATTR_IPV4_ADDRESS_DATA] = Variant("aa{sv}", address_data)
|
||||||
ipv4[CONF_ATTR_IPV4_GATEWAY] = Variant("s", str(interface.ipv4setting.gateway))
|
ipv4[CONF_ATTR_IPV4_GATEWAY] = Variant("s", str(interface.ipv4setting.gateway))
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Invalid IPv4 InterfaceMethod")
|
||||||
|
|
||||||
|
if (
|
||||||
|
not interface.ipv4setting
|
||||||
|
or interface.ipv4setting.method == InterfaceMethod.AUTO
|
||||||
|
or interface.ipv4setting.method == InterfaceMethod.STATIC
|
||||||
|
):
|
||||||
|
nameservers = interface.ipv4setting.nameservers if interface.ipv4setting else []
|
||||||
|
ipv4[CONF_ATTR_IPV4_DNS] = Variant(
|
||||||
|
"au",
|
||||||
|
[socket.htonl(int(ip_address)) for ip_address in nameservers],
|
||||||
|
)
|
||||||
|
|
||||||
conn[CONF_ATTR_IPV4] = ipv4
|
conn[CONF_ATTR_IPV4] = ipv4
|
||||||
|
|
||||||
@ -134,12 +140,8 @@ def get_connection_from_interface(
|
|||||||
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "auto")
|
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "auto")
|
||||||
elif interface.ipv6setting.method == InterfaceMethod.DISABLED:
|
elif interface.ipv6setting.method == InterfaceMethod.DISABLED:
|
||||||
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "link-local")
|
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "link-local")
|
||||||
else:
|
elif interface.ipv4setting.method == InterfaceMethod.STATIC:
|
||||||
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "manual")
|
ipv6[CONF_ATTR_IPV6_METHOD] = Variant("s", "manual")
|
||||||
ipv6[CONF_ATTR_IPV6_DNS] = Variant(
|
|
||||||
"aay",
|
|
||||||
[ip_address.packed for ip_address in interface.ipv6setting.nameservers],
|
|
||||||
)
|
|
||||||
|
|
||||||
address_data = []
|
address_data = []
|
||||||
for address in interface.ipv6setting.address:
|
for address in interface.ipv6setting.address:
|
||||||
@ -152,6 +154,19 @@ def get_connection_from_interface(
|
|||||||
|
|
||||||
ipv6[CONF_ATTR_IPV6_ADDRESS_DATA] = Variant("aa{sv}", address_data)
|
ipv6[CONF_ATTR_IPV6_ADDRESS_DATA] = Variant("aa{sv}", address_data)
|
||||||
ipv6[CONF_ATTR_IPV6_GATEWAY] = Variant("s", str(interface.ipv6setting.gateway))
|
ipv6[CONF_ATTR_IPV6_GATEWAY] = Variant("s", str(interface.ipv6setting.gateway))
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Invalid IPv6 InterfaceMethod")
|
||||||
|
|
||||||
|
if (
|
||||||
|
not interface.ipv6setting
|
||||||
|
or interface.ipv6setting.method == InterfaceMethod.AUTO
|
||||||
|
or interface.ipv6setting.method == InterfaceMethod.STATIC
|
||||||
|
):
|
||||||
|
nameservers = interface.ipv6setting.nameservers if interface.ipv6setting else []
|
||||||
|
ipv6[CONF_ATTR_IPV6_DNS] = Variant(
|
||||||
|
"aay",
|
||||||
|
[ip_address.packed for ip_address in nameservers],
|
||||||
|
)
|
||||||
|
|
||||||
conn[CONF_ATTR_IPV6] = ipv6
|
conn[CONF_ATTR_IPV6] = ipv6
|
||||||
|
|
||||||
|
@ -251,8 +251,14 @@ async def test_api_network_vlan(
|
|||||||
"autoconnect": Variant("b", True),
|
"autoconnect": Variant("b", True),
|
||||||
"uuid": connection["connection"]["uuid"],
|
"uuid": connection["connection"]["uuid"],
|
||||||
}
|
}
|
||||||
assert connection["ipv4"] == {"method": Variant("s", "auto")}
|
assert connection["ipv4"] == {
|
||||||
assert connection["ipv6"] == {"method": Variant("s", "auto")}
|
"method": Variant("s", "auto"),
|
||||||
|
"dns": Variant("au", []),
|
||||||
|
}
|
||||||
|
assert connection["ipv6"] == {
|
||||||
|
"method": Variant("s", "auto"),
|
||||||
|
"dns": Variant("aay", []),
|
||||||
|
}
|
||||||
assert connection["vlan"] == {
|
assert connection["vlan"] == {
|
||||||
"id": Variant("u", 1),
|
"id": Variant("u", 1),
|
||||||
"parent": Variant("s", "0c23631e-2118-355c-bbb0-8943229cb0d6"),
|
"parent": Variant("s", "0c23631e-2118-355c-bbb0-8943229cb0d6"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user