@@ -10,12 +10,12 @@ Intermediate representation
10
10
11
11
The intermediate representation is the output of the a :ref: `converter `,
12
12
it is backend specific and is built as a tree structure made from python
13
- builtins values
13
+ builtins values.
14
14
15
15
A tree is a *acyclic, directional graph * with an element called *root *.
16
16
17
17
The 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:
19
19
20
20
.. code-block :: python
21
21
@@ -30,9 +30,9 @@ As an example here we present the tree `('spam', ['eggs', 'snakes'])`
30
30
}
31
31
32
32
As 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.
34
34
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' }}]) `:
36
36
37
37
.. graphviz ::
38
38
@@ -46,7 +46,7 @@ As an example here we present the tree `('spam', [ { 'eggs': 2 }, { 'snakes' : {
46
46
47
47
}
48
48
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:
50
50
51
51
.. code-block :: ini
52
52
@@ -55,7 +55,7 @@ This tree could be tranlated to a configuration file for AirOS that looks like t
55
55
56
56
57
57
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.
59
59
60
60
Instead when the configuration requires that the son values must be prefixed from a number,
61
61
e.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.
65
65
(
66
66
' spam' ,
67
67
[
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
+ ],
70
84
},
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
+ ])
87
87
88
- And the resulting tree is this
88
+ And the resulting tree is:
89
89
90
90
.. graphviz ::
91
91
@@ -109,7 +109,7 @@ And the resulting tree is this
109
109
110
110
}
111
111
112
- And the configuration is
112
+ And the configuration is:
113
113
114
114
.. code-block :: ini
115
115
@@ -119,32 +119,32 @@ And the configuration is
119
119
spam.snakes.loved.2.ipython =true
120
120
121
121
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.
123
123
124
124
Flattening
125
125
----------
126
126
127
127
To 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 *.
129
129
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 `:
131
131
132
132
.. code-block :: json
133
133
134
134
//netjson
135
135
{
136
136
"type" : " DeviceConfiguration" ,
137
137
"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
+ }
148
148
]
149
149
}
150
150
@@ -153,21 +153,21 @@ This input NetJSON will be converted to a python :ref:`configuration_dictionary`
153
153
# python
154
154
{
155
155
' 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
+ }
166
166
]
167
167
}
168
168
169
169
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:
171
171
172
172
.. code-block :: ini
173
173
@@ -182,7 +182,7 @@ And this must be converted to an appropiate AirOS configuration which looks like
182
182
vlan.status =enabled
183
183
184
184
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.
186
186
187
187
.. code-block :: python
188
188
@@ -208,9 +208,9 @@ resemble the target text, the output configuration
208
208
209
209
)
210
210
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.
212
212
213
- The tree associated with the previous NetJSON example is this
213
+ The tree associated with the previous NetJSON example is this:
214
214
215
215
.. graphviz ::
216
216
0 commit comments