From 29f128cd1f9499ad4c600898d90ebf5b9ceca5f3 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 2 Nov 2018 10:29:20 +0000 Subject: [PATCH] Check if a port can be bound to a virtual bridge If port VNIC type is "normal", the port can be bound to a virtual bridge; e.g.: Linux Bridge, OVS. Change-Id: I0dab235bd492538c7fa909dace08fad2267a589d Partial-Bug: #1566951 --- neutron_lib/plugins/utils.py | 10 ++++++++++ ...rt-be-bound-to-virtual-bridge-5d6db8785e58fcb9.yaml | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 releasenotes/notes/add-can-port-be-bound-to-virtual-bridge-5d6db8785e58fcb9.yaml diff --git a/neutron_lib/plugins/utils.py b/neutron_lib/plugins/utils.py index 2fa32a891..18d35959e 100644 --- a/neutron_lib/plugins/utils.py +++ b/neutron_lib/plugins/utils.py @@ -26,6 +26,7 @@ from neutron_lib._i18n import _ from neutron_lib.api import attributes from neutron_lib.api.definitions import network as net_apidef from neutron_lib.api.definitions import port as port_apidef +from neutron_lib.api.definitions import portbindings as pb from neutron_lib.api.definitions import portbindings_extended as pb_ext from neutron_lib.api.definitions import subnet as subnet_apidef from neutron_lib import constants @@ -382,3 +383,12 @@ def get_port_binding_by_status_and_host(bindings, status, host='', return binding if raise_if_not_found: raise exceptions.PortBindingNotFound(port_id=port_id, host=host) + + +def can_port_be_bound_to_virtual_bridge(port): + """Returns if port can be bound to a virtual bridge (e.g.: LB, OVS) + + :param port: (dict) A port dictionary. + :returns: True if the port VNIC type is 'normal'; False in any other case. + """ + return port[pb.VNIC_TYPE] == pb.VNIC_NORMAL diff --git a/releasenotes/notes/add-can-port-be-bound-to-virtual-bridge-5d6db8785e58fcb9.yaml b/releasenotes/notes/add-can-port-be-bound-to-virtual-bridge-5d6db8785e58fcb9.yaml new file mode 100644 index 000000000..54aed3542 --- /dev/null +++ b/releasenotes/notes/add-can-port-be-bound-to-virtual-bridge-5d6db8785e58fcb9.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``can_port_be_bound_to_virtual_bridge`` function in + ``neutron_lib.plugins.utils``. This function checks if a port, depending + on the VNIC type, can be bound to a virtual bridge.