From 8241ff8be7906e88d0ffb7158b5c33e11782539e Mon Sep 17 00:00:00 2001 From: zhuyue Date: Mon, 29 Nov 2021 18:26:39 +0800 Subject: [PATCH] fix: Fix environment with no pfw fix environment with no pfw Change-Id: I5f836eb028e5d2a3376575fad7e02545c5b513f7 --- src/client/neutron/index.js | 4 ++++ .../containers/FloatingIp/actions/CreateDNAT.jsx | 5 ++++- .../network/containers/FloatingIp/index.jsx | 3 ++- src/resources/neutron.js | 16 ++++++++++++++++ src/stores/root.js | 14 ++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/client/neutron/index.js b/src/client/neutron/index.js index 1d7c085d..ae549295 100644 --- a/src/client/neutron/index.js +++ b/src/client/neutron/index.js @@ -80,6 +80,10 @@ class NeutronClient extends Base { }, ], }, + { + key: 'extensions', + responseKey: 'extensions', + }, { key: 'agents', responseKey: 'agent', diff --git a/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx b/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx index 4c8df61c..43c5b8b6 100644 --- a/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx +++ b/src/pages/network/containers/FloatingIp/actions/CreateDNAT.jsx @@ -22,6 +22,7 @@ import { PortStore } from 'stores/neutron/port'; import { getPortFormItem, getPortsAndReasons } from 'resources/port'; import { getInterfaceWithReason } from 'resources/floatingip'; import globalPortForwardingStore from 'stores/neutron/port-forwarding'; +import { enablePFW } from 'resources/neutron'; @inject('rootStore') @observer @@ -110,7 +111,9 @@ export default class CreateDNAT extends ModalAction { static policy = 'create_floatingip_port_forwarding'; - static allowed = (item) => Promise.resolve(isNull(item.fixed_ip_address)); + static allowed = (item) => { + return Promise.resolve(isNull(item.fixed_ip_address) && enablePFW()); + }; onSubmit = (values) => { const { diff --git a/src/pages/network/containers/FloatingIp/index.jsx b/src/pages/network/containers/FloatingIp/index.jsx index 61010862..fbcf904b 100644 --- a/src/pages/network/containers/FloatingIp/index.jsx +++ b/src/pages/network/containers/FloatingIp/index.jsx @@ -21,6 +21,7 @@ import { emptyActionConfig } from 'utils/constants'; import { Col, Popover, Row } from 'antd'; import { FileTextOutlined } from '@ant-design/icons'; import { qosEndpoint } from 'client/client/constants'; +import { enablePFW } from 'resources/neutron'; import styles from './styles.less'; import actionConfigs from './actions'; @@ -151,7 +152,7 @@ export class FloatingIps extends Base { render: (resource_name, record) => { if ( !resource_name && - record.port_forwardings && + enablePFW() && record.port_forwardings.length !== 0 ) { return ( diff --git a/src/resources/neutron.js b/src/resources/neutron.js index b80d8508..ec7065c6 100644 --- a/src/resources/neutron.js +++ b/src/resources/neutron.js @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +import globalRootStore from 'stores/root'; + export const availabilityZoneState = { available: t('Available'), unavailable: t('Unavailable'), @@ -21,3 +23,17 @@ export const availabilityZoneResource = { router: t('Router'), network: t('Network'), }; + +export function enablePFW() { + const { neutronExtensions: extensions } = globalRootStore; + let enabled = false; + let pfwInFip = false; + extensions.forEach((i) => { + if (i.alias === 'floating-ip-port-forwarding') { + enabled = true; + } else if (i.alias === 'expose-port-forwarding-in-fip') { + pfwInFip = true; + } + }); + return enabled && pfwInFip; +} diff --git a/src/stores/root.js b/src/stores/root.js index 0a94a055..da347d79 100644 --- a/src/stores/root.js +++ b/src/stores/root.js @@ -76,6 +76,9 @@ export class RootStore { @observable enableBilling = false; + @observable + neutronExtensions = []; + // @observable // menu = renderMenu(i18n.t); @@ -179,6 +182,17 @@ export class RootStore { this.client.policies.list(), ]); this.updateUser(profile, policies.policies || []); + this.getNeutronExtensions(); + } + + @action + async getNeutronExtensions() { + try { + const { extensions } = await client.neutron.extensions.list(); + this.neutronExtensions = extensions; + } catch (error) { + this.neutronExtensions = []; + } } @action