mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ce_engine: Refactor check_ip_addr (#34126)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
47665ca335
commit
0196b6bb69
2 changed files with 2 additions and 40 deletions
|
@ -195,7 +195,7 @@ import sys
|
||||||
import socket
|
import socket
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, ce_argument_spec
|
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, ce_argument_spec, check_ip_addr
|
||||||
|
|
||||||
CE_NC_GET_BFD = """
|
CE_NC_GET_BFD = """
|
||||||
<filter type="subtree">
|
<filter type="subtree">
|
||||||
|
@ -219,24 +219,6 @@ CE_NC_GET_BFD_GLB = """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def check_ip_addr(ipaddr):
|
|
||||||
"""check ip address, Supports IPv4 and IPv6"""
|
|
||||||
|
|
||||||
if not ipaddr or '\x00' in ipaddr:
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
|
|
||||||
socket.SOCK_STREAM,
|
|
||||||
0, socket.AI_NUMERICHOST)
|
|
||||||
return bool(res)
|
|
||||||
except socket.gaierror:
|
|
||||||
err = sys.exc_info()[1]
|
|
||||||
if err.args[0] == socket.EAI_NONAME:
|
|
||||||
return False
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
def check_default_ip(ipaddr):
|
def check_default_ip(ipaddr):
|
||||||
"""check the default multicast IP address"""
|
"""check the default multicast IP address"""
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ import sys
|
||||||
import socket
|
import socket
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, ce_argument_spec
|
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, ce_argument_spec, check_ip_addr
|
||||||
|
|
||||||
|
|
||||||
CE_NC_GET_BFD = """
|
CE_NC_GET_BFD = """
|
||||||
|
@ -229,26 +229,6 @@ def is_valid_ip_vpn(vpname):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_ip_addr(ipaddr):
|
|
||||||
"""check ip address, Supports IPv4 and IPv6"""
|
|
||||||
|
|
||||||
if not ipaddr or '\x00' in ipaddr:
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
res = socket.getaddrinfo(ipaddr, 0, socket.AF_UNSPEC,
|
|
||||||
socket.SOCK_STREAM,
|
|
||||||
0, socket.AI_NUMERICHOST)
|
|
||||||
return bool(res)
|
|
||||||
except socket.gaierror:
|
|
||||||
err = sys.exc_info()[1]
|
|
||||||
if err.args[0] == socket.EAI_NONAME:
|
|
||||||
return False
|
|
||||||
raise
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def check_default_ip(ipaddr):
|
def check_default_ip(ipaddr):
|
||||||
"""check the default multicast IP address"""
|
"""check the default multicast IP address"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue