libs/tools: resolve_identifier supports ip networks, not ip addresses

This commit is contained in:
Franzi 2021-02-15 13:44:21 +01:00
parent 6527c985a7
commit 9a2f9038c4
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -1,4 +1,4 @@
from ipaddress import ip_address, IPv4Address
from ipaddress import ip_address, ip_network, IPv4Address, IPv4Network
from bundlewrap.exceptions import NoSuchGroup, NoSuchNode
from bundlewrap.utils.text import bold, red
@ -16,9 +16,9 @@ def resolve_identifier(repo, identifier):
nodes = repo.nodes_in_group(identifier)
except NoSuchGroup:
try:
ip = ip_address(identifier)
ip = ip_network(identifier)
if isinstance(ip, IPv4Address):
if isinstance(ip, IPv4Network):
return {'ipv4': {ip}, 'ipv6': set()}
else:
return {'ipv4': set(), 'ipv6': {ip}}
@ -29,7 +29,7 @@ def resolve_identifier(repo, identifier):
i=identifier,
e=str(e),
))
return {'ipv4': set(), 'ipv6': set()}
raise
found_ips = set()
for node in nodes: