Allow max_tx_rate config on Horizon

There was no field in the Horizon interface dialogs to specify the
max-tx-rate. This commit adds the max_tx_rate field to the Add,
Modify and Details dialogs.

Test plan

PASS Add interface with max_tx_rate set to 100
PASS Add interface with max_tx_rate set to 0
PASS Add interface with max_tx_rate set to empty
PASS Modify interface with max_tx_rate previously set to 100, changing it to 200
PASS Modify interface with max_tx_rate previously set to 100, changing it to 0
PASS Modify interface with max_tx_rate previously set to 100, changing it to empty
PASS Modify interface with max_tx_rate previously set to 0, changing it to 100
PASS Modify interface with max_tx_rate previously set to 0, changing it to empty
PASS View details of interface with max_tx_rate set to 0
PASS View details of interface with max_tx_rate set to 100
PASS View details of interface with max_tx_rate set to empty

Closes-Bug: #2000635

Signed-off-by: Lucas Ratusznei Fonseca <lucas.ratuszneifonseca@windriver.com>
Change-Id: I16ce1dbd2dbf12367ed6a4428216ad37b4c31f14
This commit is contained in:
Lucas Ratusznei Fonseca 2022-12-28 11:49:57 -03:00
parent 559f04a695
commit 5e81ff8710
4 changed files with 39 additions and 5 deletions

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
#
# Copyright (c) 2013-2021 Wind River Systems, Inc.
# Copyright (c) 2013-2023 Wind River Systems, Inc.
#
from __future__ import absolute_import
@ -242,7 +242,7 @@ class Port(base.APIResourceWrapper):
'psvendor', 'psdevice', 'numa_node', 'mac', 'mtu', 'speed',
'link_mode', 'capabilities', 'host_uuid', 'interface_uuid',
'bootp', 'autoneg', 'type', 'sriov_numvfs', 'sriov_totalvfs',
'sriov_vfs_pci_address', 'sriov_vf_driver',
'sriov_vfs_pci_address', 'sriov_vf_driver', 'max_tx_rate',
'driver', 'dpdksupport', 'neighbours']
def __init__(self, apiresource):
@ -1961,7 +1961,7 @@ class Interface(base.APIResourceWrapper):
'aemode', 'txhashpolicy', 'primary_reselect', 'vlan_id',
'uses', 'used_by', 'ihost_uuid',
'ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool',
'sriov_numvfs', 'sriov_vf_driver']
'sriov_numvfs', 'sriov_vf_driver', 'max_tx_rate']
def __init__(self, apiresource):
super(Interface, self).__init__(apiresource)

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2013-2021 Wind River Systems, Inc.
# Copyright (c) 2013-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -379,6 +379,23 @@ class AddInterface(forms.SelfHandlingForm):
'data-switch-on': 'ipv6_mode',
'data-ipv6_mode-pool': 'IPv6 Address Pool'}))
max_tx_rate = forms.IntegerField(
label=_("Max Tx Rate"),
initial=0,
min_value=0,
required=False,
help_text=_('Allowed maximum transmit bandwidth, in Mbps, for the '
'specified VF. Setting this parameter to 0 disables '
'rate limiting.'),
error_messages={'invalid': _('Max Tx Rate must be '
'equal or greater than 0.')},
widget=forms.TextInput(
attrs={
'class': 'switched',
'data-switch-on': 'interface_type',
'data-slug': 'max_tx_rate',
'data-interface_type-vf': 'Max Tx Rate'}))
failure_url = 'horizon:admin:inventory:detail'
def __init__(self, *args, **kwargs):
@ -602,6 +619,13 @@ class AddInterface(forms.SelfHandlingForm):
del data['sriov_numvfs']
del data['sriov_vf_driver']
if data['iftype'] == 'vf':
if not data['max_tx_rate']:
data['max_tx_rate'] = 0
data['max_tx_rate'] = str(data['max_tx_rate'])
else:
del data['max_tx_rate']
del data['datanetworks']
del data['networks']
interface = sysinv.host_interface_create(request, **data)
@ -917,6 +941,13 @@ class UpdateInterface(AddInterface):
if 'sriov_vf_driver' in data:
data['sriov_vf_driver'] = str(data['sriov_vf_driver'])
if data['iftype'] == 'vf':
if not data['max_tx_rate']:
data['max_tx_rate'] = 0
data['max_tx_rate'] = str(data['max_tx_rate'])
else:
del data['max_tx_rate']
# Explicitly set iftype when user selects pci-pt or pci-sriov
ifclass = \
flatten(list(nt) for nt in self.fields['ifclass'].choices)

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2013-2021 Wind River Systems, Inc.
# Copyright (c) 2013-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -229,6 +229,7 @@ class UpdateView(forms.ModalFormView):
'sriov_numvfs': interface.sriov_numvfs,
'sriov_vf_driver': interface.sriov_vf_driver,
'imtu': interface.imtu,
'max_tx_rate': interface.max_tx_rate,
'ipv4_mode': getattr(interface, 'ipv4_mode', 'disabled'),
'ipv4_pool': getattr(interface, 'ipv4_pool', None),
'ipv6_mode': getattr(interface, 'ipv6_mode', 'disabled'),

View File

@ -36,5 +36,7 @@
<dd>{{ interface.sriov_numvfs|default:_("None") }}</dd>
<dt>{% trans "Virtual Function Driver" %}</dt>
<dd>{{ interface.sriov_vf_driver|default:_("None") }}</dd>
<dt>{% trans "Max Tx Rate" %}</dt>
<dd>{{ interface.max_tx_rate|default:_("None") }}</dd>
</dl>
</div>