From 4354bc04f95c03fc90d7b596422874e329996660 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 27 Nov 2019 19:08:07 +0100 Subject: Replace netaddr dependency with stdlib ipaddress netaddr is quite a big library, and all we need is covered by the built-in ipaddress module (available in python 3). Also add a safeguard for invalid 'ip route' output. Change-Id: I9d76a8d1c1b6b1585e301a9c63b37fab3b98746f --- ironic_python_agent/hardware.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ironic_python_agent/hardware.py') diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 79f7ac8f..fd0b3f91 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -15,6 +15,7 @@ import abc import binascii import functools +import ipaddress import json from multiprocessing.pool import ThreadPool import os @@ -24,7 +25,6 @@ import time from ironic_lib import disk_utils from ironic_lib import utils as il_utils -import netaddr from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log @@ -1320,9 +1320,9 @@ class GenericHardwareManager(HardwareManager): out = out.strip() try: - netaddr.IPAddress(out) - except netaddr.AddrFormatError: - LOG.warning('Invalid IP address: %s', out) + ipaddress.ip_address(out) + except ValueError as exc: + LOG.warning('Invalid IP address %s: %s', out, exc) continue # In case we get 0.0.0.0 on a valid channel, we need to keep @@ -1397,9 +1397,9 @@ class GenericHardwareManager(HardwareManager): continue try: - return str(netaddr.IPNetwork(address).ip) - except netaddr.AddrFormatError: - LOG.warning('Invalid IP address: %s', address) + return str(ipaddress.ip_interface(address).ip) + except ValueError as exc: + LOG.warning('Invalid IP address %s: %s', address, exc) continue except (processutils.ProcessExecutionError, OSError) as e: # Not error, because it's normal in virtual environment -- cgit v1.2.1