import _ from 'lodash' import PasswordFetcher from '@Compute/sections/PasswordFetcher' import { getRegionTableColumn, getStatusTableColumn, getBrandTableColumn, getEnabledTableColumn, getNameDescriptionTableColumn, getPublicScopeTableColumn, getProjectDomainTableColumn, getTagTableColumn, getAccountTableColumn, getOsArch, getTimeTableColumn, getCopyWithContentTableColumn, } from '@/utils/common/tableColumn' import { sizestr, bytesPerSecondStr } from '@/utils/utils' import i18n from '@/locales' import { getHostSpecInfo } from '../utils/index' export default { created () { const getStatusToolTip = (row) => { if (row.metadata) { const sysWarn = row.metadata.sys_warn const sysError = row.metadata.sys_error const titleCon = sysWarn || sysError if (titleCon) { // const aLink = 查看日志 const aIcon = return { aIcon } } } return null } this.columns = [ getNameDescriptionTableColumn({ onManager: this.onManager, hideField: true, addBackup: true, formRules: [ { required: true, message: i18n.t('compute.text_210') }, // { validator: this.$validate('serverCreateName') }, ], slotCallback: row => { return ( this.handleOpenSidepage(row) }>{ row.name } ) }, cellWrapSlots: row => { return { append: () => { var ret = [] if (row.is_baremetal) { ret.push() } if (row.isolated_device_count) { ret.push() } if (row.page_size_kb > 4) { ret.push() } return ret }, } }, }), getStatusTableColumn({ statusModule: 'host', minWidth: 100, vm: this, }), getEnabledTableColumn(), getStatusTableColumn({ field: 'host_status', title: i18n.t('compute.text_502'), statusModule: 'host_status', slotCallback: row => { return [
{ getStatusToolTip(row) }
, ] }, }), getTagTableColumn({ onManager: this.onManager, resource: 'hosts', columns: () => this.columns, editCheck: (row) => (row.provider || '').toLowerCase() !== 'bingocloud', }), { field: 'custom_ip', title: 'IP', width: 200, showOverflow: 'ellipsis', slots: { default: ({ row }) => { const cellWrap = [] if (row.access_ip) { cellWrap.push(
{this.$t('compute.text_1319')}
, ) } if (row.ipmi_ip) { cellWrap.push(
{this.$t('compute.text_1320')}
, ) } if (row.public_ip) { cellWrap.push(
(EIP)
, ) } return cellWrap }, }, formatter: ({ row }) => { const list = [] if (row.access_ip) { list.push(`${row.access_ip}${this.$t('compute.text_1319')}`) } if (row.ipmi_ip) { list.push(`${row.ipmi_ip}${this.$t('compute.text_1320')}`) } return list.length ? list.join(',') : '-' }, }, { field: 'id', title: 'IPMI', width: 60, slots: { default: ({ cellValue, row }) => { if (!row.is_baremetal) { return '-' } else { return [] } }, }, }, { field: 'server_id', title: i18n.t('compute.text_566'), width: 70, slots: { default: ({ cellValue, row }) => { if (!row.is_baremetal) { return '-' } else { return [] } }, }, }, { field: 'nonsystem_guests', sortBy: 'order_by_server_count', title: '#VM', width: 60, sortable: true, slots: { default: ({ row }, h) => { if (this.isPreLoad && row.nonsystem_guests === undefined) return [] return `${row.nonsystem_guests}` }, }, formatter: ({ row }) => { return row.nonsystem_guests || '-' }, }, getOsArch({ field: 'cpu_architecture' }), { field: 'cpu_usage', title: this.$t('compute.text_563'), minWidth: 100, sortable: true, // sortBy: 'order_by_cpu_commit', slots: { default: ({ row }) => { const { cpu_count = 0, cpu_used = 0 } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${Math.round(cpu_used)}\n${this.$t('common_234')}: ${Math.round(cpu_count)}` return [ val > 0 ? (Math.max(Math.round(val), 1)) : Math.round(val)} totalFormatter={(val) => val > 0 ? (Math.max(Math.round(val), 1)) : Math.round(val)} />] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { cpu_count = 0, cpu_used = 0 } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${Math.round(cpu_used)}, ${this.$t('common_234')}: ${Math.round(cpu_count)}` return title }, }, { field: 'virtual_cpu_usage', title: this.$t('compute.text_563_1'), minWidth: 100, sortable: true, // sortBy: 'order_by_cpu_commit', slots: { default: ({ row }) => { const { cpu_commit = 0, cpu_count = 0, cpu_count_virtual = 0, cpu_commit_bound } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${Math.round(cpu_commit)}\n` + `${this.$t('common_234')}: ${Math.round(cpu_count_virtual)}\n` + `${this.$t('compute.text_594')}: ${(cpu_commit / cpu_count).toFixed(2)}\n` + `${this.$t('compute.cpu_commit_bound')}: ${cpu_commit_bound}` return [] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { cpu_commit = 0, cpu_count_virtual = 0 } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${Math.round(cpu_commit)}, ${this.$t('common_234')}: ${Math.round(cpu_count_virtual)}` return title }, }, { field: 'mem_usage', title: this.$t('compute.text_564'), minWidth: 100, sortable: true, // sortBy: 'order_by_mem_commit', slots: { default: ({ row }) => { const { mem_size, mem_used } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${sizestr(mem_used, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(mem_size, 'M', 1024)}` return [ sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { mem_size, mem_used } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${sizestr(mem_used, 'M', 1024)}, ${this.$t('common_234')}: ${sizestr(mem_size, 'M', 1024)}` return title }, }, { field: 'virtual_mem_usage', title: this.$t('compute.text_564_1'), minWidth: 100, sortable: true, // sortBy: 'order_by_mem_commit', slots: { default: ({ row }) => { const { mem_size_virtual, mem_commit, mem_size, mem_commit_bound } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${sizestr(mem_commit, 'M', 1024)}\n` + `${this.$t('common_234')}: ${sizestr(mem_size_virtual, 'M', 1024)}\n` + `${this.$t('compute.text_594')}: ${(mem_commit / mem_size).toFixed(2)}\n` + `${this.$t('compute.memory_commit_bound')}: ${mem_commit_bound}` return [ sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { mem_size_virtual, mem_commit } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${sizestr(mem_commit, 'M', 1024)}, ${this.$t('common_234')}: ${sizestr(mem_size_virtual, 'M', 1024)}` return title }, }, { field: 'storage_usage', title: this.$t('compute.text_565'), minWidth: 100, sortable: true, // sortBy: 'order_by_mem_commit', slots: { default: ({ row }) => { const { storage_size, actual_storage_used } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${sizestr(actual_storage_used, 'M', 1024)}\n${this.$t('common_234')}: ${sizestr(storage_size, 'M', 1024)}` return [ sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { storage_size, actual_storage_used } = getHostSpecInfo(row) const title = `${this.$t('common_407')}: ${sizestr(actual_storage_used, 'M', 1024)}, ${this.$t('common_234')}: ${sizestr(storage_size, 'M', 1024)}` return title }, }, { field: 'virtual_storage_usage', title: this.$t('compute.text_565_1'), minWidth: 100, sortable: true, // sortBy: 'order_by_storage_virtual', slots: { default: ({ row }) => { const { storage_size_virtual, storage_commit, storage_size } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${sizestr(storage_commit, 'M', 1024)}\n` + `${this.$t('common_234')}: ${sizestr(storage_size_virtual, 'M', 1024)}\n` + `${this.$t('compute.text_594')}: ${(storage_commit / storage_size).toFixed(2)}\n` + `${this.$t('compute.storage_commit_bound')}: ${(storage_size_virtual / storage_size).toFixed(2)}` return [ sizestr(val, 'M', 1024)} totalFormatter={(val) => sizestr(val, 'M', 1024)} />] }, header: ({ column }) => { return [ {column.title} , ] }, }, formatter: ({ row }) => { const { storage_size_virtual, storage_commit } = getHostSpecInfo(row) const title = `${this.$t('common_233')}: ${sizestr(storage_commit, 'M', 1024)}, ${this.$t('common_234')}: ${sizestr(storage_size_virtual, 'M', 1024)}` return title }, }, { field: 'disk_rate', title: i18n.t('common.disk_rate'), minWidth: 100, slots: { default: ({ row }) => { if (row.alert_data && row.alert_data.hasOwnProperty('disk_read_rate') && row.alert_data.hasOwnProperty('disk_write_rate')) { return [
{i18n.t('common.disk_read_rate_value', [bytesPerSecondStr(row.alert_data.disk_read_rate)])}
,
{i18n.t('common.disk_write_rate_value', [bytesPerSecondStr(row.alert_data.disk_write_rate)])}
, ] } return '-' }, }, formatter: ({ row }) => { if (row.alert_data && row.alert_data.hasOwnProperty('disk_read_rate') && row.alert_data.hasOwnProperty('disk_write_rate')) { return `${i18n.t('common.disk_read_rate_value', [bytesPerSecondStr(row.alert_data.disk_read_rate)])} / ${i18n.t('common.disk_write_rate_value', [bytesPerSecondStr(row.alert_data.disk_write_rate)])}` } return '-' }, }, { field: 'net_iops', title: i18n.t('common.net_iops'), minWidth: 100, slots: { default: ({ row }) => { if (row.alert_data && row.alert_data.hasOwnProperty('net_in_rate') && row.alert_data.hasOwnProperty('net_out_rate')) { return [
{i18n.t('common.net_in_rate_value', [bytesPerSecondStr(row.alert_data.net_in_rate)])}
,
{i18n.t('common.net_out_rate_value', [bytesPerSecondStr(row.alert_data.net_out_rate)])}
, ] } return '-' }, }, formatter: ({ row }) => { if (row.alert_data && row.alert_data.hasOwnProperty('net_in_rate') && row.alert_data.hasOwnProperty('net_out_rate')) { return `${i18n.t('common.net_in_rate_value', [bytesPerSecondStr(row.alert_data.net_in_rate)])} / ${i18n.t('common.net_out_rate_value', [bytesPerSecondStr(row.alert_data.net_out_rate)])}` } return '-' }, }, { field: 'manufacture', title: i18n.t('compute.text_847'), width: 70, slots: { default: ({ row }) => { if (row.sys_info && row.sys_info.oem_name) { const oem_name = row.sys_info.oem_name.replaceAll(' ', '_') const icons = { dell: { height: '25px' }, hp: { height: '25px' }, hpe: { height: '30px' }, inspur: { height: '50px' }, lenovo: { height: '10px' }, supermicro: { height: '30px' }, huawei: { height: '30px' }, red_hat: { height: '30px' }, ieit_systems: { height: '30px' }, } const arr = Object.keys(icons) if (!arr.includes(oem_name)) { return row.sys_info.oem_name } const imgSrc = require(`../../physicalmachine/assets/${oem_name}.svg`) return [ , ] } }, }, formatter: ({ row }) => { if (row.sys_info && row.sys_info.oem_name) { return row.sys_info.oem_name } return '-' }, }, { field: 'model', title: this.$t('compute.text_580'), formatter: ({ cellValue, row }) => { return ((row.sys_info || {}).model) || '-' }, }, getCopyWithContentTableColumn({ field: 'sn', title: this.$t('compute.text_591'), }), { field: 'host_type', title: this.$t('compute.host.host_type.title'), width: 80, formatter: ({ cellValue, row }) => { let ret = '-' if (row.host_type === 'container') { ret = this.$t('compute.host.host_type.container.title') } else if (row.host_type === 'kvm' || row.host_type === 'hypervisor') { ret = this.$t('compute.host.host_type.kvm.title') } else if (row.host_type === 'baremetal') { ret = this.$t('compute.host.host_type.baremetal.title') } else if (row.host_type) { ret = row.host_type } return ret }, }, { field: 'schedtags', title: i18n.t('compute.text_541'), width: 120, // type: 'expand', slots: { default: ({ row }) => { const tags = _.sortBy(row.schedtags, ['default', 'name']) if (!tags.length) { return [
{this.$t('compute.text_1322')}
, ] } const list = tags.map(tag => {tag.name}) return [
{...list}
, ] }, }, formatter: ({ row }) => { const tags = _.sortBy(row.schedtags, ['default', 'name']) if (tags.length > 0) { return tags.map(tag => tag.name) } return this.$t('compute.text_1322') }, }, getBrandTableColumn(), getAccountTableColumn({ vm: this }), getPublicScopeTableColumn({ vm: this, resource: 'hosts' }), getProjectDomainTableColumn({ vm: this }), getRegionTableColumn({ vm: this }), { field: 'alert_data', title: this.$t('compute.alert_status'), hidden: () => { return this.$isScopedPolicyMenuHidden('host_hidden_columns.alert_data') }, slots: { header: () => { return [{this.$t('compute.alert_status')}, ] }, default: ({ row }) => { if (row.alert_data?.alert_state) { return [] } return '-' }, }, }, getTimeTableColumn(), ] }, }