Skip to content

Commit e394bc6

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: add ad dc functions for interface filtering
These functions will later be used by the provisioning (sub)command to filter interfaces without having to know exactly what is on the target system. Signed-off-by: John Mulligan <[email protected]>
1 parent 9446b35 commit e394bc6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sambacc/addc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#
1818

1919
import logging
20+
import re
2021
import subprocess
2122
import typing
2223

24+
from sambacc import config
2325
from sambacc import samba_cmds
2426

2527
_logger = logging.getLogger(__name__)
@@ -215,3 +217,24 @@ def _group_add_members_cmd(group_name: str, members: list[str]) -> list[str]:
215217
",".join(members),
216218
].argv()
217219
return cmd
220+
221+
222+
def _ifnames() -> list[str]:
223+
import socket
224+
225+
return [iface for _, iface in socket.if_nameindex()]
226+
227+
228+
def filtered_interfaces(
229+
ic: config.DCInterfaceConfig, ifnames: typing.Optional[list[str]] = None
230+
) -> list[str]:
231+
_include = re.compile(ic.include_pattern or "^.*$")
232+
_exclude = re.compile(ic.exclude_pattern or "^$")
233+
if ifnames is None:
234+
ifnames = _ifnames()
235+
return [
236+
name
237+
for name in ifnames
238+
if (name == "lo")
239+
or (_include.match(name) and not _exclude.match(name))
240+
]

0 commit comments

Comments
 (0)