libs.tools.resolve_identifier(): add option to filter out linklocal ips and only physical interfaces
This commit is contained in:
parent
6539923644
commit
2b51812118
3 changed files with 19 additions and 27 deletions
|
@ -5,7 +5,7 @@ from bundlewrap.utils.text import bold, red
|
|||
from bundlewrap.utils.ui import io
|
||||
|
||||
|
||||
def resolve_identifier(repo, identifier):
|
||||
def resolve_identifier(repo, identifier, linklocal=False, only_physical=False):
|
||||
"""
|
||||
Try to resolve an identifier (group or node). Return a set of ip
|
||||
addresses valid for this identifier.
|
||||
|
@ -34,6 +34,15 @@ def resolve_identifier(repo, identifier):
|
|||
found_ips = set()
|
||||
for node in nodes:
|
||||
for interface, config in node.metadata.get('interfaces', {}).items():
|
||||
if only_physical and not (
|
||||
interface.startswith('bond') or
|
||||
interface.startswith('br') or
|
||||
interface.startswith('en') or
|
||||
interface.startswith('et') or
|
||||
interface == 'default' # dummy nodes use these
|
||||
):
|
||||
continue
|
||||
|
||||
for ip in config.get('ips', set()):
|
||||
if '/' in ip:
|
||||
found_ips.add(ip_address(ip.split('/')[0]))
|
||||
|
@ -54,6 +63,9 @@ def resolve_identifier(repo, identifier):
|
|||
}
|
||||
|
||||
for ip in found_ips:
|
||||
if ip.is_link_local and not linklocal:
|
||||
continue
|
||||
|
||||
if isinstance(ip, IPv4Address):
|
||||
ip_dict['ipv4'].add(ip)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue