Gpu.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns" />
  5. </template>
  6. <script>
  7. import * as R from 'ramda'
  8. import WindowsMixin from '@/mixins/windows'
  9. import { sizestr } from '@/utils/utils'
  10. const DEVICE_MAP = {
  11. '10de': 'nvidia',
  12. 1002: 'amd',
  13. }
  14. export default {
  15. name: 'HostGpuList',
  16. mixins: [WindowsMixin],
  17. props: {
  18. resId: String,
  19. getParams: {
  20. type: [Function, Object],
  21. },
  22. source: {
  23. type: String,
  24. default: 'host',
  25. },
  26. },
  27. data () {
  28. return {
  29. list: this.$list.createList(this, {
  30. id: 'GpuListForHostSidePage',
  31. resource: 'isolated_devices',
  32. getParams: this.getParam,
  33. }),
  34. }
  35. },
  36. computed: {
  37. columns () {
  38. const ret = [
  39. {
  40. field: 'dev_type',
  41. title: this.$t('compute.text_481'),
  42. },
  43. {
  44. field: 'model',
  45. title: this.$t('compute.text_482'),
  46. slots: {
  47. default: ({ cellValue, row }, h) => {
  48. const device = row.vendor_device_id.split(':')[0]
  49. if (!device) {
  50. return cellValue
  51. }
  52. return [
  53. <span>{row.model}</span>,
  54. <icon type={ DEVICE_MAP[device] } />,
  55. ]
  56. },
  57. },
  58. },
  59. {
  60. field: 'guest_id',
  61. title: this.$t('compute.text_232'),
  62. formatter: ({ cellValue, row }) => {
  63. return row.guest || cellValue
  64. },
  65. },
  66. {
  67. field: '',
  68. title: this.$t('compute.text_501'),
  69. minWidth: 100,
  70. showOverflow: 'title',
  71. slots: {
  72. default: ({ row }, h) => {
  73. const ret = []
  74. const config = row.reserved_cpu + 'C' + sizestr(row.reserved_memory, 'M', 1024) + (row.reserved_storage ? sizestr(row.reserved_storage, 'M', 1024) : '')
  75. return ret.concat(<div class='text-truncate' style={{ color: '#53627C' }}>{ config }</div>)
  76. },
  77. },
  78. },
  79. ]
  80. if (this.source === 'physicalmachine') {
  81. const addObj = {
  82. field: 'host',
  83. title: this.$t('compute.text_1318'),
  84. }
  85. ret.splice(ret.length - 2, 2, addObj)
  86. }
  87. return ret
  88. },
  89. },
  90. created () {
  91. this.list.fetchData()
  92. },
  93. methods: {
  94. getParam () {
  95. const ret = {
  96. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  97. host_id: this.resId,
  98. }
  99. return ret
  100. },
  101. },
  102. }
  103. </script>