@@ -10,56 +10,50 @@ class Interfaces(RaspbianConverter):
10
10
def to_intermediate (self ):
11
11
result = []
12
12
interfaces = get_copy (self .netjson , self .netjson_key )
13
- routes = get_copy (self .netjson , 'routes' )
14
13
for interface in interfaces :
15
- new_interface = {}
16
- ifname = interface .get ('name' )
17
- iftype = interface .get ('type' )
14
+ result .append (self ._get_interface (interface ))
15
+ return (('interfaces' , result ),)
16
+
17
+ def _get_interface (self , interface ):
18
+ new_interface = {}
19
+ ifname = interface .get ('name' )
20
+ iftype = interface .get ('type' )
21
+ new_interface .update ({
22
+ 'ifname' : ifname ,
23
+ 'iftype' : iftype
24
+ })
25
+ if iftype in ['ethernet' , 'bridge' , 'loopback' , 'wireless' ]:
26
+ addresses = self ._get_address (interface )
18
27
new_interface .update ({
19
- 'ifname' : ifname ,
20
- 'iftype' : iftype
28
+ 'address' : addresses
21
29
})
22
- if iftype in ['ethernet' , 'bridge' , 'loopback' , 'wireless' ]:
23
- addresses = self ._get_address (interface )
24
- new_interface .update ({
25
- 'address' : addresses
26
- })
27
- if routes :
28
- for route in routes :
29
- if ip_network (route .get ('next' )).version == 4 :
30
- route ['version' ] = 4
31
- destination = IPv4Interface (route ['destination' ]).with_netmask
32
- dest , dest_mask = destination .split ('/' )
33
- route ['dest' ] = dest
34
- route ['dest_mask' ] = dest_mask
35
- del route ['destination' ]
36
- elif ip_network (route .get ('next' )).version == 6 :
37
- route ['version' ] = 6
38
- new_interface .update ({'route' : route })
39
- mac = interface .get ('mac' , False )
40
- if mac :
41
- new_interface .update ({'mac' : mac })
42
- mtu = interface .get ('mtu' , False )
43
- if mtu :
44
- new_interface .update ({'mtu' : mtu })
45
- txqueuelen = interface .get ('txqueuelen' , False )
46
- if txqueuelen :
47
- new_interface .update ({'txqueuelen' : txqueuelen })
48
- autostart = interface .get ('autostart' , False )
49
- if autostart :
50
- new_interface .update ({'autostart' : autostart })
51
- if iftype == 'wireless' and interface .get ('wireless' ).get ('mode' ) == 'adhoc' :
52
- wireless = interface .get ('wireless' )
53
- new_interface .update ({
54
- 'essid' : wireless .get ('ssid' ),
55
- 'mode' : wireless .get ('mode' )
56
- })
57
- if iftype == 'bridge' :
58
- new_interface .update ({
59
- 'bridge_members' : interface .get ('bridge_members' )
60
- })
61
- result .append (new_interface )
62
- return (('interfaces' , result ),)
30
+ routes = get_copy (self .netjson , 'routes' )
31
+ if routes :
32
+ route = self ._get_route (routes )
33
+ new_interface .update ({'route' : route })
34
+ mac = interface .get ('mac' , False )
35
+ if mac :
36
+ new_interface .update ({'mac' : mac })
37
+ mtu = interface .get ('mtu' , False )
38
+ if mtu :
39
+ new_interface .update ({'mtu' : mtu })
40
+ txqueuelen = interface .get ('txqueuelen' , False )
41
+ if txqueuelen :
42
+ new_interface .update ({'txqueuelen' : txqueuelen })
43
+ autostart = interface .get ('autostart' , False )
44
+ if autostart :
45
+ new_interface .update ({'autostart' : autostart })
46
+ if iftype == 'wireless' and interface .get ('wireless' ).get ('mode' ) == 'adhoc' :
47
+ wireless = interface .get ('wireless' )
48
+ new_interface .update ({
49
+ 'essid' : wireless .get ('ssid' ),
50
+ 'mode' : wireless .get ('mode' )
51
+ })
52
+ if iftype == 'bridge' :
53
+ new_interface .update ({
54
+ 'bridge_members' : interface .get ('bridge_members' )
55
+ })
56
+ return new_interface
63
57
64
58
def _get_address (self , interface ):
65
59
addresses = interface .get ('addresses' , False )
@@ -75,3 +69,16 @@ def _get_address(self, interface):
75
69
address ['netmask' ] = address ['mask' ]
76
70
del address ['mask' ]
77
71
return addresses
72
+
73
+ def _get_route (self , routes ):
74
+ for route in routes :
75
+ if ip_network (route .get ('next' )).version == 4 :
76
+ route ['version' ] = 4
77
+ destination = IPv4Interface (route ['destination' ]).with_netmask
78
+ dest , dest_mask = destination .split ('/' )
79
+ route ['dest' ] = dest
80
+ route ['dest_mask' ] = dest_mask
81
+ del route ['destination' ]
82
+ elif ip_network (route .get ('next' )).version == 6 :
83
+ route ['version' ] = 6
84
+ return route
0 commit comments