add ipaddress for base class
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user