-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlan.py
More file actions
47 lines (39 loc) · 1.21 KB
/
lan.py
File metadata and controls
47 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import configuration
import ipv4
import static
import service
JSON = """{
"is_dhcp": true,
"static": {
"address": "%s",
"netmask": "%s",
"gateway": "%s",
"dns": "%s"
}
}""" % (
static.IPv4.address, static.IPv4.netmask, static.IPv4.gateway, static.IPv4.dns,
)
class JSONStore(configuration.JSONStore):
def __init__(self, path):
super().__init__(path, JSON)
class Service(service.Service):
def __init__(self, networkStatus):
self._networkStatus = networkStatus
async def _set(self, getter):
lan = ipv4.LAN()
if getter.get('is_dhcp'):
await lan.dhcp()
else:
address = getter.get('static.address')
netmask = getter.get('static.netmask')
gateway = getter.get('static.gateway')
dns = getter.get('static.dns')
await lan.static(
address, netmask, gateway, dns=dns
)
async def onStart(self):
async with self._networkStatus.getter as getter:
await self._set(getter)
async def onLoop(self, stopCallback):
async with self._networkStatus.watcher as getter:
await self._set(getter)