diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-03-30 23:02:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 21:02:44 -0600 |
commit | 4f825b3e6d8fde5c239d29639b04d2bea6d95d0e (patch) | |
tree | 4d73682ac9118d057e1009aae02e18f3139e5244 /cloudinit/net/__init__.py | |
parent | ee0377924aa6bcd072dc5836dbf8ac51110bd87d (diff) | |
download | vyos-cloud-init-4f825b3e6d8fde5c239d29639b04d2bea6d95d0e.tar.gz vyos-cloud-init-4f825b3e6d8fde5c239d29639b04d2bea6d95d0e.zip |
cloudinit: refactor util.is_ipv4 to net.is_ipv4_address (#292)
This also simplifies the implementation to rely on the stdlib, instead
of our own NIH checking.
Diffstat (limited to 'cloudinit/net/__init__.py')
-rw-r--r-- | cloudinit/net/__init__.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index 08eaf0a3..cb8c1601 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -978,6 +978,22 @@ def is_ip_address(s: str) -> bool: return True +def is_ipv4_address(s: str) -> bool: + """Returns a bool indicating if ``s`` is an IPv4 address. + + :param s: + The string to test. + + :return: + A bool indicating if the string contains an IPv4 address or not. + """ + try: + ipaddress.IPv4Address(s) + except ValueError: + return False + return True + + class EphemeralIPv4Network(object): """Context manager which sets up temporary static network configuration. |