summaryrefslogtreecommitdiff
path: root/ironic_python_agent/hardware.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2019-11-27 19:08:07 +0100
committerDmitry Tantsur <dtantsur@protonmail.com>2019-12-02 12:13:04 +0100
commit4354bc04f95c03fc90d7b596422874e329996660 (patch)
treeb56108da504e1622b4495e72b8862c96d377405f /ironic_python_agent/hardware.py
parent9f6c2aa05bce227efafd4d9b4c316664cccdfbae (diff)
downloadironic-python-agent-4354bc04f95c03fc90d7b596422874e329996660.tar.gz
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
Diffstat (limited to 'ironic_python_agent/hardware.py')
-rw-r--r--ironic_python_agent/hardware.py14
1 files changed, 7 insertions, 7 deletions
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