19
19
class IProute2 (InstanceModule ):
20
20
"""Test network configuration via iproute2 commands
21
21
22
- >>> host.iproute2.rules()
22
+ Optional arguments:
23
+ - family: force iproute2 tools to use a specific protocol family
24
+ - namespace: execute iproute2 tools inside the provided namespace
23
25
24
- host.ip.rules(from,to,tos,fwmark,iif,oif,pref, uidrange, ipproto, sport, dport)
25
- host.ip.routes(table, device, scope, proto, src, metric)
26
- host.ip.links()
27
- host.ip.addresses()
28
- host.ip.tunnels()
29
-
30
- Optionally, the protocol family can be provided to reduce the number of routes returned:
31
- >>> host.iproute2.routes("inet6", table="main")
32
- ...FIX
33
-
34
- Optionally, this can work inside a different network namespace:
35
- >>> host.iproute2.routes("inet6", "vpn")
36
- ...FIX
37
26
"""
38
27
39
28
def __init__ (self , family = None , namespace = None ):
@@ -58,7 +47,14 @@ def exists(self):
58
47
return self .run_test ("{} -V" .format (self ._ip )).rc == 0
59
48
60
49
def addresses (self , address = None , ifname = None , local = None ):
61
- """Return the addresses associated with interfaces"""
50
+ """Return the addresses associated with interfaces
51
+
52
+ Optionally, results can be filtered by:
53
+ - address
54
+ - ifname
55
+ - local
56
+
57
+ """
62
58
cmd = f"{ self ._ip } --json address show"
63
59
out = self .check_output (cmd )
64
60
j = json .loads (out )
@@ -86,7 +82,20 @@ def links(self):
86
82
def routes (
87
83
self , table = "all" , device = None , scope = None , proto = None , src = None , metric = None
88
84
):
89
- """Return the routes installed"""
85
+ """Returns the routes installed
86
+
87
+ Optionally, routes returned can be filtered with the following
88
+ selectors. This can be useful in busy routing tables.
89
+
90
+ Selectors:
91
+ - table
92
+ - device (maps to ip-route's 'dev' selector)
93
+ - scope
94
+ - proto
95
+ - src
96
+ - metric
97
+
98
+ """
90
99
cmd = f"{ self ._ip } --json route show "
91
100
options = []
92
101
if table is not None :
@@ -120,7 +129,25 @@ def rules(
120
129
sport = None ,
121
130
dport = None ,
122
131
):
123
- """Return the rules our routing policy consists of"""
132
+ """Returns the rules our routing policy consists of
133
+
134
+ Optionally, rules returned can be filtered with the following
135
+ selectors. This can be useful in busy rulesets.
136
+
137
+ Selectors:
138
+ - src (maps to ip-rule's 'from' selector)
139
+ - to
140
+ - tos
141
+ - fwmark
142
+ - iif
143
+ - oif
144
+ - pref
145
+ - uidrange
146
+ - ipproto
147
+ - sport
148
+ - dport
149
+
150
+ """
124
151
cmd = f"{ self ._ip } --json rule show "
125
152
126
153
options = []
@@ -162,7 +189,15 @@ def rules(
162
189
return json .loads (out )
163
190
164
191
def tunnels (self , ifname = None ):
165
- """Return all configured tunnels"""
192
+ """Returns all configured tunnels
193
+
194
+ Optionally, tunnels returned can be filtered with the interface name.
195
+ This can be faster in busy tunnel installations.
196
+
197
+ Selectors:
198
+ - ifname
199
+
200
+ """
166
201
cmd = f"{ self ._ip } --json tunnel show "
167
202
168
203
options = []
@@ -174,13 +209,13 @@ def tunnels(self, ifname=None):
174
209
return json .loads (out )
175
210
176
211
def vrfs (self ):
177
- """Return all configured vrfs"""
212
+ """Returns all configured vrfs"""
178
213
cmd = f"{ self ._ip } --json vrf show"
179
214
out = self .check_output (cmd )
180
215
return json .loads (out )
181
216
182
217
def netns (self ):
183
- """Return all configured network namespaces"""
218
+ """Returns all configured network namespaces"""
184
219
cmd = f"{ self ._ip } --json netns show"
185
220
out = self .check_output (cmd )
186
221
if not out : # ip netns returns null instead of [] in json mode
0 commit comments