From 99c44ece478ba36f9cf08dad031012fd0e91938d Mon Sep 17 00:00:00 2001 From: xusongfu Date: Thu, 21 Jul 2022 11:11:07 +0800 Subject: [PATCH] fix: support the same port if different protocol support the same port if different protocol when create DNAT Change-Id: I8ab9c06116aceb18b5780d57c567fc3e595cc3d9 --- .../FloatingIp/actions/CreateDNAT.jsx | 17 +++++++++++++---- src/stores/neutron/port-forwarding.js | 6 +++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx b/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx index a390b746..a002175d 100644 --- a/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx +++ b/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx @@ -131,6 +131,10 @@ export class CreateDNAT extends ModalAction { }); }; + get nameForStateUpdate() { + return ['protocol']; + } + get formItems() { const { fixed_ip_address = { selectedRows: [] } } = this.state; const ret = [ @@ -169,8 +173,10 @@ export class CreateDNAT extends ModalAction { new Error(`${t('Please input')} ${t('External Port')}`) ); } - const { alreadyUsedPorts } = this.state; - const flag = alreadyUsedPorts.some((pf) => pf.external_port === val); + const { alreadyUsedPorts, protocol } = this.state; + const flag = alreadyUsedPorts.some( + (pf) => pf.external_port === val && pf.protocol === protocol + ); if (flag) { return Promise.reject( new Error( @@ -180,6 +186,7 @@ export class CreateDNAT extends ModalAction { } return Promise.resolve(true); }, + dependencies: ['protocol'], }, { name: 'internal_port', @@ -202,13 +209,14 @@ export class CreateDNAT extends ModalAction { const internal_ip_address = formData.fixed_ip_address.selectedRows[0].fixed_ip_address; const internal_port_id = formData.virtual_adapter.selectedRows[0].id; - const { alreadyUsedPorts } = this.state; + const { alreadyUsedPorts, protocol } = this.state; // determine whether the FIP has been bound to the port of the port const flag = alreadyUsedPorts.some( (pf) => pf.internal_port === val && pf.internal_port_id === internal_port_id && - pf.internal_ip_address === internal_ip_address + pf.internal_ip_address === internal_ip_address && + pf.protocol === protocol ); if (flag) { return Promise.reject( @@ -221,6 +229,7 @@ export class CreateDNAT extends ModalAction { } return Promise.resolve(true); }, + dependencies: ['protocol'], }, ]; const extraColumn = getPortFormItem.call(this, ['compute:nova', '']); diff --git a/src/stores/neutron/port-forwarding.js b/src/stores/neutron/port-forwarding.js index f29beb33..bf363d6c 100644 --- a/src/stores/neutron/port-forwarding.js +++ b/src/stores/neutron/port-forwarding.js @@ -15,6 +15,7 @@ import { action } from 'mobx'; import client from 'client'; import Base from 'stores/base'; +import { isEmpty } from 'lodash'; export class PortForwardingStore extends Base { get client() { @@ -38,7 +39,10 @@ export class PortForwardingStore extends Base { if (items.length === 0) { return items; } - const { fipInfo } = filters; + const { fipInfo = {} } = filters; + if (isEmpty(fipInfo)) { + return items; + } const { floating_ip_address } = fipInfo; items.forEach((item) => { item.fip = fipInfo;