ifstate 2.0.0rc6__py3-none-any.whl → 2.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ifstate/ifstate.py CHANGED
@@ -131,7 +131,7 @@ def main():
131
131
  parser.add_argument('--version', action='version',
132
132
  version='%(prog)s {version}'.format(version=__version__))
133
133
  group.add_argument("-v", "--verbose", action="count", default=0,
134
- help="be more verbose")
134
+ help="be more verbose (twice for very verbose)")
135
135
  group.add_argument("-q", "--quiet", action="store_true",
136
136
  help="be more quiet, print only warnings and errors")
137
137
  parser.add_argument("-s", "--soft-schema", action="store_true",
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ifstate
3
- Version: 2.0.0rc6
3
+ Version: 2.0.2
4
4
  Summary: Manage host interface settings in a declarative manner
5
5
  Home-page: https://ifstate.net/
6
6
  Author: Thomas Liske
7
7
  Author-email: thomas@fiasko-nw.net
8
8
  License: GPL3+
9
+ Requires-Python: >=3.10
9
10
  Description-Content-Type: text/markdown
10
11
  License-File: LICENSE
11
12
  Requires-Dist: jsonschema
@@ -25,6 +26,7 @@ Dynamic: license
25
26
  Dynamic: license-file
26
27
  Dynamic: provides-extra
27
28
  Dynamic: requires-dist
29
+ Dynamic: requires-python
28
30
  Dynamic: summary
29
31
 
30
32
  # IfState
@@ -1,12 +1,12 @@
1
1
  ifstate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- ifstate/ifstate.py,sha256=hmc_AWohcYVzWHU7vooWey0HDqZQOs6Yq8YZAMZBCgo,9304
2
+ ifstate/ifstate.py,sha256=Vot_Bo0MGT_5MUKD5-pt2xB-fLLkjwvJo24KgtETtR8,9329
3
3
  ifstate/shell.py,sha256=7_JFpi4icr9MijynDzbb0v5mxhFsng6PCC4m3uQ255A,2177
4
4
  ifstate/vrrp.py,sha256=FJ9b1eJseTtZFfknHU-xV68Qz7cPrRrc5PTcjUVj-fY,5953
5
- ifstate-2.0.0rc6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
6
- libifstate/__init__.py,sha256=sJRqKeltu3k9_X-uPS4yc1_aw0KR_bDTpxoBI2p0BDM,34056
5
+ ifstate-2.0.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
6
+ libifstate/__init__.py,sha256=QtL4RLZeAijw8PhXbNkpBpd2esgaHlaGu-xOtjbJmqM,34375
7
7
  libifstate/exception.py,sha256=NmKqD9O8dRWBgO__Pt0_wGSR5GWZ1RHXZZEUI3ArVLo,2360
8
8
  libifstate/log.py,sha256=rG0ISWyeGGlC_jRREoSpkdySc5EmyhOQIgSfvRqlaZA,4651
9
- libifstate/util.py,sha256=DqYyFzNqRceJxxGqTg94gT8OTHQQ2gZxQOo5Gzx6-6s,11555
9
+ libifstate/util.py,sha256=f5HPazDNbwtADJwXwhgx9YMmMfDj5NDokhpaAJBUV4I,10745
10
10
  libifstate/address/__init__.py,sha256=SobrZ9e2ItrmEidnKPBhUMitRDdTEajbkU9Rkmtx-gQ,3165
11
11
  libifstate/bpf/__init__.py,sha256=NVzaunTmJU2PbIQg9eWBMKpFgLh3EnD3ujNa7Yt6rNc,7699
12
12
  libifstate/bpf/ctypes.py,sha256=kLZJHZlba09Vc-tbsJAcKpDwdoNO2IjlYVLCopawHmA,4274
@@ -27,13 +27,13 @@ libifstate/parser/__init__.py,sha256=uzv5U-6RPy-SSIyxR6H_F0SvAOQQF8x5ygErpUhsa7Y
27
27
  libifstate/parser/base.py,sha256=v0S_R_aMZBdHJPI3zdelv5G0Xha-pUV2DRdmxhD7390,6624
28
28
  libifstate/parser/yaml.py,sha256=MC0kmwqt3P45z61fb_wfUqoj0iZyhFYkdPyr0UqMSZA,1415
29
29
  libifstate/routing/__init__.py,sha256=O4lbaCJvLgx-iQUa0WDgRmSPR4AKvveqPgxxb4HwYQ4,25305
30
- libifstate/schema/2/ifstate.conf.schema.json,sha256=hVf0fduVV09uw3ZphWWwGpeQ7nL5z1aLTHUEemn34wc,221185
30
+ libifstate/schema/2/ifstate.conf.schema.json,sha256=WYjy0BoRPCK59Fv7Z-rMu4-RVPT1v_9w7yVIlQVxros,221181
31
31
  libifstate/sysctl/__init__.py,sha256=_QNmH0CirbBy8VAupTm6UhIhB88fGWqUy9TnfmS0j5I,3637
32
- libifstate/tc/__init__.py,sha256=T8LEBxiHZH4sayPn9lK5hK8eB8dskuw6-kw81W_aMWU,12097
32
+ libifstate/tc/__init__.py,sha256=48qZo1poc4v7KKiNpUsHVuRBQyu92LaNcEMtRHjDjt8,12093
33
33
  libifstate/wireguard/__init__.py,sha256=VSn3PzQXwZeRV1qf5nOc_RbeePQlXu8FUh2Lg356-ZA,8869
34
34
  libifstate/xdp/__init__.py,sha256=X1xhEIGng7R5d5F4KsChykT2g6H-XBRWbWABijoYDQA,7208
35
- ifstate-2.0.0rc6.dist-info/METADATA,sha256=_TQXDh5XJSUFCPgE1D4O11eyO6P8NBoaQsB6GwTc49M,1607
36
- ifstate-2.0.0rc6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- ifstate-2.0.0rc6.dist-info/entry_points.txt,sha256=HF6jX7Uu_nF1Ly-J9uEPeiRapOxnM6LuHsb2y6Mt-k4,52
38
- ifstate-2.0.0rc6.dist-info/top_level.txt,sha256=A7peI7aKBaM69fsiSPvMbL3rzTKZZr5qDxKC-pHMGdE,19
39
- ifstate-2.0.0rc6.dist-info/RECORD,,
35
+ ifstate-2.0.2.dist-info/METADATA,sha256=nycqBEIXnGHt7UxjyTBjb3W99lQKGemkK1UZF2LCaz0,1653
36
+ ifstate-2.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ ifstate-2.0.2.dist-info/entry_points.txt,sha256=HF6jX7Uu_nF1Ly-J9uEPeiRapOxnM6LuHsb2y6Mt-k4,52
38
+ ifstate-2.0.2.dist-info/top_level.txt,sha256=A7peI7aKBaM69fsiSPvMbL3rzTKZZr5qDxKC-pHMGdE,19
39
+ ifstate-2.0.2.dist-info/RECORD,,
libifstate/__init__.py CHANGED
@@ -54,7 +54,7 @@ import json
54
54
  import errno
55
55
  import logging
56
56
 
57
- __version__ = "2.0.0rc6"
57
+ __version__ = "2.0.2"
58
58
 
59
59
  class IfState():
60
60
  def __init__(self):
@@ -136,16 +136,15 @@ class IfState():
136
136
  self.link_registry = LinkRegistry(self.ignore.get('ifname', []), self.root_netns)
137
137
 
138
138
  self._update(self.root_netns, ifstates)
139
- if 'namespaces' in ifstates:
140
- self.namespaces = {}
141
- self.new_namespaces = []
142
- for netns_name, netns_ifstates in ifstates['namespaces'].items():
143
- is_new = netns_name not in pyroute2.netns.listnetns()
144
- self.namespaces[netns_name] = NetNameSpace(netns_name)
145
- if is_new:
146
- self.new_namespaces.append(netns_name)
147
- self.link_registry.inventory_netns(self.namespaces[netns_name])
148
- self._update(self.namespaces[netns_name], netns_ifstates)
139
+ self.namespaces = {}
140
+ self.new_namespaces = []
141
+ for netns_name, netns_ifstates in ifstates.get('namespaces', {}).items():
142
+ is_new = netns_name not in pyroute2.netns.listnetns()
143
+ self.namespaces[netns_name] = NetNameSpace(netns_name)
144
+ if is_new:
145
+ self.new_namespaces.append(netns_name)
146
+ self.link_registry.inventory_netns(self.namespaces[netns_name])
147
+ self._update(self.namespaces[netns_name], netns_ifstates)
149
148
 
150
149
  def _update(self, netns, ifstates):
151
150
  # parse network sysctl settings
@@ -169,6 +168,7 @@ class IfState():
169
168
  netns.bpf_progs.add(name, config)
170
169
 
171
170
  # add interfaces from config
171
+ ifb_ifaces = {}
172
172
  for name, ifstate in ifstates['interfaces'].items():
173
173
  kind = ifstate['link']['kind']
174
174
  defaults = self.get_defaults(
@@ -235,7 +235,7 @@ class IfState():
235
235
  netns.sysctl.add(name, ifstate['sysctl'])
236
236
 
237
237
  if 'cshaper' in ifstate:
238
- profile_name = ifstate['parameters']['cshaper'].get(
238
+ profile_name = ifstate['cshaper'].get(
239
239
  'profile', 'default')
240
240
  logger.debug('cshaper profile {} enabled'.format(profile_name),
241
241
  extra={'iface': name, 'netns': netns})
@@ -247,8 +247,8 @@ class IfState():
247
247
  logger.debug('cshaper ifb name {}'.format(ifb_name),
248
248
  extra={'iface': name, 'netns': netns})
249
249
 
250
- ifb_state = {
251
- 'name': ifb_name,
250
+ # prepare ifb interface settings
251
+ ifb_ifaces[ifb_name] = {
252
252
  'link': {
253
253
  'state': 'up',
254
254
  'kind': 'ifb',
@@ -257,13 +257,19 @@ class IfState():
257
257
  'qdisc': cshaper_profile['ingress_qdisc'],
258
258
  }
259
259
  }
260
- ifb_state['tc']['qdisc']['bandwidth'] = ifstate['parameters']['cshaper'].get(
260
+
261
+ # configure tc on ifb
262
+ ifb_ifaces[ifb_name]['tc']['qdisc']['bandwidth'] = ifstate['cshaper'].get(
261
263
  'ingress', 'unlimited')
264
+ netns.tc[ifb_name] = TC(netns, ifb_name, ifb_ifaces[ifb_name]['tc'])
262
265
 
266
+ # clone vrrp settings
263
267
  if 'vrrp' in ifstate:
264
- ifb_state['vrrp'] = ifstate['vrrp']
268
+ ifb_ifaces[ifb_name]['vrrp'] = ifstate['vrrp']
265
269
 
266
- ifstates['interfaces'].append(ifb_state)
270
+ # add ifb link to known links
271
+ netns.links[ifb_name] = Link(self,
272
+ netns, ifb_name, ifb_ifaces[ifb_name]["link"], {}, None, [], ifstate.get('vrrp'), None)
267
273
 
268
274
  # egress
269
275
  if 'tc' in ifstate:
@@ -290,10 +296,9 @@ class IfState():
290
296
  ]
291
297
  }
292
298
 
293
- ifstate['tc']['qdisc']['bandwidth'] = ifstate['parameters']['cshaper'].get(
294
- 'egress', 'unlimited')
299
+ ifstate['tc']['qdisc']['bandwidth'] = ifstate['cshaper'].get('egress', 'unlimited')
295
300
 
296
- del ifstate['parameters']['cshaper']
301
+ del ifstate['cshaper']
297
302
 
298
303
  if 'tc' in ifstate:
299
304
  netns.tc[name] = TC(
@@ -318,17 +323,20 @@ class IfState():
318
323
 
319
324
  netns.xdp[name] = XDP(netns, name, ifstate['xdp'])
320
325
 
326
+ # cshaper: append ifb interfaces to config
327
+ ifstates['interfaces'].update(ifb_ifaces)
328
+
321
329
  # add routing from config
322
330
  if 'routing' in ifstates:
331
+ if netns.tables is None:
332
+ netns.tables = Tables(netns)
323
333
  if 'routes' in ifstates['routing']:
324
- if netns.tables is None:
325
- netns.tables = Tables(netns)
326
334
  for route in ifstates['routing']['routes']:
327
335
  netns.tables.add(route)
328
336
 
337
+ if netns.rules is None:
338
+ netns.rules = Rules(netns)
329
339
  if 'rules' in ifstates['routing']:
330
- if netns.rules is None:
331
- netns.rules = Rules(netns)
332
340
  for rule in ifstates['routing']['rules']:
333
341
  netns.rules.add(rule)
334
342
 
@@ -1757,7 +1757,7 @@
1757
1757
  "additionalProperties": false,
1758
1758
  "properties": {
1759
1759
  "script": {
1760
- "description": "filename to be executed on interface configuration: the hook name will be used by default; relatives file are based on `/etc/needrestart/hooks`",
1760
+ "description": "filename to be executed on interface configuration: the hook name will be used by default; relatives file are based on `/etc/ifstate/hooks`",
1761
1761
  "type": "string",
1762
1762
  "minLength": 1
1763
1763
  },
libifstate/tc/__init__.py CHANGED
@@ -199,7 +199,7 @@ class TC():
199
199
  "parent": parent,
200
200
  }
201
201
  try:
202
- self.netns.ipr.del_filter_by_info(**opts)
202
+ self.netns.ipr.tc("del-filter", **opts)
203
203
  except Exception as err:
204
204
  if not isinstance(err, netlinkerror_classes):
205
205
  raise
@@ -241,7 +241,7 @@ class TC():
241
241
  "info": tc_filter["prio"] << 16,
242
242
  "parent": parent,
243
243
  }
244
- self.netns.ipr.del_filter_by_info(**opts)
244
+ self.netns.ipr.tc("del-filter", **opts)
245
245
  self.netns.ipr.tc("add-filter", **tc_filter)
246
246
 
247
247
  except Exception as err:
libifstate/util.py CHANGED
@@ -171,21 +171,6 @@ class IPRouteExt(IPRoute):
171
171
  self.__sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
172
172
  self.sysfs_path = "/sys"
173
173
 
174
- def del_filter_by_info(self, index=0, handle=0, info=0, parent=0):
175
- msg = tcmsg()
176
- msg['index'] = index
177
- msg['handle'] = handle
178
- msg['info'] = info
179
- if parent != 0:
180
- msg['parent'] = parent
181
-
182
- return tuple(self.nlm_request(
183
- msg,
184
- msg_type=RTM_DELTFILTER,
185
- msg_flags=NLM_F_REQUEST |
186
- NLM_F_ACK
187
- ))
188
-
189
174
  def get_ifname_by_index(self, index):
190
175
  link = next(iter(self.get_links(index)), None)
191
176
 
@@ -268,21 +253,6 @@ class NetNSExt(NetNS):
268
253
  except OSError:
269
254
  pass
270
255
 
271
- def del_filter_by_info(self, index=0, handle=0, info=0, parent=0):
272
- msg = tcmsg()
273
- msg['index'] = index
274
- msg['handle'] = handle
275
- msg['info'] = info
276
- if parent != 0:
277
- msg['parent'] = parent
278
-
279
- return tuple(self.nlm_request(
280
- msg,
281
- msg_type=RTM_DELTFILTER,
282
- msg_flags=NLM_F_REQUEST |
283
- NLM_F_ACK
284
- ))
285
-
286
256
  def get_ifname_by_index(self, index):
287
257
  link = next(iter(self.get_links(index)), None)
288
258