List.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="templateListColumns || columns"
  5. :showSearchbox="showSearchbox"
  6. :showGroupActions="showGroupActions"
  7. :show-single-actions="!isTemplate"
  8. :show-page="!isTemplate"
  9. :group-actions="getFinalGroupActions(groupActions)"
  10. :single-actions="getFinalSingleActions(singleActions)"
  11. :export-data-options="exportDataOptions" />
  12. </template>
  13. <script>
  14. import * as R from 'ramda'
  15. import { GPU_DEV_TYPE_OPTION_MAP } from '@Compute/constants'
  16. import { getNameFilter, getRegionFilter, getDescriptionFilter } from '@/utils/common/tableFilter'
  17. import expectStatus from '@/constants/expectStatus'
  18. import WindowsMixin from '@/mixins/windows'
  19. import ListMixin from '@/mixins/list'
  20. import GlobalSearchMixin from '@/mixins/globalSearch'
  21. import ResTemplateListMixin from '@/mixins/resTemplateList'
  22. import SingleActionsMixin from '../mixins/singleActions'
  23. import ColumnsMixin from '../mixins/columns'
  24. export default {
  25. name: 'GpuList',
  26. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  27. props: {
  28. id: String,
  29. getParams: {
  30. type: [Function, Object],
  31. },
  32. resId: String,
  33. probeHostDevices: Boolean,
  34. hiddenActionKeys: Array,
  35. },
  36. data () {
  37. const filter = {}
  38. if (!this.inBaseSidePage) {
  39. if (this.$route.query.id) {
  40. filter.id = [this.$route.query.id]
  41. }
  42. if (this.$route.query.hasOwnProperty('is_associated')) {
  43. filter.is_associated = [this.$route.query.is_associated]
  44. }
  45. }
  46. return {
  47. list: this.$list.createList(this, {
  48. ctx: this,
  49. id: this.id,
  50. resource: 'isolated_devices',
  51. getParams: this.getParam,
  52. filter,
  53. isTemplate: this.isTemplate,
  54. templateLimit: this.templateLimit,
  55. filterOptions: {
  56. id: {
  57. label: this.$t('table.title.id'),
  58. },
  59. name: getNameFilter(),
  60. description: getDescriptionFilter(),
  61. dev_type: {
  62. label: this.$t('compute.text_481'),
  63. dropdown: true,
  64. multiple: true,
  65. distinctField: {
  66. type: 'field',
  67. key: 'dev_type',
  68. },
  69. },
  70. model: {
  71. label: this.$t('compute.text_482'),
  72. dropdown: true,
  73. multiple: true,
  74. distinctField: {
  75. type: 'field',
  76. key: 'model',
  77. },
  78. },
  79. vendor_device_id: {
  80. label: 'PCI ID',
  81. dropdown: true,
  82. multiple: true,
  83. distinctField: {
  84. type: 'field',
  85. key: 'vendor_device_id',
  86. },
  87. },
  88. addr: {
  89. label: 'PCI ADDR',
  90. dropdown: true,
  91. multiple: true,
  92. distinctField: {
  93. type: 'field',
  94. key: 'addr',
  95. },
  96. },
  97. device_path: {
  98. label: this.$t('compute.isolated_devices.device_path.title'),
  99. dropdown: true,
  100. multiple: true,
  101. distinctField: {
  102. type: 'field',
  103. key: 'device_path',
  104. },
  105. },
  106. numa_node: {
  107. label: 'NUMA',
  108. dropdown: true,
  109. multiple: true,
  110. distinctField: {
  111. type: 'field',
  112. key: 'numa_node',
  113. },
  114. },
  115. guest: {
  116. label: this.$t('compute.text_483', [this.$t('dictionary.server')]),
  117. filter: true,
  118. jointFilter: true,
  119. formatter: val => {
  120. return `servers.id(guest_id).name.contains("${val}")`
  121. },
  122. },
  123. is_associated: {
  124. label: this.$t('network.is_associated'),
  125. dropdown: true,
  126. items: [
  127. { label: this.$t('network.associated'), key: 'true' },
  128. { label: this.$t('network.un_associated'), key: 'false' },
  129. ],
  130. filter: true,
  131. formatter: (val) => {
  132. return val[0] === 'true' ? 'guest_id.isnotempty()' : 'guest_id.isnullorempty()'
  133. },
  134. },
  135. host: {
  136. label: this.$t('compute.text_484'),
  137. filter: true,
  138. jointFilter: true,
  139. formatter: val => {
  140. return `hosts.id(host_id).name.contains("${val}")`
  141. },
  142. },
  143. region: getRegionFilter(),
  144. zone: {
  145. label: this.$t('dictionary.zone'),
  146. },
  147. },
  148. steadyStatus: {
  149. guest_status: [...Object.values(expectStatus.server).flat(), '', undefined],
  150. },
  151. }),
  152. groupActions: [
  153. {
  154. label: this.$t('compute.text_485', [this.$t('dictionary.server')]),
  155. permission: 'server_perform_detach_isolated_device',
  156. action: () => {
  157. this.createDialog('DetachGpuDialog', {
  158. data: this.list.selectedItems,
  159. columns: this.columns,
  160. title: this.$t('compute.text_485', [this.$t('dictionary.server')]),
  161. name: this.$t('compute.text_113'),
  162. refresh: this.refresh,
  163. devices: this.list.selectedItems,
  164. })
  165. },
  166. meta: () => {
  167. const item = this.list.selectedItems
  168. if (item.length <= 0) {
  169. return {
  170. validate: false,
  171. tooltip: this.$t('compute.text_486'),
  172. }
  173. }
  174. const validateGuestStatus = item.every(item => item.guest_id && (item.guest_status === 'ready' || item.guest_status === 'running'))
  175. const validateGuestId = item.every(item => item.guest_id)
  176. const someNicDevice = item.some(v => v.dev_type === 'NIC')
  177. if (someNicDevice) {
  178. return {
  179. validate: !someNicDevice,
  180. tooltip: this.$t('compute.sriov_device_nic_notsupport'),
  181. }
  182. }
  183. if (!validateGuestId) {
  184. return {
  185. validate: false,
  186. tooltip: this.$t('compute.text_487', [this.$t('dictionary.server')]),
  187. }
  188. }
  189. if (!validateGuestStatus) {
  190. return {
  191. validate: false,
  192. tooltip: this.$t('compute.text_489', [this.$t('dictionary.server')]),
  193. }
  194. }
  195. return {
  196. validate: true,
  197. }
  198. },
  199. },
  200. {
  201. key: 'SetReserveResource',
  202. label: this.$t('compute.text_490'),
  203. permission: 'isolated_devices_update',
  204. action: () => {
  205. this.createDialog('SetReserveResourceDialog', {
  206. onManager: this.onManager,
  207. data: this.list.selectedItems,
  208. columns: this.columns,
  209. refresh: this.refresh,
  210. })
  211. },
  212. meta: () => {
  213. const item = this.list.selectedItems
  214. if (item.length <= 0) {
  215. return {
  216. validate: false,
  217. tooltip: this.$t('compute.text_491'),
  218. }
  219. }
  220. let otherType = ''
  221. item.map(obj => {
  222. if (obj.dev_type && obj.dev_type.indexOf('GPU') === -1) {
  223. otherType = obj.dev_type
  224. }
  225. })
  226. if (otherType) {
  227. return {
  228. validate: false,
  229. tooltip: this.$t('compute.text_1398', [otherType]),
  230. }
  231. }
  232. return {
  233. validate: true,
  234. }
  235. },
  236. },
  237. {
  238. label: this.$t('gpu.device_type.update'),
  239. action: obj => {
  240. this.createDialog('UpdateDeviceTypeDialog', {
  241. data: this.list.selectedItems,
  242. columns: this.columns,
  243. refresh: this.refresh,
  244. })
  245. },
  246. meta: obj => {
  247. const ret = { validate: true }
  248. const isSelected = this.list.selectedItems?.length > 0
  249. if (!isSelected) {
  250. ret.validate = false
  251. ret.tooltip = this.$t('gpu.device_type.update.tooltip')
  252. return ret
  253. }
  254. const isAllGPU = this.list.selectedItems.every(o => o.dev_type.indexOf('GPU') !== -1)
  255. if (!isAllGPU) {
  256. ret.validate = false
  257. ret.tooltip = this.$t('gpu.device_type.gpu.tooltip')
  258. return ret
  259. }
  260. const isGpuHpcOrVga = this.list.selectedItems.every(o => {
  261. return o.dev_type === GPU_DEV_TYPE_OPTION_MAP['GPU-HPC'].value || o.dev_type === GPU_DEV_TYPE_OPTION_MAP['GPU-VGA'].value
  262. })
  263. if (!isGpuHpcOrVga) {
  264. ret.validate = false
  265. ret.tooltip = this.$t('gpu.device_type.tooltip.check_hpc_vga_gpu')
  266. return ret
  267. }
  268. return ret
  269. },
  270. },
  271. {
  272. label: this.$t('compute.host_probe_isolated_devices'),
  273. permission: 'hosts_perform_probe_isolated_devices',
  274. action: () => {
  275. this.updateHostProbeIsolatedDevices()
  276. },
  277. hidden: () => !this.probeHostDevices,
  278. },
  279. ],
  280. }
  281. },
  282. computed: {
  283. exportDataOptions () {
  284. return {
  285. downloadType: 'local',
  286. items: this.columns,
  287. title: this.$t('compute.text_113'),
  288. }
  289. },
  290. },
  291. created () {
  292. this.$bus.$on('gpu-sidepage-refresh', () => {
  293. this.list.refresh()
  294. })
  295. this.init()
  296. this.list.fetchData().then(() => {
  297. this.$nextTick(() => {
  298. if (this.$route.query.id && this.list.data[this.$route.query.id]) {
  299. this.handleOpenSidepage(this.list.data[this.$route.query.id].data)
  300. }
  301. })
  302. })
  303. },
  304. methods: {
  305. getParam () {
  306. const ret = {
  307. show_baremetal_isolated_devices: false,
  308. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  309. with_meta: true,
  310. details: true,
  311. }
  312. return ret
  313. },
  314. handleOpenSidepage (row, tab) {
  315. this.initSidePageTab(tab)
  316. this.sidePageTriggerHandle(this, 'GpuSidePage', {
  317. id: row.id,
  318. resource: 'isolated_devices',
  319. getParams: this.getParam,
  320. currentTab: 'servers-list',
  321. }, {
  322. list: this.list,
  323. })
  324. },
  325. async init () {
  326. this.list.fetchData()
  327. },
  328. async updateHostProbeIsolatedDevices () {
  329. const loading = this.$message.loading(this.$t('compute.host_probe_isolated_devices'), 0)
  330. try {
  331. new this.$Manager('hosts', 'v1').performAction({
  332. id: this.resId,
  333. action: 'probe-isolated-devices',
  334. }).then(res => {
  335. this.list.refresh()
  336. loading()
  337. })
  338. } catch (err) {
  339. loading()
  340. throw err
  341. }
  342. },
  343. getFinalGroupActions () {
  344. if (this.hiddenActionKeys?.length > 0) {
  345. return this.groupActions.filter(o => !this.hiddenActionKeys.includes(o.key))
  346. }
  347. return this.groupActions
  348. },
  349. getFinalSingleActions () {
  350. if (this.hiddenActionKeys?.length > 0) {
  351. return this.singleActions.filter(o => !this.hiddenActionKeys.includes(o.key))
  352. }
  353. return this.singleActions
  354. },
  355. },
  356. }
  357. </script>