// Copyright 2021 99cloud
//
// 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.
import React from 'react';
import { toJS } from 'mobx';
import { inject, observer } from 'mobx-react';
import { ServerStore } from 'stores/nova/instance';
import { InstanceVolumeStore } from 'stores/nova/instance-volume';
import { PortStore } from 'stores/neutron/port';
import { ServerGroupStore } from 'stores/nova/server-group';
import Base from 'containers/BaseDetail';
import ItemActionButtons from 'components/Tables/Base/ItemActionButtons';
import { Link } from 'react-router-dom';
// render topo content
import { Col, Row, Button } from 'antd';
import { SyncOutlined } from '@ant-design/icons';
import Status from 'components/Status';
import volumeIcon from 'asset/image/volume.svg';
import instanceIcon from 'asset/image/instance.svg';
import interfaceIcon from 'asset/image/interface.svg';
import classnames from 'classnames';
import ImageType from 'components/ImageType';
import { instanceStatus, isIronicInstance } from 'resources/instance';
import { generateId } from 'utils/index';
import { getSinceTime, getLocalTimeStr } from 'utils/time';
import AttachVolume from 'pages/compute/containers/Instance/actions/AttachVolume';
import globalRootStore from 'stores/root';
import styles from './index.less';
export class BaseDetail extends Base {
componentDidMount() {
this.fetchVolumes();
this.fetchInterfaces();
if (this.detailData.server_groups[0]) {
this.fetchSeverGroup();
}
}
init() {
this.store = new ServerStore();
this.interfaceStore = new PortStore();
this.volumeStore = new InstanceVolumeStore();
this.serverGroupStore = new ServerGroupStore();
}
get leftCards() {
const cards = [
this.networkCard,
this.flavorCard,
this.imageCard,
this.securityGroupCard,
];
if (!isIronicInstance(this.detailData)) {
cards.push(this.serverGroupCard);
}
return cards;
}
get rightCards() {
const ret = [this.topoCard];
const {
detail: { fault },
} = this.props;
if (fault && fault.message) {
ret.splice(0, 0, this.errorCard);
}
return ret;
}
get networkCard() {
const addresses = toJS(this.detailData.addresses) || [];
const networks = [];
Object.keys(addresses).forEach((netName) => {
const values = addresses[netName];
const fixedIps = values.filter((it) => it['OS-EXT-IPS:type'] === 'fixed');
const fips = values.filter((it) => it['OS-EXT-IPS:type'] === 'floating');
fixedIps.forEach((fixedIp) => {
const fip = fips.find(
(it) =>
it['OS-EXT-IPS-MAC:mac_addr'] === fixedIp['OS-EXT-IPS-MAC:mac_addr']
);
networks.push({
netName,
fixedIp,
fip,
});
});
});
const content = networks.map((item, index) => {
const { netName, fixedIp, fip } = item;
return (
);
}
get topoCard() {
const title = t('Instance Architecture');
const titleHelp = (
{t(
'The instance architecture diagram mainly shows the overall architecture composition of the instance. If you need to view the network topology of the instance, please go to: '
)}