@@ -10,12 +10,12 @@ Intermediate representation
1010
1111The intermediate representation is the output of the a :ref: `converter `,
1212it is backend specific and is built as a tree structure made from python
13- builtins values
13+ builtins values.
1414
1515A tree is a *acyclic, directional graph * with an element called *root *.
1616
1717The root of our tree is stored in the first element of a tuple, along with
18- the root's direct sons as a list
18+ the root's direct sons as a list:
1919
2020.. code-block :: python
2121
@@ -30,9 +30,9 @@ As an example here we present the tree `('spam', ['eggs', 'snakes'])`
3030 }
3131
3232As a son may be a carrier of a value so we store it in a dictionary instead of adding a *leaf *
33- with another level of recursion
33+ with another level of recursion.
3434
35- As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : { 'loved' : 'python' }}]) `
35+ As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : { 'loved' : 'python' }}]) `:
3636
3737.. graphviz ::
3838
@@ -46,7 +46,7 @@ As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : {
4646
4747 }
4848
49- This tree could be tranlated to a configuration file for AirOS that looks like this
49+ This tree could be tranlated to a configuration file for AirOS that looks like this:
5050
5151.. code-block :: ini
5252
@@ -55,7 +55,7 @@ This tree could be tranlated to a configuration file for AirOS that looks like t
5555
5656
5757 So our tree representation is based on the simple assumption that a *leaf * is a dictionary
58- without nested values and nested values in a dictionary creates a father-son relationship
58+ without nested values and nested values in a dictionary creates a father-son relationship.
5959
6060Instead when the configuration requires that the son values must be prefixed from a number,
6161e.g. `vlan.1.devname=eth0 ` we store a list of dictionaries.
@@ -65,27 +65,27 @@ e.g. `vlan.1.devname=eth0` we store a list of dictionaries.
6565 (
6666 ' spam' ,
6767 [
68- {
69- ' eggs' : 2 ,
68+ {
69+ ' eggs' : 2 ,
70+ },
71+ {
72+ ' snakes' : {
73+ ' loved' : [
74+ {
75+ ' python2' : True ,
76+ },
77+ {
78+ ' python3' : True ,
79+ },
80+ {
81+ ' ipython' : True ,
82+ }
83+ ],
7084 },
71- {
72- ' snakes' : {
73- ' loved' : [
74- {
75- ' python2' : True ,
76- },
77- {
78- ' python3' : True ,
79- },
80- {
81- ' ipython' : True ,
82- }
83- ],
84- },
85- }
86- ]
85+ }
86+ ])
8787
88- And the resulting tree is this
88+ And the resulting tree is:
8989
9090.. graphviz ::
9191
@@ -109,7 +109,7 @@ And the resulting tree is this
109109
110110 }
111111
112- And the configuration is
112+ And the configuration is:
113113
114114.. code-block :: ini
115115
@@ -119,32 +119,32 @@ And the configuration is
119119 spam.snakes.loved.2.ipython =true
120120
121121 The process by which we can go from the intermediate representation from
122- the output configuration is called flattening
122+ the output configuration is called flattening, you can find more in the next section.
123123
124124Flattening
125125----------
126126
127127To avoid at all cost a recursive logic in the template we flatten the intermediate
128- representation to something that has a * namespace* a * key* and a * value*
128+ representation to something that has a *namespace * a *key * and a *value *.
129129
130- This input NetJSON will be converted to a python :ref:`configuration_dictionary`
130+ This input NetJSON will be converted to a python :ref: `configuration_dictionary `:
131131
132132.. code-block :: json
133133
134134 //netjson
135135 {
136136 "type" : " DeviceConfiguration" ,
137137 "interfaces" : [
138- {
139- " name" : " eth0.1" ,
140- " type" : " ethernet" ,
141- " comment" : " management vlan"
142- },
143- {
144- " name" : " eth0.2" ,
145- " type" : " ethernet" ,
146- " comment" : " traffic vlan"
147- }
138+ {
139+ "name" : " eth0.1" ,
140+ "type" : " ethernet" ,
141+ "comment" : " management vlan"
142+ },
143+ {
144+ "name" : " eth0.2" ,
145+ "type" : " ethernet" ,
146+ "comment" : " traffic vlan"
147+ }
148148 ]
149149 }
150150
@@ -153,21 +153,21 @@ This input NetJSON will be converted to a python :ref:`configuration_dictionary`
153153 # python
154154 {
155155 ' interfaces' : [
156- {
157- ' name' : ' eth0.1' ,
158- ' type' : ' ethernet' ,
159- ' comment' : ' management'
160- },
161- {
162- ' name' : ' eth0.2' ,
163- ' type' : ' ethernet' ,
164- ' comment' : ' traffic'
165- }
156+ {
157+ ' name' : ' eth0.1' ,
158+ ' type' : ' ethernet' ,
159+ ' comment' : ' management vlan '
160+ },
161+ {
162+ ' name' : ' eth0.2' ,
163+ ' type' : ' ethernet' ,
164+ ' comment' : ' traffic vlan '
165+ }
166166 ]
167167 }
168168
169169
170- And this must be converted to an appropiate AirOS configuration which looks like this
170+ And this must be converted to an appropiate AirOS configuration which looks like this:
171171
172172.. code-block :: ini
173173
@@ -182,7 +182,7 @@ And this must be converted to an appropiate AirOS configuration which looks like
182182 vlan.status =enabled
183183
184184 To do this we must convert the :ref: `configuration_dictionary ` into something that
185- resemble the target text, the output configuration
185+ resembles the target text, the output configuration.
186186
187187.. code-block :: python
188188
@@ -208,9 +208,9 @@ resemble the target text, the output configuration
208208
209209 )
210210
211- And to do that we get rid of the multiple indentation levels by flattening the tree structure
211+ And to do that we get rid of the multiple indentation levels by flattening the tree structure.
212212
213- The tree associated with the previous NetJSON example is this
213+ The tree associated with the previous NetJSON example is this:
214214
215215.. graphviz ::
216216
0 commit comments