diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index e0ed5e751cf..ea6a0ea93b1 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -1135,7 +1135,7 @@ def add_namespace_to_cmd(cmd, namespace=None): def get_ip_version(ip_or_cidr): - return netaddr.IPNetwork(ip_or_cidr).version + return common_utils.get_ip_version(ip_or_cidr) def get_ipv6_lladdr(mac_addr): diff --git a/neutron/agent/linux/openvswitch_firewall/rules.py b/neutron/agent/linux/openvswitch_firewall/rules.py index 233972ed91f..a7a7803b769 100644 --- a/neutron/agent/linux/openvswitch_firewall/rules.py +++ b/neutron/agent/linux/openvswitch_firewall/rules.py @@ -18,7 +18,6 @@ from neutron_lib import constants as n_consts from oslo_log import log as logging from neutron.agent import firewall -from neutron.agent.linux import ip_lib from neutron.agent.linux.openvswitch_firewall import constants as ovsfw_consts from neutron.common import utils from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants \ @@ -49,15 +48,15 @@ def create_flows_from_rule_and_port(rule, port): } if is_valid_prefix(dst_ip_prefix): - if ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_4: + if utils.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_4: flow_template["nw_dst"] = dst_ip_prefix - elif ip_lib.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_6: + elif utils.get_ip_version(dst_ip_prefix) == n_consts.IP_VERSION_6: flow_template["ipv6_dst"] = dst_ip_prefix if is_valid_prefix(src_ip_prefix): - if ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_4: + if utils.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_4: flow_template["nw_src"] = src_ip_prefix - elif ip_lib.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_6: + elif utils.get_ip_version(src_ip_prefix) == n_consts.IP_VERSION_6: flow_template["ipv6_src"] = src_ip_prefix flows = create_protocol_flows(direction, flow_template, port, rule) diff --git a/neutron/common/utils.py b/neutron/common/utils.py index 71b633eca4a..bb370756da9 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -335,6 +335,10 @@ def is_cidr_host(cidr): return net.prefixlen == n_const.IPv6_BITS +def get_ip_version(ip_or_cidr): + return netaddr.IPNetwork(ip_or_cidr).version + + def ip_version_from_int(ip_version_int): if ip_version_int == 4: return n_const.IPv4