From a3961d7f7ab9e29ca7e4cdd5e646cb2ab812a88a Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 8 Jul 2020 16:02:29 +0000 Subject: [PATCH] New api-def: port-numa-affinity-policy New API definition: ``port-numa-affinity-policy``. The new field added to ``ports`` API, ``numa_affinity_policy``, represents the NUMA affinity policy requested by this port during the virtual machine scheduling. Values: "None", "required", "preferred", "legacy". Change-Id: I5402a8ad462a10c51dc251cb4561b64dbf0b8744 Related-Bug: #1886798 --- api-ref/source/v2/parameters.yaml | 14 ++++++ api-ref/source/v2/ports.inc | 15 +++++++ neutron_lib/api/definitions/__init__.py | 2 + .../definitions/port_numa_affinity_policy.py | 45 +++++++++++++++++++ neutron_lib/api/definitions/portbindings.py | 2 + neutron_lib/constants.py | 7 +++ neutron_lib/exceptions/__init__.py | 14 ++++++ .../test_port_numa_affinity_policy.py | 22 +++++++++ ...numa-affinity-policy-9e6d1bafd3c6af36.yaml | 7 +++ 9 files changed, 128 insertions(+) create mode 100644 neutron_lib/api/definitions/port_numa_affinity_policy.py create mode 100644 neutron_lib/tests/unit/api/definitions/test_port_numa_affinity_policy.py create mode 100644 releasenotes/notes/port-numa-affinity-policy-9e6d1bafd3c6af36.yaml diff --git a/api-ref/source/v2/parameters.yaml b/api-ref/source/v2/parameters.yaml index 2620eb7bf..a942e900a 100644 --- a/api-ref/source/v2/parameters.yaml +++ b/api-ref/source/v2/parameters.yaml @@ -4131,6 +4131,20 @@ networks: in: body required: true type: array +numa_affinity_policy: + description: | + The port NUMA affinity policy requested during the virtual machine + scheduling. Values: ``None``, ``requiered``, ``preferred`` or ``legacy``. + in: body + required: False + type: string +numa_affinity_policy-request: + description: | + The port NUMA affinity policy requested during the virtual machine + scheduling. Values: ``None``, ``requiered``, ``preferred`` or ``legacy``. + in: body + required: False + type: string object_id: description: | The ID of the ``object_type`` resource. An ``object_type`` of ``network`` diff --git a/api-ref/source/v2/ports.inc b/api-ref/source/v2/ports.inc index 0c4152183..7a22c2328 100644 --- a/api-ref/source/v2/ports.inc +++ b/api-ref/source/v2/ports.inc @@ -85,6 +85,13 @@ The ``mac_learning_enabled`` extension extends neutron ports providing the ability to enable MAC learning on the associated port via the ```mac_learning_enabled``` attribute. +NUMA affinity policy +==================== + +The NUMA affinity policy extension (``port-numa-affinity-policy``) defines +the Nova scheduling strategy according to the network backend NUMA topology. +This parameter could be ``required``, ``preferred``, ``legacy`` or ``None``. + Port binding extended attributes ================================ @@ -206,6 +213,7 @@ Response Parameters - mac_address: mac_address - name: name - network_id: network_id + - numa_affinity_policy: numa_affinity_policy - port_security_enabled: port_security_enabled - project_id: project_id - qos_network_policy_id: qos_network_policy_id-port-response @@ -289,6 +297,7 @@ Request - fixed_ips: fixed_ips-request - mac_address: mac_address-request-put - name: name-request + - numa_affinity_policy: numa_affinity_policy-request - port_security_enabled: port_security_enabled-request - qos_policy_id: qos_policy_id-port-request - security_groups: port-security_groups-request @@ -334,6 +343,7 @@ Response Parameters - mac_address: mac_address - name: name - network_id: network_id + - numa_affinity_policy: numa_affinity_policy - port_security_enabled: port_security_enabled - project_id: project_id - qos_network_policy_id: qos_network_policy_id-port-response @@ -470,6 +480,7 @@ Response Parameters - mac_address: mac_address - name: name - network_id: network_id + - numa_affinity_policy: numa_affinity_policy - port_security_enabled: port_security_enabled - project_id: project_id - qos_network_policy_id: qos_network_policy_id-port-response @@ -531,6 +542,7 @@ Request - mac_address: mac_address-request - name: name-request - network_id: network_id + - numa_affinity_policy: numa_affinity_policy-request - port_security_enabled: port_security_enabled-request - project_id: project_id-request - qos_policy_id: qos_policy_id-port-request @@ -579,6 +591,7 @@ Response Parameters - mac_address: mac_address - name: name - network_id: network_id + - numa_affinity_policy: numa_affinity_policy - port_security_enabled: port_security_enabled - project_id: project_id - qos_network_policy_id: qos_network_policy_id-port-response @@ -639,6 +652,7 @@ Request - mac_address: mac_address-request - name: name-request - network_id: network_id + - numa_affinity_policy: numa_affinity_policy-request - port_security_enabled: port_security_enabled-request - project_id: project_id-request - qos_policy_id: qos_policy_id-port-request @@ -681,6 +695,7 @@ Response Parameters - mac_address: mac_address - name: name - network_id: network_id + - numa_affinity_policy: numa_affinity_policy - port_security_enabled: port_security_enabled - project_id: project_id - qos_network_policy_id: qos_network_policy_id-port-response diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 94bf81d84..5bdb0116e 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -70,6 +70,7 @@ from neutron_lib.api.definitions import network_segment_range from neutron_lib.api.definitions import pagination from neutron_lib.api.definitions import port from neutron_lib.api.definitions import port_mac_address_regenerate +from neutron_lib.api.definitions import port_numa_affinity_policy from neutron_lib.api.definitions import port_resource_request from neutron_lib.api.definitions import port_security from neutron_lib.api.definitions import portbindings @@ -181,6 +182,7 @@ _ALL_API_DEFINITIONS = { pagination, port, port_mac_address_regenerate, + port_numa_affinity_policy, port_resource_request, port_security, portbindings, diff --git a/neutron_lib/api/definitions/port_numa_affinity_policy.py b/neutron_lib/api/definitions/port_numa_affinity_policy.py new file mode 100644 index 000000000..b364c9e28 --- /dev/null +++ b/neutron_lib/api/definitions/port_numa_affinity_policy.py @@ -0,0 +1,45 @@ +# Copyright (c) 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import port +from neutron_lib import constants + + +ALIAS = 'port-numa-affinity-policy' +IS_SHIM_EXTENSION = False +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Port NUMA affinity policy' +DESCRIPTION = "Expose the port NUMA affinity policy" +UPDATED_TIMESTAMP = "2020-07-08T10:00:00-00:00" +RESOURCE_NAME = port.RESOURCE_NAME +COLLECTION_NAME = port.COLLECTION_NAME +NUMA_AFFINITY_POLICY = 'numa_affinity_policy' + +RESOURCE_ATTRIBUTE_MAP = { + COLLECTION_NAME: { + NUMA_AFFINITY_POLICY: { + 'allow_post': True, + 'allow_put': True, + 'validate': { + 'type:values': constants.PORT_NUMA_POLICIES + (None, )}, + 'default': None, + 'is_visible': True} + }, +} + +SUB_RESOURCE_ATTRIBUTE_MAP = None +ACTION_MAP = {} +ACTION_STATUS = {} +REQUIRED_EXTENSIONS = [] +OPTIONAL_EXTENSIONS = [] diff --git a/neutron_lib/api/definitions/portbindings.py b/neutron_lib/api/definitions/portbindings.py index 7394ef7d4..63dd83a38 100644 --- a/neutron_lib/api/definitions/portbindings.py +++ b/neutron_lib/api/definitions/portbindings.py @@ -105,6 +105,8 @@ VIF_TYPE_AGILIO_OVS = 'agilio_ovs' VIF_TYPE_HW_VEB = 'hw_veb' VIF_TYPE_HOSTDEV_PHY = 'hostdev_physical' +VIF_UNPLUGGED_TYPES = (VIF_TYPE_BINDING_FAILED, VIF_TYPE_UNBOUND) + # VNIC_TYPE: It's used to determine which mechanism driver to use to bind a # port. It can be specified via the Neutron API. Default is normal, # used by OVS and LinuxBridge agent. diff --git a/neutron_lib/constants.py b/neutron_lib/constants.py index b8511f1ed..538732ef7 100644 --- a/neutron_lib/constants.py +++ b/neutron_lib/constants.py @@ -641,3 +641,10 @@ EXT_PARENT_PREFIX = 'ext_parent' RP_BANDWIDTHS = 'resource_provider_bandwidths' RP_INVENTORY_DEFAULTS = 'resource_provider_inventory_defaults' + +# Port NUMA affinity policies, matching Nova NUMA affinity policy constants +PORT_NUMA_POLICY_REQUIRED = 'required' +PORT_NUMA_POLICY_PREFERRED = 'preferred' +PORT_NUMA_POLICY_LEGACY = 'legacy' +PORT_NUMA_POLICIES = (PORT_NUMA_POLICY_REQUIRED, PORT_NUMA_POLICY_PREFERRED, + PORT_NUMA_POLICY_LEGACY) diff --git a/neutron_lib/exceptions/__init__.py b/neutron_lib/exceptions/__init__.py index 7f209bbd6..b8ee04786 100644 --- a/neutron_lib/exceptions/__init__.py +++ b/neutron_lib/exceptions/__init__.py @@ -266,6 +266,20 @@ class PortBound(InUse): "old_mac %(old_mac)s, new_mac %(new_mac)s.") +class PortBoundNUMAAffinityPolicy(InUse): + """An operational error indicating a port is already bound. + + NUMA affinity policy cannot be modified when the port is bound. + + :param port_id: The UUID of the port requested. + :param host_id: The host ID where the port is bound. + :param numa_affinity_policy: value passed to be updated. + """ + message = _("Unable to complete operation on port %(port_id)s, " + "port is already bound to host %(host_id)s, " + "numa_affinity_policy value given %(numa_affinity_policy)s.") + + class MacAddressInUse(InUse): """An network operational error indicating a MAC address is already in use. diff --git a/neutron_lib/tests/unit/api/definitions/test_port_numa_affinity_policy.py b/neutron_lib/tests/unit/api/definitions/test_port_numa_affinity_policy.py new file mode 100644 index 000000000..d2f418766 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_port_numa_affinity_policy.py @@ -0,0 +1,22 @@ +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import port_numa_affinity_policy +from neutron_lib.tests.unit.api.definitions import base + + +class PortNumaAffinityPolicyDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = port_numa_affinity_policy + extension_resources = (port_numa_affinity_policy.COLLECTION_NAME,) + extension_attributes = (port_numa_affinity_policy.NUMA_AFFINITY_POLICY,) diff --git a/releasenotes/notes/port-numa-affinity-policy-9e6d1bafd3c6af36.yaml b/releasenotes/notes/port-numa-affinity-policy-9e6d1bafd3c6af36.yaml new file mode 100644 index 000000000..1c38c2764 --- /dev/null +++ b/releasenotes/notes/port-numa-affinity-policy-9e6d1bafd3c6af36.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + New API definition: ``port-numa-affinity-policy``. The new field added to + ``ports`` API, ``numa_affinity_policy``, represents the NUMA affinity + policy requested by this port during the virtual machine scheduling. + Values: None, "required", "preferred", "legacy".