import Vue from 'vue' import { typeClouds } from '@/utils/common/hypervisor' import i18n from '@/locales' import { sizestr } from '@/utils/utils' const __cpuNumaPinHVm = new Vue() const _cpuNumaPinH = (...args) => __cpuNumaPinHVm.$createElement(...args) const hypervisorMap = typeClouds.hypervisorMap const serverStatus = i18n.t('status.server') const _toArr = value => { if (!Array.isArray(value)) { value = [value] } return value } const _tran = enArr => { return enArr.map(v => serverStatus[v] || v).filter(v => v).join(',') } const actionEableMap = { start: { cn: i18n.t('compute.text_272'), brand: { azure: ['ready'], qcloud: ['ready'], aliyun: ['ready'], aws: ['ready'], onecloud: ['ready'], cloudpods: ['ready'], vmware: ['ready'], baremetal: ['ready'], huawei: ['ready'], hcso: ['ready'], hcs: ['ready'], openstack: ['ready'], zstack: ['ready'], dstack: ['ready'], ucloud: ['ready'], ctyun: ['ready'], google: ['ready'], apsara: ['ready'], jdcloud: ['ready'], ecloud: ['ready'], nutanix: ['ready'], proxmox: ['ready'], bingocloud: false, incloudsphere: ['ready'], volcengine: ['ready'], remotefile: false, sangfor: ['ready'], zettakit: ['ready'], uis: ['ready'], ksyun: ['ready'], cnware: ['ready'], baidu: ['ready'], }, }, stop: { cn: i18n.t('compute.text_273'), brand: { azure: ['running', 'stop_fail'], qcloud: ['running', 'stop_fail'], aliyun: ['running', 'stop_fail'], aws: ['running', 'stop_fail'], onecloud: ['running', 'stop_fail'], cloudpods: ['running', 'stop_fail'], vmware: ['running', 'stop_fail'], baremetal: ['running', 'stop_fail'], huawei: ['running', 'stop_fail'], hcso: ['running', 'stop_fail'], hcs: ['running', 'stop_fail'], openstack: ['running', 'stop_fail'], zstack: ['running', 'stop_fail'], dstack: ['running', 'stop_fail'], ucloud: ['running', 'stop_fail'], ctyun: ['running', 'stop_fail'], google: ['running', 'stop_fail'], apsara: ['running', 'stop_fail'], jdcloud: ['running', 'stop_fail'], ecloud: ['running', 'stop_fail'], nutanix: ['running', 'stop_fail'], proxmox: ['running', 'stop_fail'], bingocloud: false, incloudsphere: ['running', 'stop_fail'], remotefile: false, volcengine: ['running', 'stop_fail'], sangfor: ['running', 'stop_fail'], zettakit: ['running', 'stop_fail'], uis: ['running', 'stop_fail'], ksyun: ['running', 'stop_fail'], cnware: ['running', 'stop_fail'], baidu: ['running', 'stop_fail'], }, }, restart: { cn: i18n.t('compute.text_274'), brand: { azure: ['running', 'stop_fail'], qcloud: ['running', 'stop_fail'], aliyun: ['running', 'stop_fail'], aws: ['running', 'stop_fail'], onecloud: ['running', 'stop_fail'], cloudpods: ['running', 'stop_fail'], vmware: ['running', 'stop_fail'], baremetal: ['running', 'stop_fail'], huawei: ['running', 'stop_fail'], hcso: ['running', 'stop_fail'], hcs: ['running', 'stop_fail'], openstack: ['running', 'stop_fail'], zstack: ['running', 'stop_fail'], dstack: ['running', 'stop_fail'], ucloud: ['running', 'stop_fail'], ctyun: ['running', 'stop_fail'], google: ['running', 'stop_fail'], apsara: ['running', 'stop_fail'], jdcloud: ['running', 'stop_fail'], ecloud: ['running', 'stop_fail'], nutanix: ['running', 'stop_fail'], proxmox: ['running', 'stop_fail'], bingocloud: false, incloudsphere: ['running', 'stop_fail'], remotefile: false, volcengine: ['running', 'stop_fail'], sangfor: ['running', 'stop_fail'], zettakit: ['running', 'stop_fail'], uis: ['running', 'stop_fail'], ksyun: ['running', 'stop_fail'], cnware: ['running', 'stop_fail'], baidu: ['running', 'stop_fail'], }, }, rebuildRoot: { cn: i18n.t('compute.text_357'), brand: { azure: ['ready', 'running'], qcloud: ['ready', 'running'], aliyun: ['ready', 'running'], aws: ['ready', 'running'], onecloud: ['ready'], cloudpods: ['ready'], vmware: ['ready'], baremetal: ['ready', 'admin'], huawei: ['ready', 'rebuild_root_fail'], hcso: ['ready', 'rebuild_root_fail'], hcs: ['ready', 'rebuild_root_fail'], openstack: ['ready'], zstack: ['ready'], dstack: ['ready'], ucloud: ['ready'], ctyun: ['ready'], google: ['ready'], apsara: ['running', 'ready'], proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: ['running'], uis: ['running'], ksyun: ['ready'], cnware: false, baidu: ['ready', 'running'], }, }, resetPassword: { cn: i18n.t('compute.text_276'), brand: { azure: ['running'], qcloud: ['ready'], aliyun: ['ready'], aws: false, onecloud: ['running', 'ready'], cloudpods: ['ready'], vmware: ['ready'], baremetal: ['ready', 'admin'], huawei: ['ready'], hcso: ['ready'], hcs: ['ready'], openstack: ['running'], zstack: ['running'], dstack: ['running'], ucloud: ['ready'], ctyun: ['running'], google: ['ready'], apsara: ['running'], proxmox: false, nutanix: false, bingocloud: false, incloudsphere: ['running'], remotefile: false, volcengine: ['ready'], sangfor: false, zettakit: false, uis: false, ksyun: ['ready', 'running'], cnware: false, baidu: ['ready', 'running'], }, }, bindKeyPair: { cn: i18n.t('compute.text_361'), brand: { azure: ['running'], qcloud: ['ready'], aliyun: ['ready'], aws: false, onecloud: ['ready'], cloudpods: ['ready'], vmware: ['ready'], baremetal: ['ready', 'admin'], huawei: false, hcso: false, hcs: false, openstack: ['running'], zstack: ['running'], dstack: ['running'], ucloud: false, ctyun: ['ready', 'running'], google: ['ready'], apsara: ['running'], proxmox: false, nutanix: false, bingocloud: false, incloudsphere: ['running'], remotefile: false, volcengine: ['ready'], sangfor: false, zettakit: false, uis: false, ksyun: ['ready'], cnware: false, baidu: false, }, }, unBindKeyPair: { cn: i18n.t('compute.text_364'), brand: { azure: ['running'], qcloud: ['ready'], aliyun: ['ready'], aws: false, onecloud: ['ready'], cloudpods: ['ready'], vmware: ['ready'], baremetal: ['ready', 'admin'], huawei: false, hcso: false, hcs: false, openstack: ['running'], zstack: ['running'], dstack: ['running'], ucloud: false, ctyun: ['ready', 'running'], google: ['ready'], apsara: ['running'], proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: ['ready'], sangfor: false, zettakit: false, uis: false, ksyun: ['ready', 'running'], cnware: false, baidu: false, }, }, adjustConfig: { cn: i18n.t('compute.text_1100'), brand: { azure: ['ready', 'running'], qcloud: ['ready'], aliyun: ['ready', 'running'], aws: ['ready', 'running'], onecloud: ['ready', 'running'], cloudpods: ['ready', 'running'], vmware: ['ready', 'running'], baremetal: false, huawei: ['ready', 'running'], hcso: ['ready'], hcs: ['ready'], openstack: ['ready', 'running'], zstack: ['ready'], dstack: ['ready'], ucloud: ['ready'], ctyun: ['ready', 'running'], google: ['ready', 'running'], apsara: ['ready'], nutanix: ['ready'], proxmox: ['ready', 'running'], bingocloud: false, incloudsphere: ['ready', 'running'], remotefile: false, volcengine: ['ready', 'running'], sangfor: ['ready'], zettakit: ['ready'], uis: ['ready'], ksyun: ['ready', 'running'], cnware: false, baidu: ['ready', 'running'], }, }, vnc: { cn: 'vnc', brand: { azure: false, qcloud: ['running'], aliyun: ['running'], aws: false, onecloud: ['running', 'block_stream', 'live_migrating'], cloudpods: ['running'], vmware: ['running'], baremetal: false, huawei: ['running'], hcso: ['running'], hcs: ['running'], openstack: ['running'], zstack: ['running'], dstack: ['running'], ucloud: false, ctyun: ['running'], google: false, apsara: ['running'], jdcloud: ['running'], ecloud: ['running'], proxmox: ['running'], nutanix: false, bingocloud: false, incloudsphere: ['running'], remotefile: false, volcengine: ['running'], sangfor: ['running'], zettakit: ['running'], uis: ['running'], ksyun: ['running'], cnware: ['running'], baidu: ['running'], }, }, 'EIP SSH': { cn: 'EIP SSH', brand: { azure: ['running'], qcloud: ['running'], aliyun: ['running'], aws: ['running'], onecloud: ['running'], cloudpods: ['running'], vmware: ['running'], baremetal: ['running'], huawei: ['running'], hcso: ['running'], hcs: ['running'], openstack: ['running'], zstack: ['running'], dstack: ['running'], ucloud: ['running'], ctyun: ['running'], google: ['running'], apsara: ['running'], jdcloud: ['running'], ecloud: ['running'], nutanix: ['running'], proxmox: false, bingocloud: false, remotefile: false, volcengine: ['running'], sangfor: ['running'], zettakit: ['running'], uis: ['running'], ksyun: ['running'], cnware: false, baidu: ['running'], }, }, 'IP SSH': { cn: 'IP SSH', brand: { azure: false, // 暂时网络未打通 qcloud: false, // 暂时网络未打通 aliyun: false, // 暂时网络未打通 aws: false, // 暂时网络未打通 onecloud: ['running'], cloudpods: ['running'], vmware: ['running'], baremetal: ['running'], huawei: false, // 暂时网络未打通 hcso: false, // 暂时网络未打通 hcs: false, // 暂时网络未打通 openstack: ['running'], zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, jdcloud: false, ecloud: false, nutanix: ['running'], bingocloud: false, incloudsphere: ['running'], proxmox: false, remotefile: false, volcengine: ['running'], sangfor: ['running'], zettakit: ['running'], uis: ['running'], ksyun: false, cnware: false, baidu: ['running'], }, }, createSnapshot: { cn: i18n.t('compute.text_1276'), brand: { azure: ['running', 'ready'], qcloud: ['running', 'ready'], aliyun: ['running', 'ready'], aws: ['running', 'ready'], onecloud: ['running', 'ready'], cloudpods: ['running', 'ready'], vmware: ['running', 'ready'], baremetal: ['running', 'ready'], huawei: ['running', 'ready'], hcso: ['running', 'ready'], hcs: ['running', 'ready'], openstack: ['running', 'ready'], zstack: ['running', 'ready'], dstack: ['running', 'ready'], ucloud: false, ctyun: false, google: ['running', 'ready'], apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: ['running', 'ready'], baidu: ['running', 'ready'], }, }, createBackup: { cn: i18n.t('compute.text_1276'), brand: { azure: false, qcloud: false, aliyun: false, aws: false, onecloud: ['running', 'ready'], cloudpods: false, vmware: false, baremetal: false, huawei: false, hcso: false, hcs: false, openstack: false, zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, nutanix: false, bingocloud: false, proxmox: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, transfer: { cn: i18n.t('compute.text_1127'), brand: { azure: false, qcloud: false, aliyun: false, aws: false, onecloud: ['running', 'ready'], cloudpods: ['running', 'ready'], vmware: ['running', 'ready'], baremetal: false, huawei: false, hcso: false, hcs: false, openstack: true, zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, nutanix: false, proxmox: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, v2vTransfer: { cn: i18n.t('compute.v2vtransfer.label'), brand: { azure: false, qcloud: false, aliyun: false, aws: false, onecloud: false, cloudpods: ['ready'], vmware: ['ready'], baremetal: false, huawei: false, hcso: false, hcs: false, openstack: false, zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, assignSecgroup: { cn: i18n.t('compute.text_1116'), brand: { azure: true, qcloud: true, aliyun: true, aws: true, onecloud: true, cloudpods: true, vmware: false, baremetal: true, huawei: true, hcso: true, hcs: true, openstack: true, zstack: true, dstack: true, ucloud: true, ctyun: true, google: true, apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: true, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, insertiso: { cn: i18n.t('compute.text_366'), brand: { azure: true, qcloud: true, aliyun: true, aws: true, onecloud: true, vmware: true, baremetal: true, huawei: true, hcso: true, hcs: true, openstack: false, zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, ejectiso: { cn: i18n.t('compute.text_367'), brand: { azure: true, qcloud: true, aliyun: true, aws: true, onecloud: true, vmware: true, baremetal: true, huawei: true, hcso: true, hcs: true, openstack: true, zstack: false, dstack: false, ucloud: false, ctyun: false, google: false, apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, ksyun: false, cnware: false, baidu: false, }, }, bindEip: { cn: i18n.t('compute.text_1302'), brand: { azure: ['running', 'ready'], qcloud: ['running', 'ready'], aliyun: ['running', 'ready'], aws: ['running', 'ready'], onecloud: ['running', 'ready'], cloudpods: ['running', 'ready'], vmware: false, baremetal: false, huawei: ['running', 'ready'], hcso: ['running', 'ready'], hcs: ['running', 'ready'], openstack: ['running', 'ready'], zstack: ['running', 'ready'], dstack: ['running', 'ready'], ucloud: ['running', 'ready'], ctyun: ['running', 'ready'], google: ['running', 'ready'], apsara: false, proxmox: false, nutanix: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: ['running', 'ready'], sangfor: false, zettakit: false, uis: false, ksyun: ['running', 'ready'], cnware: false, baidu: ['running', 'ready'], }, }, unbindEip: { cn: i18n.t('compute.text_1303'), brand: { azure: ['running', 'ready'], qcloud: ['running', 'ready'], aliyun: ['running', 'ready'], aws: ['running', 'ready'], onecloud: ['running', 'ready'], cloudpods: ['running', 'ready'], vmware: false, baremetal: false, huawei: ['running', 'ready'], hcso: ['running', 'ready'], hcs: ['running', 'ready'], openstack: ['running', 'ready'], zstack: ['running', 'ready'], dstack: ['running', 'ready'], ucloud: ['running', 'ready'], ctyun: ['running', 'ready'], google: ['running', 'ready'], apsara: false, nutanix: false, proxmox: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: ['running', 'ready'], sangfor: false, zettakit: false, uis: false, ksyun: ['running', 'ready'], cnware: false, baidu: ['running', 'ready'], }, }, acttachGpu: { cn: i18n.t('compute.text_1304'), brand: { onecloud: ['ready', 'running'], vmware: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, cloudpods: false, baidu: false, }, }, acttachUsb: { cn: i18n.t('compute.text_1399'), brand: { onecloud: ['ready', 'running'], vmware: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, cloudpods: false, baidu: false, }, }, publicIpToEip: { cn: i18n.t('compute.text_1305'), brand: { qcloud: ['running', 'ready'], aliyun: ['running', 'ready'], google: false, aws: false, bingocloud: false, incloudsphere: false, remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, baidu: false, }, }, changeBlockStorage: { cn: i18n.t('compute.vminstance.change_disk_storage'), brand: { onecloud: ['ready', 'running'], remotefile: false, volcengine: false, sangfor: false, zettakit: false, uis: false, baidu: false, }, }, addBackup: { cn: i18n.t('compute.text_1162'), brand: { onecloud: ['ready'], volcengine: false, sangfor: false, zettakit: false, uis: false, baidu: false, }, }, } export const commonEnabled = (value, statusArr = ['ready']) => { return statusArr.includes(value.status) } export const commonTip = (obj, statusArr = ['ready']) => { if (statusArr.includes(obj.status)) { return null } else { return i18n.t('compute.text_1306', [_tran(statusArr)]) } } export const commonUnabled = (value, statusArr = ['sched_fail', 'net_fail', 'disk_fail']) => { return statusArr.includes(value.status) } export const cloudEnabled = (action, value, othersEabledStatus = ['ready']) => { value = _toArr(value) if (!value || !value.length) return false const actionItem = actionEableMap[action] && actionEableMap[action].brand return value.every(obj => { let H = obj.brand ? obj.brand.toLowerCase() : obj.hypervisor.toLowerCase() // 兼容没有brand的情况 if (H === 'kvm') H = 'onecloud' // 兼容没有brand的情况 if (H === 'esxi') H = 'vmware' // 兼容没有brand的情况 if (actionItem === undefined) { // 不是 actionEnableMap 中的一种 return commonEnabled(obj) } else if (Array.isArray(actionItem[H])) { // 是 actionEnableMap 中的一种,且状态是数组 return actionItem[H].includes(obj.status) } else if (actionItem[H] === undefined) { // 新接入的平台 return commonEnabled(obj) } else { // 是 actionEnableMap 中的一种,且状态是 boolean if (actionItem[H] === true) { return true } else if (actionItem[H] === undefined) { // 且不是 aliyun、azure、qcloud、aws 的一种 return commonEnabled(obj, othersEabledStatus) } else { return false } } }) } export const cloudUnabledTip = (action, value, othersEabledStatus = ['ready']) => { value = _toArr(value) if (!value || !value.length) return i18n.t('compute.text_1307') let errorMsg = null const actionItem = actionEableMap[action] && actionEableMap[action].brand const valid = value.every(obj => { let H = obj.brand ? obj.brand.toLowerCase() : obj.hypervisor.toLowerCase() // 兼容没有brand的情况 if (H === 'kvm') H = 'onecloud' // 兼容没有brand的情况 if (H === 'esxi') H = 'vmware' // 兼容没有brand的情况 if (actionItem === undefined) { // 不是 actionEnableMap 中的一种 if (commonEnabled(obj)) { return true } else { errorMsg = i18n.t('compute.text_1308') return false } } else if (Array.isArray(actionItem[H])) { // 是 actionEnableMap 中的一种,且状态是数组 if (actionItem[H].includes(obj.status)) { return true } else { errorMsg = i18n.t('compute.text_1309', [_tran(actionItem[H])]) return false } } else if (actionItem[H] === undefined) { // 新接入的平台 if (commonEnabled(obj)) { return true } else { errorMsg = commonTip(obj, othersEabledStatus) return false } } else { // 是 actionEnableMap 中的一种,且状态是 boolean if (actionItem[H] === true) { return true } else if (actionItem[H] === undefined) { // 且不是 aliyun、azure、qcloud、aws 的一种 errorMsg = commonTip(obj, othersEabledStatus) return false } else { if (H === 'onecloud') H = 'kvm' if (H === 'vmware') H = 'esxi' const tooltip = hypervisorMap[H].label errorMsg = i18n.t('compute.text_1287', [tooltip]) return false } } }) if (valid) { return null } else { return errorMsg } } export const isSameDate = (date1, date2) => { let isSame = true if (date1.getFullYear() !== date2.getFullYear()) { isSame = false } if (date1.getMonth() !== date2.getMonth()) { isSame = false } if (date1.getDate() !== date2.getDate()) { isSame = false } return isSame } export const validateRescueMode = (val) => { const ret = { validate: true } if (Array.isArray(val)) { const isSomeRescueMode = val.some(item => item.rescue_mode === true) if (isSomeRescueMode) { ret.validate = false ret.tooltip = i18n.t('compute.start_rescue.validate_tooltip') } } else { if (val?.rescue_mode === true) { ret.validate = false ret.tooltip = i18n.t('compute.start_rescue.validate_tooltip') } } return ret } /** cpu_numa_pin:每项一行;内存 sizestr;绑定 CPU 取全部 pcpu 排序后合并连续区间 */ export const formatSortedPcpuRanges = (sortedPcpus) => { if (!sortedPcpus.length) return '-' const parts = [] let start = sortedPcpus[0] let end = sortedPcpus[0] for (let i = 1; i < sortedPcpus.length; i++) { const cur = sortedPcpus[i] if (cur === end + 1) { end = cur } else { parts.push(start === end ? String(start) : `${start}-${end}`) start = cur end = cur } } parts.push(start === end ? String(start) : `${start}-${end}`) return parts.join(',') } const getCpuNumaPinLineData = (item) => { const nodeId = item.node_id const sizeMb = item.size_mb const pin = item.vcpu_pin || [] const pcpus = [...new Set( pin .filter(p => p && typeof p.pcpu === 'number') .map(p => p.pcpu), )].sort((a, b) => a - b) const cpuStr = formatSortedPcpuRanges(pcpus) const memStr = sizestr(sizeMb, 'M', 1024) return { nodeId, memStr, cpuStr } } export const formatCpuNumaPinLine = (item) => { const { nodeId, memStr, cpuStr } = getCpuNumaPinLineData(item) return `node:${nodeId} mem: ${memStr} cpu: ${cpuStr}` } const CPU_NUMA_PIN_LINE_GAP = '12px' export const formatCpuNumaPin = (row) => { const raw = row.cpu_numa_pin if (raw === undefined || raw === null || raw === '') return '-' let arr = raw if (typeof raw === 'string') { try { arr = JSON.parse(raw) } catch (e) { return '-' } } if (!Array.isArray(arr) || arr.length === 0) return '-' return _cpuNumaPinH('div', arr.map((item, idx) => { const { nodeId, memStr, cpuStr } = getCpuNumaPinLineData(item) return _cpuNumaPinH('div', { key: idx, style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', columnGap: CPU_NUMA_PIN_LINE_GAP, rowGap: '4px', }, }, [ _cpuNumaPinH('span', `node: ${nodeId}`), _cpuNumaPinH('span', `mem: ${memStr}`), _cpuNumaPinH('span', `cpu: ${cpuStr}`), ]) })) }