add ipaddress for base class

This commit is contained in:
IluaAir
2025-06-25 17:22:57 +03:00
parent 2e54749159
commit 8bb5ae94df

View File

@@ -1,3 +1,4 @@
import ipaddress
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import Protocol from typing import Protocol
@@ -81,7 +82,12 @@ class BaseDevice(Protocol):
ip_address_match = re.search(r'\s?ip address\s(.+)$', interface_block, re.MULTILINE) ip_address_match = re.search(r'\s?ip address\s(.+)$', interface_block, re.MULTILINE)
if not description_match and not ip_address_match: if not description_match and not ip_address_match:
continue continue
ip_address = ip_address_match.group(1).replace(' ', '/') if ip_address_match else None ip_address = ip_address_match.group(1).replace(' ', '/').replace('\r', '') if ip_address_match else None
try:
if ip_address is not None:
ip_address = ipaddress.ip_interface(ip_address)
except ValueError:
continue
description = description_match.group(1) if description_match else None description = description_match.group(1) if description_match else None
interfaces.append(L3Interface( interfaces.append(L3Interface(
interface=interface_name, interface=interface_name,