utils.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. import { typeClouds } from '@/utils/common/hypervisor'
  2. import i18n from '@/locales'
  3. const hypervisorMap = typeClouds.hypervisorMap
  4. const serverStatus = i18n.t('status.server')
  5. const _toArr = value => {
  6. if (!Array.isArray(value)) {
  7. value = [value]
  8. }
  9. return value
  10. }
  11. const _tran = enArr => {
  12. return enArr.map(v => serverStatus[v] || v).filter(v => v).join(',')
  13. }
  14. const actionEableMap = {
  15. start: {
  16. cn: i18n.t('compute.text_272'),
  17. brand: {
  18. azure: ['ready'],
  19. qcloud: ['ready'],
  20. aliyun: ['ready'],
  21. aws: ['ready'],
  22. onecloud: ['ready'],
  23. cloudpods: ['ready'],
  24. vmware: ['ready'],
  25. baremetal: ['ready'],
  26. huawei: ['ready'],
  27. hcso: ['ready'],
  28. hcs: ['ready'],
  29. openstack: ['ready'],
  30. zstack: ['ready'],
  31. dstack: ['ready'],
  32. ucloud: ['ready'],
  33. ctyun: ['ready'],
  34. google: ['ready'],
  35. apsara: ['ready'],
  36. jdcloud: ['ready'],
  37. ecloud: ['ready'],
  38. nutanix: ['ready'],
  39. proxmox: ['ready'],
  40. bingocloud: false,
  41. incloudsphere: ['ready'],
  42. volcengine: ['ready'],
  43. remotefile: false,
  44. },
  45. },
  46. stop: {
  47. cn: i18n.t('compute.text_273'),
  48. brand: {
  49. azure: ['running'],
  50. qcloud: ['running'],
  51. aliyun: ['running'],
  52. aws: ['running'],
  53. onecloud: ['running'],
  54. cloudpods: ['running'],
  55. vmware: ['running'],
  56. baremetal: ['running'],
  57. huawei: ['running'],
  58. hcso: ['running'],
  59. hcs: ['running'],
  60. openstack: ['running'],
  61. zstack: ['running'],
  62. dstack: ['running'],
  63. ucloud: ['running'],
  64. ctyun: ['running'],
  65. google: ['running'],
  66. apsara: ['running'],
  67. jdcloud: ['running'],
  68. ecloud: ['running'],
  69. nutanix: ['running'],
  70. proxmox: ['running'],
  71. bingocloud: false,
  72. incloudsphere: ['running'],
  73. remotefile: false,
  74. volcengine: ['running'],
  75. },
  76. },
  77. restart: {
  78. cn: i18n.t('compute.text_274'),
  79. brand: {
  80. azure: ['running', 'stop_fail'],
  81. qcloud: ['running', 'stop_fail'],
  82. aliyun: ['running', 'stop_fail'],
  83. aws: ['running', 'stop_fail'],
  84. onecloud: ['running', 'stop_fail'],
  85. cloudpods: ['running', 'stop_fail'],
  86. vmware: ['running', 'stop_fail'],
  87. baremetal: ['running', 'stop_fail'],
  88. huawei: ['running', 'stop_fail'],
  89. hcso: ['running', 'stop_fail'],
  90. hcs: ['running', 'stop_fail'],
  91. openstack: ['running', 'stop_fail'],
  92. zstack: ['running', 'stop_fail'],
  93. dstack: ['running', 'stop_fail'],
  94. ucloud: ['running', 'stop_fail'],
  95. ctyun: ['running', 'stop_fail'],
  96. google: ['running', 'stop_fail'],
  97. apsara: ['running', 'stop_fail'],
  98. jdcloud: ['running', 'stop_fail'],
  99. ecloud: ['running', 'stop_fail'],
  100. nutanix: ['running', 'stop_fail'],
  101. proxmox: ['running', 'stop_fail'],
  102. bingocloud: false,
  103. incloudsphere: ['running', 'stop_fail'],
  104. remotefile: false,
  105. volcengine: ['running', 'stop_fail'],
  106. },
  107. },
  108. rebuildRoot: {
  109. cn: i18n.t('compute.text_357'),
  110. brand: {
  111. azure: ['ready', 'running'],
  112. qcloud: ['ready', 'running'],
  113. aliyun: ['ready', 'running'],
  114. aws: ['ready', 'running'],
  115. onecloud: ['ready'],
  116. cloudpods: ['ready'],
  117. vmware: ['ready'],
  118. baremetal: ['ready', 'admin'],
  119. huawei: ['ready', 'rebuild_root_fail'],
  120. hcso: ['ready', 'rebuild_root_fail'],
  121. hcs: ['ready', 'rebuild_root_fail'],
  122. openstack: ['ready'],
  123. zstack: ['ready'],
  124. dstack: ['ready'],
  125. ucloud: ['ready'],
  126. ctyun: ['ready'],
  127. google: ['ready'],
  128. apsara: ['running', 'ready'],
  129. proxmox: false,
  130. nutanix: false,
  131. bingocloud: false,
  132. incloudsphere: false,
  133. remotefile: false,
  134. volcengine: false,
  135. },
  136. },
  137. resetPassword: {
  138. cn: i18n.t('compute.text_276'),
  139. brand: {
  140. azure: ['running'],
  141. qcloud: ['ready'],
  142. aliyun: ['ready'],
  143. aws: false,
  144. onecloud: ['running', 'ready'],
  145. cloudpods: ['ready'],
  146. vmware: ['ready'],
  147. baremetal: ['ready', 'admin'],
  148. huawei: ['ready'],
  149. hcso: ['ready'],
  150. hcs: ['ready'],
  151. openstack: ['running'],
  152. zstack: ['running'],
  153. dstack: ['running'],
  154. ucloud: ['ready'],
  155. ctyun: ['running'],
  156. google: ['ready'],
  157. apsara: ['running'],
  158. proxmox: false,
  159. nutanix: false,
  160. bingocloud: false,
  161. incloudsphere: ['running'],
  162. remotefile: false,
  163. volcengine: ['ready'],
  164. },
  165. },
  166. bindKeyPair: {
  167. cn: i18n.t('compute.text_361'),
  168. brand: {
  169. azure: ['running'],
  170. qcloud: ['ready'],
  171. aliyun: ['ready'],
  172. aws: false,
  173. onecloud: ['ready'],
  174. cloudpods: ['ready'],
  175. vmware: ['ready'],
  176. baremetal: ['ready', 'admin'],
  177. huawei: false,
  178. hcso: false,
  179. hcs: false,
  180. openstack: ['running'],
  181. zstack: ['running'],
  182. dstack: ['running'],
  183. ucloud: false,
  184. ctyun: ['ready', 'running'],
  185. google: ['ready'],
  186. apsara: ['running'],
  187. proxmox: false,
  188. nutanix: false,
  189. bingocloud: false,
  190. incloudsphere: ['running'],
  191. remotefile: false,
  192. volcengine: ['ready'],
  193. },
  194. },
  195. unBindKeyPair: {
  196. cn: i18n.t('compute.text_364'),
  197. brand: {
  198. azure: ['running'],
  199. qcloud: ['ready'],
  200. aliyun: ['ready'],
  201. aws: false,
  202. onecloud: ['ready'],
  203. cloudpods: ['ready'],
  204. vmware: ['ready'],
  205. baremetal: ['ready', 'admin'],
  206. huawei: false,
  207. hcso: false,
  208. hcs: false,
  209. openstack: ['running'],
  210. zstack: ['running'],
  211. dstack: ['running'],
  212. ucloud: false,
  213. ctyun: ['ready', 'running'],
  214. google: ['ready'],
  215. apsara: ['running'],
  216. proxmox: false,
  217. nutanix: false,
  218. bingocloud: false,
  219. incloudsphere: false,
  220. remotefile: false,
  221. volcengine: ['ready'],
  222. },
  223. },
  224. adjustConfig: {
  225. cn: i18n.t('compute.text_1100'),
  226. brand: {
  227. azure: ['ready', 'running'],
  228. qcloud: ['ready'],
  229. aliyun: ['ready'],
  230. aws: ['ready'],
  231. onecloud: ['ready', 'running'],
  232. cloudpods: ['ready', 'running'],
  233. vmware: ['ready', 'running'],
  234. baremetal: false,
  235. huawei: ['ready'],
  236. hcso: ['ready'],
  237. hcs: ['ready'],
  238. openstack: ['ready', 'running'],
  239. zstack: ['ready'],
  240. dstack: ['ready'],
  241. ucloud: ['ready'],
  242. ctyun: ['ready'],
  243. google: ['ready'],
  244. apsara: ['ready'],
  245. nutanix: ['ready'],
  246. proxmox: ['ready', 'running'],
  247. bingocloud: false,
  248. incloudsphere: ['ready', 'running'],
  249. remotefile: false,
  250. volcengine: ['ready'],
  251. },
  252. },
  253. vnc: {
  254. cn: 'vnc',
  255. brand: {
  256. azure: false,
  257. qcloud: ['running'],
  258. aliyun: ['running'],
  259. aws: false,
  260. onecloud: ['running', 'block_stream', 'live_migrating'],
  261. cloudpods: ['running'],
  262. vmware: ['running'],
  263. baremetal: false,
  264. huawei: ['running'],
  265. hcso: ['running'],
  266. hcs: ['running'],
  267. openstack: ['running'],
  268. zstack: ['running'],
  269. dstack: ['running'],
  270. ucloud: false,
  271. ctyun: ['running'],
  272. google: false,
  273. apsara: ['running'],
  274. jdcloud: ['running'],
  275. ecloud: ['running'],
  276. proxmox: ['running'],
  277. nutanix: false,
  278. bingocloud: false,
  279. incloudsphere: ['running'],
  280. remotefile: false,
  281. volcengine: ['running'],
  282. },
  283. },
  284. 'EIP SSH': {
  285. cn: 'EIP SSH',
  286. brand: {
  287. azure: ['running'],
  288. qcloud: ['running'],
  289. aliyun: ['running'],
  290. aws: ['running'],
  291. onecloud: ['running'],
  292. cloudpods: ['running'],
  293. vmware: ['running'],
  294. baremetal: ['running'],
  295. huawei: ['running'],
  296. hcso: ['running'],
  297. hcs: ['running'],
  298. openstack: ['running'],
  299. zstack: ['running'],
  300. dstack: ['running'],
  301. ucloud: ['running'],
  302. ctyun: ['running'],
  303. google: ['running'],
  304. apsara: ['running'],
  305. jdcloud: ['running'],
  306. ecloud: ['running'],
  307. nutanix: ['running'],
  308. proxmox: false,
  309. bingocloud: false,
  310. remotefile: false,
  311. volcengine: ['running'],
  312. },
  313. },
  314. 'IP SSH': {
  315. cn: 'IP SSH',
  316. brand: {
  317. azure: false, // 暂时网络未打通
  318. qcloud: false, // 暂时网络未打通
  319. aliyun: false, // 暂时网络未打通
  320. aws: false, // 暂时网络未打通
  321. onecloud: ['running'],
  322. cloudpods: ['running'],
  323. vmware: ['running'],
  324. baremetal: ['running'],
  325. huawei: false, // 暂时网络未打通
  326. hcso: false, // 暂时网络未打通
  327. hcs: false, // 暂时网络未打通
  328. openstack: ['running'],
  329. zstack: false,
  330. dstack: false,
  331. ucloud: false,
  332. ctyun: false,
  333. google: false,
  334. apsara: false,
  335. jdcloud: false,
  336. ecloud: false,
  337. nutanix: ['running'],
  338. bingocloud: false,
  339. incloudsphere: ['running'],
  340. proxmox: false,
  341. remotefile: false,
  342. volcengine: ['running'],
  343. },
  344. },
  345. createSnapshot: {
  346. cn: i18n.t('compute.text_1276'),
  347. brand: {
  348. azure: ['running', 'ready'],
  349. qcloud: ['running', 'ready'],
  350. aliyun: ['running', 'ready'],
  351. aws: ['running', 'ready'],
  352. onecloud: ['running', 'ready'],
  353. cloudpods: ['running', 'ready'],
  354. vmware: ['running', 'ready'],
  355. baremetal: ['running', 'ready'],
  356. huawei: ['running', 'ready'],
  357. hcso: ['running', 'ready'],
  358. hcs: ['running', 'ready'],
  359. openstack: ['running', 'ready'],
  360. zstack: ['running', 'ready'],
  361. dstack: ['running', 'ready'],
  362. ucloud: false,
  363. ctyun: false,
  364. google: ['running', 'ready'],
  365. apsara: false,
  366. proxmox: false,
  367. nutanix: false,
  368. bingocloud: false,
  369. incloudsphere: false,
  370. remotefile: false,
  371. volcengine: false,
  372. },
  373. },
  374. createBackup: {
  375. cn: i18n.t('compute.text_1276'),
  376. brand: {
  377. azure: false,
  378. qcloud: false,
  379. aliyun: false,
  380. aws: false,
  381. onecloud: ['running', 'ready'],
  382. cloudpods: false,
  383. vmware: false,
  384. baremetal: false,
  385. huawei: false,
  386. hcso: false,
  387. hcs: false,
  388. openstack: false,
  389. zstack: false,
  390. dstack: false,
  391. ucloud: false,
  392. ctyun: false,
  393. google: false,
  394. apsara: false,
  395. nutanix: false,
  396. bingocloud: false,
  397. proxmox: false,
  398. incloudsphere: false,
  399. remotefile: false,
  400. volcengine: false,
  401. },
  402. },
  403. transfer: {
  404. cn: i18n.t('compute.text_1127'),
  405. brand: {
  406. azure: false,
  407. qcloud: false,
  408. aliyun: false,
  409. aws: false,
  410. onecloud: ['running', 'ready'],
  411. cloudpods: ['running', 'ready'],
  412. vmware: ['running', 'ready'],
  413. baremetal: false,
  414. huawei: false,
  415. hcso: false,
  416. hcs: false,
  417. openstack: true,
  418. zstack: false,
  419. dstack: false,
  420. ucloud: false,
  421. ctyun: false,
  422. google: false,
  423. apsara: false,
  424. nutanix: false,
  425. proxmox: false,
  426. bingocloud: false,
  427. incloudsphere: false,
  428. remotefile: false,
  429. volcengine: false,
  430. },
  431. },
  432. v2vTransfer: {
  433. cn: i18n.t('compute.v2vtransfer.label'),
  434. brand: {
  435. azure: false,
  436. qcloud: false,
  437. aliyun: false,
  438. aws: false,
  439. onecloud: false,
  440. cloudpods: ['ready'],
  441. vmware: ['ready'],
  442. baremetal: false,
  443. huawei: false,
  444. hcso: false,
  445. hcs: false,
  446. openstack: false,
  447. zstack: false,
  448. dstack: false,
  449. ucloud: false,
  450. ctyun: false,
  451. google: false,
  452. apsara: false,
  453. proxmox: false,
  454. nutanix: false,
  455. bingocloud: false,
  456. incloudsphere: false,
  457. remotefile: false,
  458. volcengine: false,
  459. },
  460. },
  461. assignSecgroup: {
  462. cn: i18n.t('compute.text_1116'),
  463. brand: {
  464. azure: true,
  465. qcloud: true,
  466. aliyun: true,
  467. aws: true,
  468. onecloud: true,
  469. cloudpods: true,
  470. vmware: false,
  471. baremetal: true,
  472. huawei: true,
  473. hcso: true,
  474. hcs: true,
  475. openstack: true,
  476. zstack: true,
  477. dstack: true,
  478. ucloud: true,
  479. ctyun: true,
  480. google: true,
  481. apsara: false,
  482. proxmox: false,
  483. nutanix: false,
  484. bingocloud: false,
  485. incloudsphere: false,
  486. remotefile: false,
  487. volcengine: true,
  488. },
  489. },
  490. insertiso: {
  491. cn: i18n.t('compute.text_366'),
  492. brand: {
  493. azure: true,
  494. qcloud: true,
  495. aliyun: true,
  496. aws: true,
  497. onecloud: true,
  498. vmware: true,
  499. baremetal: true,
  500. huawei: true,
  501. hcso: true,
  502. hcs: true,
  503. openstack: false,
  504. zstack: false,
  505. dstack: false,
  506. ucloud: false,
  507. ctyun: false,
  508. google: false,
  509. apsara: false,
  510. proxmox: false,
  511. nutanix: false,
  512. bingocloud: false,
  513. incloudsphere: false,
  514. remotefile: false,
  515. volcengine: false,
  516. },
  517. },
  518. ejectiso: {
  519. cn: i18n.t('compute.text_367'),
  520. brand: {
  521. azure: true,
  522. qcloud: true,
  523. aliyun: true,
  524. aws: true,
  525. onecloud: true,
  526. vmware: true,
  527. baremetal: true,
  528. huawei: true,
  529. hcso: true,
  530. hcs: true,
  531. openstack: true,
  532. zstack: false,
  533. dstack: false,
  534. ucloud: false,
  535. ctyun: false,
  536. google: false,
  537. apsara: false,
  538. proxmox: false,
  539. nutanix: false,
  540. bingocloud: false,
  541. incloudsphere: false,
  542. remotefile: false,
  543. volcengine: false,
  544. },
  545. },
  546. bindEip: {
  547. cn: i18n.t('compute.text_1302'),
  548. brand: {
  549. azure: ['running', 'ready'],
  550. qcloud: ['running', 'ready'],
  551. aliyun: ['running', 'ready'],
  552. aws: ['running', 'ready'],
  553. onecloud: ['running', 'ready'],
  554. cloudpods: ['running', 'ready'],
  555. vmware: false,
  556. baremetal: false,
  557. huawei: ['running', 'ready'],
  558. hcso: ['running', 'ready'],
  559. hcs: ['running', 'ready'],
  560. openstack: ['running', 'ready'],
  561. zstack: ['running', 'ready'],
  562. dstack: ['running', 'ready'],
  563. ucloud: ['running', 'ready'],
  564. ctyun: ['running', 'ready'],
  565. google: ['running', 'ready'],
  566. apsara: false,
  567. proxmox: false,
  568. nutanix: false,
  569. bingocloud: false,
  570. incloudsphere: false,
  571. remotefile: false,
  572. volcengine: ['running', 'ready'],
  573. },
  574. },
  575. unbindEip: {
  576. cn: i18n.t('compute.text_1303'),
  577. brand: {
  578. azure: ['running', 'ready'],
  579. qcloud: ['running', 'ready'],
  580. aliyun: ['running', 'ready'],
  581. aws: ['running', 'ready'],
  582. onecloud: ['running', 'ready'],
  583. cloudpods: ['running', 'ready'],
  584. vmware: false,
  585. baremetal: false,
  586. huawei: ['running', 'ready'],
  587. hcso: ['running', 'ready'],
  588. hcs: ['running', 'ready'],
  589. openstack: ['running', 'ready'],
  590. zstack: ['running', 'ready'],
  591. dstack: ['running', 'ready'],
  592. ucloud: ['running', 'ready'],
  593. ctyun: ['running', 'ready'],
  594. google: ['running', 'ready'],
  595. apsara: false,
  596. nutanix: false,
  597. proxmox: false,
  598. bingocloud: false,
  599. incloudsphere: false,
  600. remotefile: false,
  601. volcengine: ['running', 'ready'],
  602. },
  603. },
  604. acttachGpu: {
  605. cn: i18n.t('compute.text_1304'),
  606. brand: {
  607. onecloud: ['ready'],
  608. vmware: false,
  609. bingocloud: false,
  610. incloudsphere: false,
  611. remotefile: false,
  612. volcengine: false,
  613. },
  614. },
  615. acttachUsb: {
  616. cn: i18n.t('compute.text_1399'),
  617. brand: {
  618. onecloud: ['ready', 'running'],
  619. vmware: false,
  620. bingocloud: false,
  621. incloudsphere: false,
  622. remotefile: false,
  623. volcengine: false,
  624. },
  625. },
  626. publicIpToEip: {
  627. cn: i18n.t('compute.text_1305'),
  628. brand: {
  629. qcloud: ['running', 'ready'],
  630. aliyun: ['running', 'ready'],
  631. google: false,
  632. aws: false,
  633. bingocloud: false,
  634. incloudsphere: false,
  635. remotefile: false,
  636. volcengine: false,
  637. },
  638. },
  639. changeBlockStorage: {
  640. cn: i18n.t('compute.vminstance.change_disk_storage'),
  641. brand: {
  642. onecloud: ['ready', 'running'],
  643. remotefile: false,
  644. volcengine: false,
  645. },
  646. },
  647. addBackup: {
  648. cn: i18n.t('compute.text_1162'),
  649. brand: {
  650. onecloud: ['ready'],
  651. volcengine: false,
  652. },
  653. },
  654. }
  655. export const commonEnabled = (value, statusArr = ['ready']) => {
  656. return statusArr.includes(value.status)
  657. }
  658. export const commonTip = (obj, statusArr = ['ready']) => {
  659. if (statusArr.includes(obj.status)) {
  660. return null
  661. } else {
  662. return i18n.t('compute.text_1306', [_tran(statusArr)])
  663. }
  664. }
  665. export const commonUnabled = (value, statusArr = ['sched_fail', 'net_fail', 'disk_fail']) => {
  666. return statusArr.includes(value.status)
  667. }
  668. export const cloudEnabled = (action, value, othersEabledStatus = ['ready']) => {
  669. value = _toArr(value)
  670. if (!value || !value.length) return false
  671. const actionItem = actionEableMap[action] && actionEableMap[action].brand
  672. return value.every(obj => {
  673. let H = obj.brand ? obj.brand.toLowerCase() : obj.hypervisor.toLowerCase() // 兼容没有brand的情况
  674. if (H === 'kvm') H = 'onecloud' // 兼容没有brand的情况
  675. if (H === 'esxi') H = 'vmware' // 兼容没有brand的情况
  676. if (actionItem === undefined) { // 不是 actionEnableMap 中的一种
  677. return commonEnabled(obj)
  678. } else if (Array.isArray(actionItem[H])) { // 是 actionEnableMap 中的一种,且状态是数组
  679. return actionItem[H].includes(obj.status)
  680. } else if (actionItem[H] === undefined) { // 新接入的平台
  681. return commonEnabled(obj)
  682. } else { // 是 actionEnableMap 中的一种,且状态是 boolean
  683. if (actionItem[H] === true) {
  684. return true
  685. } else if (actionItem[H] === undefined) { // 且不是 aliyun、azure、qcloud、aws 的一种
  686. return commonEnabled(obj, othersEabledStatus)
  687. } else {
  688. return false
  689. }
  690. }
  691. })
  692. }
  693. export const cloudUnabledTip = (action, value, othersEabledStatus = ['ready']) => {
  694. value = _toArr(value)
  695. if (!value || !value.length) return i18n.t('compute.text_1307')
  696. let errorMsg = null
  697. const actionItem = actionEableMap[action] && actionEableMap[action].brand
  698. const valid = value.every(obj => {
  699. let H = obj.brand ? obj.brand.toLowerCase() : obj.hypervisor.toLowerCase() // 兼容没有brand的情况
  700. if (H === 'kvm') H = 'onecloud' // 兼容没有brand的情况
  701. if (H === 'esxi') H = 'vmware' // 兼容没有brand的情况
  702. if (actionItem === undefined) { // 不是 actionEnableMap 中的一种
  703. if (commonEnabled(obj)) {
  704. return true
  705. } else {
  706. errorMsg = i18n.t('compute.text_1308')
  707. return false
  708. }
  709. } else if (Array.isArray(actionItem[H])) { // 是 actionEnableMap 中的一种,且状态是数组
  710. if (actionItem[H].includes(obj.status)) {
  711. return true
  712. } else {
  713. errorMsg = i18n.t('compute.text_1309', [_tran(actionItem[H])])
  714. return false
  715. }
  716. } else if (actionItem[H] === undefined) { // 新接入的平台
  717. if (commonEnabled(obj)) {
  718. return true
  719. } else {
  720. errorMsg = commonTip(obj, othersEabledStatus)
  721. return false
  722. }
  723. } else { // 是 actionEnableMap 中的一种,且状态是 boolean
  724. if (actionItem[H] === true) {
  725. return true
  726. } else if (actionItem[H] === undefined) { // 且不是 aliyun、azure、qcloud、aws 的一种
  727. errorMsg = commonTip(obj, othersEabledStatus)
  728. return false
  729. } else {
  730. if (H === 'onecloud') H = 'kvm'
  731. if (H === 'vmware') H = 'esxi'
  732. const tooltip = hypervisorMap[H].label
  733. errorMsg = i18n.t('compute.text_1287', [tooltip])
  734. return false
  735. }
  736. }
  737. })
  738. if (valid) {
  739. return null
  740. } else {
  741. return errorMsg
  742. }
  743. }
  744. export const isSameDate = (date1, date2) => {
  745. let isSame = true
  746. if (date1.getFullYear() !== date2.getFullYear()) {
  747. isSame = false
  748. }
  749. if (date1.getMonth() !== date2.getMonth()) {
  750. isSame = false
  751. }
  752. if (date1.getDate() !== date2.getDate()) {
  753. isSame = false
  754. }
  755. return isSame
  756. }
  757. export const validateRescueMode = (val) => {
  758. const ret = { validate: true }
  759. if (Array.isArray(val)) {
  760. const isSomeRescueMode = val.some(item => item.rescue_mode === true)
  761. if (isSomeRescueMode) {
  762. ret.validate = false
  763. ret.tooltip = i18n.t('compute.start_rescue.validate_tooltip')
  764. }
  765. } else {
  766. if (val?.rescue_mode === true) {
  767. ret.validate = false
  768. ret.tooltip = i18n.t('compute.start_rescue.validate_tooltip')
  769. }
  770. }
  771. return ret
  772. }