Skip to content

Commit a093f47

Browse files
author
Ritwick DSouza
committed
[raspbia] Added documentation for write and generate method
1 parent 0c8bef5 commit a093f47

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

docs/source/backends/raspbian.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,72 @@ Will return the following output::
6767
address fd87::1
6868
netmask 128
6969

70+
Generate method
71+
---------------
72+
73+
.. automethod:: netjsonconfig.Raspbian.generate
74+
75+
Code example:
76+
77+
.. code-block:: python
78+
79+
>>> import tarfile
80+
>>> from netjsonconfig import Raspbian
81+
>>>
82+
>>> o = Raspbian({
83+
... "interfaces": [
84+
... {
85+
... "name": "eth0",
86+
... "type": "ethernet",
87+
... "addresses": [
88+
... {
89+
... "proto": "dhcp",
90+
... "family": "ipv4"
91+
... }
92+
... ]
93+
... }
94+
... ]
95+
... })
96+
>>> stream = o.generate()
97+
>>> print(stream)
98+
<_io.BytesIO object at 0x7f8bc6efb620>
99+
>>> tar = tarfile.open(fileobj=stream, mode='r:gz')
100+
>>> print(tar.getmembers())
101+
[<TarInfo '/etc/network/interfaces' at 0x7f8bc6f08048>]
102+
103+
The ``generate`` method does not write to disk but instead returns a instance of
104+
``io.BytesIO`` which contains a tar.gz file object.
105+
106+
Write method
107+
------------
108+
109+
.. automethod:: netjsonconfig.OpenWrt.write
110+
111+
Example:
112+
113+
.. code-block:: python
114+
115+
>>> import tarfile
116+
>>> from netjsonconfig import Raspbian
117+
>>>
118+
>>> o = Raspbian({
119+
... "interfaces": [
120+
... {
121+
... "name": "eth0",
122+
... "type": "ethernet",
123+
... "addresses": [
124+
... {
125+
... "proto": "dhcp",
126+
... "family": "ipv4"
127+
... }
128+
... ]
129+
... }
130+
... ]
131+
... })
132+
>>> o.write('dhcp-router', path='/tmp/')
133+
134+
Writes the configuration archive in ``/tmp/dhcp-router.tar.gz``
135+
70136
General settings
71137
----------------
72138

@@ -352,6 +418,7 @@ Configure your interface
352418
Let us say that ``wlan0`` is our wireless interface which we will be using.
353419
First we need to setup a static IP for our wireless interface. Edit the
354420
``wlan0`` section in interface configuration file ``/etc/network/interfaces``::
421+
355422
auto wlan0
356423
iface wlan0 inet static
357424
address 172.128.1.1
@@ -372,6 +439,7 @@ At this point you should be able to see your wireless network. If you try to con
372439
to this network, it will authenticate but will not recieve any IP address until
373440
dnsmasq is setup. Use **Ctrl+C** to stop it.
374441
If you want the wireless service to start automatically at boot, find the line::
442+
375443
#DAEMON_CONF=""
376444

377445
in ``/etc/default/hostapd`` and replace it with::
@@ -385,6 +453,7 @@ By default ``/etc/dnsmasq.conf`` contains the complete documentation for how the
385453
file needs to be used. It is advisable to create a copy of the original ``dnsmasq.conf``.
386454
After creating the backup, delete the original file and create a new file ``/etc/dnsmasq.conf``
387455
Setup your DNS and DHCP server. Below is an example configuration file::
456+
388457
# User interface wlan0
389458
interface=wlan0
390459
# Specify the address to listen on

0 commit comments

Comments
 (0)