index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <base-side-page
  3. @cancel="cancelSidePage"
  4. :title="$t('compute.text_91')"
  5. icon="res-vminstance"
  6. :res-name="detailData.name"
  7. :current-tab="params.windowData.currentTab"
  8. :tabs="filterDetailTabs"
  9. :loaded="loaded"
  10. @tab-change="handleTabChange">
  11. <template v-slot:actions v-if="showActions">
  12. <actions
  13. :options="singleActions"
  14. :row="detailData"
  15. :before-show-menu="beforeShowMenu"
  16. button-type="link"
  17. button-size="small" />
  18. </template>
  19. <component
  20. v-bind="listActives"
  21. :is="params.windowData.currentTab"
  22. :data="componentData"
  23. :serverColumns="columns"
  24. :res-id="data.id"
  25. :id="listId"
  26. :getParams="componentParams"
  27. :on-manager="onManager"
  28. :show-create-action="false"
  29. :isPageDestroyed="isPageDestroyed"
  30. :hiddenColumns="hiddenColumns"
  31. :hiddenSingleActions="hiddenSingleActions"
  32. :hiddenActionKeys="['SetReserveResource']"
  33. taskResource="compute-tasks"
  34. @refresh="refresh"
  35. @single-refresh="singleRefresh"
  36. @tab-change="handleTabChange" />
  37. </base-side-page>
  38. </template>
  39. <script>
  40. // import HostList from '@Compute/views/host/components/List'
  41. import GpuList from '@Compute/views/gpu/components/List'
  42. import ScheduledtasksList from '@Cloudenv/views/scheduledtask/components/List'
  43. import SidePageMixin from '@/mixins/sidePage'
  44. import WindowsMixin from '@/mixins/windows'
  45. import Actions from '@/components/PageList/Actions'
  46. import { hasPermission } from '@/utils/auth'
  47. import { isScopedPolicyMenuHidden } from '@/utils/scopedPolicy'
  48. import NetworkListForVmInstanceSidepage from './Network'
  49. import SingleActionsMixin from '../mixins/singleActions'
  50. import ColumnsMixin from '../mixins/columns'
  51. // import { cloudEnabled, cloudUnabledTip } from '../utils'
  52. import VmInstanceDetail from './Detail'
  53. import VmInstanceMonitorSidepage from './Monitor'
  54. import VmInstanceAlertSidepage from './Alert'
  55. import VmSnapshotSidepage from './Snapshot'
  56. import SecgroupList from './Secgroup'
  57. import DiskListForVmInstanceSidepage from './DiskList'
  58. // import DiskSnapshotListForVmInstanceSidepage from '@Compute/views/snapshot/components/List'
  59. // import InstanceSnapshotListForVmInstanceSidepage from '@Compute/views/snapshot-instance/components/List'
  60. // import EipListForVmInstanceSidepage from './EipList'
  61. export default {
  62. name: 'VmInstanceSidePage',
  63. components: {
  64. Actions,
  65. VmInstanceDetail,
  66. NetworkListForVmInstanceSidepage,
  67. // DiskSnapshotListForVmInstanceSidepage,
  68. // InstanceSnapshotListForVmInstanceSidepage,
  69. DiskListForVmInstanceSidepage,
  70. SecgroupList,
  71. // HostList,
  72. VmInstanceMonitorSidepage,
  73. VmInstanceAlertSidepage,
  74. VmSnapshotSidepage,
  75. GpuList,
  76. ScheduledtasksList,
  77. // EipListForVmInstanceSidepage,
  78. },
  79. mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
  80. data () {
  81. let detailTabs = [
  82. { label: this.$t('compute.text_238'), key: 'vm-instance-detail' },
  83. { label: this.$t('compute.text_105'), key: 'secgroup-list' },
  84. // { label: '宿主机', key: 'host-list' },
  85. { label: this.$t('compute.text_104'), key: 'network-list-for-vm-instance-sidepage' },
  86. // { label: this.$t('compute.text_107'), key: 'eip-list-for-vm-instance-sidepage' },
  87. { label: this.$t('compute.text_376'), key: 'disk-list-for-vm-instance-sidepage' },
  88. { label: this.$t('compute.text_462'), key: 'vm-snapshot-sidepage' },
  89. // { label: this.$t('compute.text_101'), key: 'disk-snapshot-list-for-vm-instance-sidepage' },
  90. // { label: this.$t('compute.text_102'), key: 'instance-snapshot-list-for-vm-instance-sidepage' },
  91. { label: this.$t('compute.text_113'), key: 'gpu-list' },
  92. { label: this.$t('compute.text_608'), key: 'vm-instance-monitor-sidepage' },
  93. { label: this.$t('compute.text_1301'), key: 'vm-instance-alert-sidepage' },
  94. { label: this.$t('table.title.task'), key: 'task-drawer' },
  95. { label: this.$t('cloudenv.text_431'), key: 'scheduledtasks-list' },
  96. { label: this.$t('compute.text_240'), key: 'event-drawer' },
  97. ]
  98. if (!hasPermission({ key: 'guestsecgroups_list' }) || isScopedPolicyMenuHidden('server_hidden_columns.secgroups')) {
  99. detailTabs = detailTabs.filter(item => item.key !== 'secgroup-list')
  100. }
  101. if (!hasPermission({ key: 'guestnetworks_list' }) || isScopedPolicyMenuHidden('server_hidden_columns.ips')) {
  102. detailTabs = detailTabs.filter(item => item.key !== 'network-list-for-vm-instance-sidepage')
  103. }
  104. if (!hasPermission({ key: 'guestdisks_list' }) || isScopedPolicyMenuHidden('server_hidden_columns.disk')) {
  105. detailTabs = detailTabs.filter(item => item.key !== 'disk-list-for-vm-instance-sidepage')
  106. }
  107. if (!hasPermission({ key: 'eip_list' })) {
  108. detailTabs = detailTabs.filter(item => item.key !== 'eip-list-for-vm-instance-sidepage')
  109. }
  110. if (this.$store.getters.isProjectMode) {
  111. detailTabs = detailTabs.filter(item => item.key !== 'gpu-list')
  112. }
  113. if (isScopedPolicyMenuHidden('sub_hidden_menus.disk_snapshot') && isScopedPolicyMenuHidden('sub_hidden_menus.instance_snapshot')) {
  114. detailTabs = detailTabs.filter(item => item.key !== 'vm-snapshot-sidepage')
  115. }
  116. if (isScopedPolicyMenuHidden('sub_hidden_menus.scheduledtask')) {
  117. detailTabs = detailTabs.filter(item => item.key !== 'scheduledtasks-list')
  118. }
  119. return {
  120. detailTabs,
  121. agent_status: '',
  122. agent_fail_reason: '',
  123. agent_fail_code: '',
  124. isPageDestroyed: false,
  125. }
  126. },
  127. computed: {
  128. componentParams () {
  129. const tabs = ['secgroup-list', 'disk-list-for-vm-instance-sidepage']
  130. const snapshotsTabs = ['vm-snapshot-sidepage']
  131. if (tabs.includes(this.params.windowData.currentTab)) {
  132. return {
  133. detail: true,
  134. server: this.detailData.id,
  135. }
  136. }
  137. if (this.params.windowData.currentTab === 'host-list') {
  138. return {
  139. detail: true,
  140. id: this.detailData.host_id,
  141. }
  142. }
  143. if (this.params.windowData.currentTab === 'network-list-for-vm-instance-sidepage') {
  144. return {
  145. associate_id: this.detailData.id,
  146. detail: true,
  147. }
  148. }
  149. if (snapshotsTabs.includes(this.params.windowData.currentTab)) {
  150. return {
  151. server_id: this.detailData.id,
  152. }
  153. }
  154. if (this.params.windowData.currentTab === 'gpu-list') {
  155. return {
  156. guest_id: this.data.id,
  157. }
  158. }
  159. if (this.params.windowData.currentTab === 'scheduledtasks-list') {
  160. return {
  161. label: this.data.id,
  162. }
  163. }
  164. return null
  165. },
  166. secgroupListActives () {
  167. // const me = this
  168. const _ = {
  169. frontGroupActions: function () {
  170. return [
  171. // {
  172. // index: 1,
  173. // label: this.$t('compute.text_1116'),
  174. // permission: 'server_perform_add_secgroup',
  175. // action: () => {
  176. // this.createDialog('VmSetSecgroupDialog', {
  177. // vm: me,
  178. // data: [me.detailData],
  179. // columns: me.columns,
  180. // onManager: me.onManager,
  181. // refresh: () => {
  182. // this.refresh()
  183. // },
  184. // })
  185. // },
  186. // meta: () => {
  187. // const ret = {
  188. // validate: cloudEnabled('assignSecgroup', me.detailData),
  189. // tooltip: cloudUnabledTip('assignSecgroup', me.detailData),
  190. // }
  191. // return ret
  192. // },
  193. // hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_perform_add_secgroup'),
  194. // },
  195. ]
  196. },
  197. }
  198. return _
  199. },
  200. listActives () {
  201. const _ = {
  202. 'secgroup-list': this.secgroupListActives,
  203. }
  204. return _[this.params.windowData.currentTab] || {}
  205. },
  206. listId () {
  207. switch (this.params.windowData.currentTab) {
  208. case 'network-list-for-vm-instance-sidepage':
  209. return 'NetworkListForVminstanceSidepage'
  210. case 'disk-list-for-vm-instance-sidepage':
  211. return 'DiskLiskForVminstanceSidepage'
  212. case 'secgroup-list':
  213. return 'SecgroupLiskForVminstanceSidepage'
  214. case 'vm-instance-alert-sidepage':
  215. return 'AlertLiskForVminstanceSidepage'
  216. case 'event-drawer':
  217. return 'EventListForVminstanceSidepage'
  218. case 'gpu-list':
  219. return 'GpuListForVminstanceSidePage'
  220. case 'scheduledtasks-list':
  221. return 'ScheduledtasksListForVminstancesidePage'
  222. // case 'eip-list-for-vm-instance-sidepage':
  223. // return 'EipListForVmInstanceSidepage'
  224. default:
  225. return ''
  226. }
  227. },
  228. componentData () {
  229. return Object.assign({}, this.detailData, { agent_status: this.agent_status, agent_fail_reason: this.agent_fail_reason, agent_fail_code: this.agent_fail_code })
  230. },
  231. hiddenColumns () {
  232. if (this.params.windowData.currentTab === 'scheduledtasks-list') {
  233. return ['resource_type', 'labels']
  234. }
  235. return []
  236. },
  237. hiddenSingleActions () {
  238. return this.params.windowData.currentTab === 'scheduledtasks-list'
  239. },
  240. showActions () {
  241. return !this.$isScopedPolicyMenuHidden('server_hidden_columns.perform_action')
  242. },
  243. filterDetailTabs () {
  244. return this.detailTabs.map(item => {
  245. if (!this.detailData.id) {
  246. return {
  247. ...item,
  248. disabled: true,
  249. }
  250. }
  251. return item
  252. }).filter(item => {
  253. if (this.detailData?.hypervisor === 'sangfor' && item.key === 'secgroup-list') {
  254. return false
  255. }
  256. return true
  257. })
  258. },
  259. },
  260. created () {
  261. this.initHiddenTab()
  262. this.initChangeTab()
  263. this.$bus.$on('agentStatusQuery', (val) => {
  264. if (this.agent_status === 'failed') {
  265. this.agent_status = 'applying'
  266. }
  267. this.handleInstallTask({
  268. script_apply_id: val,
  269. })
  270. })
  271. },
  272. beforeDestroy () {
  273. this.isPageDestroyed = true
  274. },
  275. methods: {
  276. initHiddenTab () {
  277. if (this.listRowData.brand !== 'OneCloud') {
  278. this.detailTabs = this.detailTabs.filter(item => item.key !== 'gpu-list')
  279. }
  280. if (this.listRowData.brand === 'VolcEngine') {
  281. this.detailTabs = this.detailTabs.filter(item => item.key !== 'vm-snapshot-sidepage')
  282. }
  283. },
  284. initChangeTab () {
  285. if (this.params.tab) {
  286. this.handleTabChange(this.params.tab)
  287. }
  288. },
  289. async fetchDataCallback () {
  290. try {
  291. if (!this.data.data) return
  292. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params: { server_id: this.data.data.id, details: false, limit: 1 } })
  293. if (data[0]) {
  294. this.agent_status = data[0].status
  295. if (data[0].status === 'applying') {
  296. if (!this.componentData.id) return
  297. this.handleInstallTask({
  298. server_id: this.componentData.id,
  299. details: false,
  300. limit: 1,
  301. })
  302. } else if (data[0].status === 'failed') {
  303. this.agent_fail_reason = data[0].reason
  304. this.agent_fail_code = data[0].fail_code || ''
  305. }
  306. }
  307. } catch (e) {}
  308. },
  309. beforeShowMenu () {
  310. return this.$store.dispatch('scopedPolicy/get', {
  311. category: ['vminstance_hidden_menus', 'vminstance_configured_callback_address', 'disk_hidden_menus'],
  312. })
  313. },
  314. async handleInstallTask (params) {
  315. try {
  316. let maxTry = 60
  317. while (maxTry > 0) {
  318. if (this.isPageDestroyed) {
  319. break
  320. }
  321. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params: params })
  322. if (data[0]) {
  323. if (data[0].status === 'succeed' || data[0].status === 'failed') {
  324. this.agent_status = data[0].status
  325. this.agent_fail_reason = data[0].reason
  326. this.agent_fail_code = data[0].fail_code || ''
  327. break
  328. }
  329. }
  330. maxTry -= 1
  331. await new Promise(resolve => setTimeout(resolve, 6000))
  332. }
  333. } catch (e) {}
  334. },
  335. },
  336. }
  337. </script>