Merge "fix: Fix environment with no pfw"

This commit is contained in:
Zuul 2021-11-30 13:54:32 +00:00 committed by Gerrit Code Review
commit 220f8d4723
5 changed files with 40 additions and 2 deletions

View File

@ -80,6 +80,10 @@ class NeutronClient extends Base {
},
],
},
{
key: 'extensions',
responseKey: 'extensions',
},
{
key: 'agents',
responseKey: 'agent',

View File

@ -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 {

View File

@ -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 (

View File

@ -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;
}

View File

@ -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