Skip to content

Commit 0c2a452

Browse files
author
Ritwick DSouza
committed
[raspbian] Added support for NTP
1 parent a49330d commit 0c2a452

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

netjsonconfig/backends/raspbian/converters.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,15 @@ def to_intermediate(self):
148148
for domain in dns_search:
149149
result.append(domain)
150150
return (('dns_search', result),)
151+
152+
153+
class Ntp(BaseConverter):
154+
netjson_key = 'ntp'
155+
156+
def to_intermediate(self):
157+
result = []
158+
ntp = get_copy(self.netjson, self.netjson_key)
159+
if ntp.get('enabled', False) == True:
160+
for server in ntp.get('server'):
161+
result.append(server)
162+
return (('ntp', result),)

netjsonconfig/backends/raspbian/raspbian.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .converters import Interfaces, Wireless, DnsServers, DnsSearch
1+
from .converters import Interfaces, Wireless, DnsServers, DnsSearch, Ntp
22
from .renderers import Raspbian
33
from ..base.backend import BaseBackend
44
from .schema import schema
@@ -15,5 +15,6 @@ class Raspbian(BaseBackend):
1515
Wireless,
1616
DnsServers,
1717
DnsSearch,
18+
Ntp
1819
]
1920
renderer = Raspbian

netjsonconfig/backends/raspbian/templates/raspbian.jinja2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ wpa_pairwise={{ wireless.get('encryption').get('wpa_pairwise')}}
124124
{% else %}
125125
{% endif %}
126126
{% endfor %}
127+
{% for i, j in data.items() %}
128+
{% if i|string() == 'ntp' %}
129+
config: /etc/ntp.conf
130+
{% for server in j %}
131+
server {{ server }}
132+
{% endfor %}
133+
{% endif %}
134+
{% endfor %}

tests/raspbian/test_system.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unittest
2+
3+
from netjsonconfig import Raspbian
4+
from netjsonconfig.utils import _TabsMixin
5+
6+
class TestSystemRender(unittest.TestCase, _TabsMixin):
7+
8+
def test_ntp(self):
9+
o = Raspbian({
10+
"ntp": {
11+
"enabled": True,
12+
"enable_server": False,
13+
"server": [
14+
"0.openwrt.pool.ntp.org",
15+
"1.openwrt.pool.ntp.org",
16+
"2.openwrt.pool.ntp.org",
17+
"3.openwrt.pool.ntp.org"
18+
]
19+
}
20+
})
21+
22+
expected = '''config: /etc/ntp.config
23+
server 0.openwrt.pool.ntp.org
24+
server 1.openwrt.pool.ntp.org
25+
server 2.openwrt.pool.ntp.org
26+
server 3.openwrt.pool.ntp.org
27+
'''

0 commit comments

Comments
 (0)