VmContainer.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions" />
  7. </template>
  8. <script>
  9. import { sizestr } from '@/utils/utils'
  10. import {
  11. getProjectTableColumn,
  12. getRegionTableColumn,
  13. getStatusTableColumn,
  14. getBrandTableColumn,
  15. getCopyWithContentTableColumn,
  16. getIpsTableColumn,
  17. getTagTableColumn,
  18. getNameDescriptionTableColumn,
  19. } from '@/utils/common/tableColumn'
  20. import WindowsMixin from '@/mixins/windows'
  21. import ListMixin from '@/mixins/list'
  22. import expectStatus from '@/constants/expectStatus'
  23. import { cloudEnabled, cloudUnabledTip } from '@Compute/views/vminstance-container/utils'
  24. const commonUnabled = (value, statusArr = ['sched_fail', 'net_fail', 'disk_fail']) => {
  25. return statusArr.includes(value.status)
  26. }
  27. export default {
  28. name: 'VmContainerListForGpuSidePage',
  29. mixins: [WindowsMixin, ListMixin],
  30. props: {
  31. data: {
  32. type: Object,
  33. required: true,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. id: 'VmContainerListForGpuSidePage',
  40. resource: 'servers',
  41. getParams: this.getParam,
  42. filterOptions: {
  43. name: {
  44. label: this.$t('compute.text_228'),
  45. filter: true,
  46. formatter: val => {
  47. return `name.contains("${val}")`
  48. },
  49. },
  50. },
  51. steadyStatus: Object.values(expectStatus.container).flat(),
  52. }),
  53. columns: [
  54. getNameDescriptionTableColumn({
  55. vm: this,
  56. hideField: true,
  57. addLock: true,
  58. addBackup: true,
  59. slotCallback: row => {
  60. return (
  61. <side-page-trigger onTrigger={ () => this.sidePageTriggerHandle(row.id, 'VmContainerInstanceSidePage') }>{ row.name }</side-page-trigger>
  62. )
  63. },
  64. }),
  65. getTagTableColumn({ onManager: this.onManager, resource: 'server', columns: () => this.columns }),
  66. getIpsTableColumn({ field: 'ip', title: 'IP' }),
  67. {
  68. field: 'instance_type',
  69. title: this.$t('compute.text_295'),
  70. showOverflow: 'ellipsis',
  71. minWidth: 120,
  72. sortable: true,
  73. slots: {
  74. default: ({ row }) => {
  75. const ret = []
  76. if (row.instance_type) {
  77. ret.push(<div class='text-truncate' style={{ color: '#0A1F44' }}>{ row.instance_type }</div>)
  78. }
  79. const config = row.vcpu_count + 'C' + sizestr(row.vmem_size, 'M', 1024) + (row.disk ? sizestr(row.disk, 'M', 1024) : '')
  80. return ret.concat(<div class='text-truncate' style={{ color: '#53627C' }}>{ config }</div>)
  81. },
  82. },
  83. },
  84. {
  85. field: 'secgroups',
  86. title: this.$t('compute.text_105'),
  87. width: 80,
  88. showOverflow: 'ellipsis',
  89. formatter: ({ cellValue = [] }) => {
  90. return cellValue.map(item => item.name).join(',')
  91. },
  92. },
  93. {
  94. field: 'billing_type',
  95. title: this.$t('compute.text_498'),
  96. width: 100,
  97. showOverflow: 'ellipsis',
  98. slots: {
  99. default: ({ row }) => {
  100. const ret = []
  101. if (row.billing_type === 'postpaid') {
  102. ret.push(<div style={{ color: '#0A1F44' }}>{this.$t('billingType.postpaid')}</div>)
  103. } else if (row.billing_type === 'prepaid') {
  104. ret.push(<div style={{ color: '#0A1F44' }}>{this.$t('billingType.postpaid')}</div>)
  105. }
  106. if (row.expired_at) {
  107. const dateArr = this.$moment(row.expired_at).fromNow().split(' ')
  108. const date = dateArr.join(' ')
  109. const seconds = this.$moment(row.expired_at).diff(new Date()) / 1000
  110. const textColor = seconds / 24 / 60 / 60 < 7 ? '#DD2727' : '#53627C'
  111. const text = seconds < 0 ? this.$t('compute.text_499') : this.$t('compute.text_500', [date])
  112. ret.push(<div style={{ color: textColor }}>{ text }</div>)
  113. }
  114. return ret
  115. },
  116. },
  117. },
  118. getStatusTableColumn({ statusModule: 'container' }),
  119. getCopyWithContentTableColumn({ field: 'host', title: this.$t('compute.text_111'), sortable: true }),
  120. getProjectTableColumn(),
  121. getBrandTableColumn(),
  122. getRegionTableColumn(),
  123. ],
  124. groupActions: [
  125. {
  126. label: this.$t('compute.text_483', [this.$t('dictionary.server_container')]),
  127. permission: 'server_perform_attach_isolated_device',
  128. action: obj => {
  129. this.createDialog('GpuAttachServerDialog', {
  130. data: [this.data],
  131. title: this.$t('compute.text_483', [this.$t('dictionary.server_container')]),
  132. columns: this.columns,
  133. refresh: this.refresh,
  134. resourceType: 'server_container',
  135. })
  136. },
  137. meta: obj => {
  138. const ret = { validate: true }
  139. if (this.data.dev_type === 'NIC') {
  140. ret.validate = false
  141. ret.tooltip = this.$t('compute.sriov_device_nic_notsupport')
  142. return ret
  143. }
  144. if (this.data.guest_id) {
  145. ret.validate = false
  146. return ret
  147. }
  148. ret.validate = true
  149. return ret
  150. },
  151. },
  152. ],
  153. singleActions: [
  154. {
  155. label: this.$t('compute.text_272'),
  156. permission: 'server_perform_start',
  157. action: (obj) => {
  158. this.list.onManager('performAction', {
  159. steadyStatus: 'running',
  160. id: obj.id,
  161. managerArgs: {
  162. action: 'start',
  163. },
  164. })
  165. },
  166. meta: (obj) => {
  167. return {
  168. validate: obj.status === 'ready' && !commonUnabled(obj),
  169. }
  170. },
  171. },
  172. {
  173. label: this.$t('compute.text_273'),
  174. permission: 'server_perform_stop',
  175. action: (obj) => {
  176. this.createDialog('VmShutDownDialog', {
  177. data: [obj],
  178. columns: this.columns,
  179. list: this.list,
  180. name: this.$t('compute.vminstance-container'),
  181. onManager: this.onManager,
  182. })
  183. },
  184. meta: (obj) => {
  185. return {
  186. validate: obj.status === 'running' && !commonUnabled(obj),
  187. }
  188. },
  189. },
  190. {
  191. label: this.$t('compute.text_260', [this.$t('compute.text_113')]),
  192. permission: 'server_perform_detach_isolated_device',
  193. action: obj => {
  194. this.createDialog('DetachGpuDialog', {
  195. data: [obj],
  196. title: this.$t('compute.text_485', [this.$t('compute.text_113')]),
  197. columns: this.columns,
  198. refresh: this.refresh,
  199. name: this.$t('dictionary.server_container'),
  200. device: this.data,
  201. })
  202. },
  203. meta: obj => {
  204. const ret = { validate: true }
  205. if (this.data.dev_type === 'NIC') {
  206. ret.validate = false
  207. ret.tooltip = this.$t('compute.sriov_device_nic_notsupport')
  208. return ret
  209. }
  210. if (obj.status !== 'ready') {
  211. ret.validate = false
  212. ret.tooltip = this.$t('compute.text_489_1', [this.$t('compute.text_113')])
  213. return ret
  214. }
  215. ret.validate = cloudEnabled('acttachGpu', obj)
  216. ret.tooltip = cloudUnabledTip('acttachGpu', obj)
  217. return ret
  218. },
  219. },
  220. ],
  221. }
  222. },
  223. watch: {
  224. 'data.guest_id': {
  225. handler (val) {
  226. this.list.fetchData()
  227. },
  228. },
  229. },
  230. created () {
  231. this.initSidePageTab('detail')
  232. this.list.fetchData()
  233. },
  234. methods: {
  235. refresh () {
  236. this.$bus.$emit('gpu-sidepage-refresh')
  237. },
  238. getParam () {
  239. return {
  240. 'filter.0': `id.equals(${this.data.guest_id})`,
  241. 'filter.1': 'hypervisor.in(pod)',
  242. }
  243. },
  244. },
  245. }
  246. </script>