singleActions.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { SERVER_TYPE } from '@Compute/constants'
  2. import { findPlatform } from '@/utils/common/hypervisor'
  3. import i18n from '@/locales'
  4. import { hasSetupKey } from '@/utils/auth'
  5. export default {
  6. created () {
  7. const type = findPlatform(this.data.hypervisor)
  8. const isPublic = type === SERVER_TYPE.private
  9. const isPrivate = type === SERVER_TYPE.public
  10. this.singleActions = [
  11. {
  12. label: i18n.t('compute.text_389'),
  13. permission: 'server_perform_change_bandwidth',
  14. action: (obj) => {
  15. this.$openNewWindowForMenuHook('vminstance_configured_callback_address.modify_bandwidth_callback_address', () => {
  16. this.createDialog('VmChangeBandwidthDialog', {
  17. data: [obj],
  18. columns: this.columns,
  19. refresh: this.refresh,
  20. resData: [this.data],
  21. })
  22. })
  23. },
  24. hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_edit_bandwidth'),
  25. },
  26. {
  27. label: i18n.t('compute.text_352'),
  28. actions: obj => {
  29. return [
  30. {
  31. label: i18n.t('compute.text_247'),
  32. action: (obj) => {
  33. this.createDialog('VmUpdateNetworkAttrDialog', {
  34. resId: this.resId,
  35. data: [obj],
  36. columns: this.columns,
  37. refresh: this.refresh,
  38. })
  39. },
  40. meta: (obj) => {
  41. const ret = { validate: true }
  42. const isOneCloud = this.data.brand === 'OneCloud'
  43. if (obj && obj.driver === 'vfio-pci') {
  44. ret.validate = false
  45. return ret
  46. }
  47. if (!isOneCloud) {
  48. ret.validate = false
  49. ret.tooltip = i18n.t('compute.text_391')
  50. return ret
  51. }
  52. return ret
  53. },
  54. hidden: () => !hasSetupKey(['onecloud']),
  55. },
  56. {
  57. label: i18n.t('compute.text_390'),
  58. permission: 'server_perform_change_ipaddr',
  59. action: (obj) => {
  60. this.createDialog('VmChangeIpDialog', {
  61. data: [obj],
  62. columns: this.columns,
  63. zone: this.data.zone_id,
  64. resId: this.resId,
  65. hypervisor: this.data.hypervisor,
  66. refresh: this.refresh,
  67. })
  68. },
  69. meta: (obj) => {
  70. const ret = {
  71. validate: false,
  72. tooltip: null,
  73. }
  74. if (isPrivate || isPublic) {
  75. ret.tooltip = i18n.t('compute.text_391')
  76. return ret
  77. }
  78. ret.validate = true
  79. return ret
  80. },
  81. hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_change_ip'),
  82. },
  83. {
  84. label: i18n.t('compute.change_sub_ip'),
  85. permission: 'server_perform_update_sub_ips',
  86. action: (obj) => {
  87. this.createDialog('VmNetworkChangeSubIpDialog', {
  88. data: [obj],
  89. columns: this.columns,
  90. refresh: this.refresh,
  91. server: this.data,
  92. })
  93. },
  94. hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_change_sub_ip') || (this.hiddenActions || []).includes('change_sub_ip'),
  95. },
  96. {
  97. label: i18n.t('compute.set_nic_num_queue'),
  98. action: (obj) => {
  99. this.createDialog('VmSetNicNumQueueDialog', {
  100. data: [obj],
  101. columns: this.columns,
  102. refresh: this.refresh,
  103. server: this.data,
  104. onManager: this.onManager,
  105. })
  106. },
  107. meta: (obj) => {
  108. const ret = {
  109. validate: true,
  110. tooltip: null,
  111. }
  112. const isOneCloud = this.data.brand === 'OneCloud'
  113. if (!isOneCloud) {
  114. ret.validate = false
  115. ret.tooltip = i18n.t('compute.text_391')
  116. return ret
  117. }
  118. if (this.data.status !== 'ready') {
  119. ret.validate = false
  120. ret.tooltip = i18n.t('compute.text_1357')
  121. return ret
  122. }
  123. return ret
  124. },
  125. hidden: () => !hasSetupKey(['onecloud']),
  126. },
  127. {
  128. label: i18n.t('compute.detach_network'),
  129. permission: 'server_perform_detachnetwork',
  130. action: (obj) => {
  131. this.createDialog('VmDetachNetworkDialog', {
  132. data: [obj],
  133. columns: this.columns,
  134. refresh: this.refresh,
  135. server: this.data,
  136. })
  137. },
  138. meta: (obj) => {
  139. const ret = {
  140. validate: false,
  141. tooltip: null,
  142. }
  143. if (isPrivate || isPublic || this.data.hypervisor === 'esxi') {
  144. ret.tooltip = i18n.t('compute.text_391')
  145. return ret
  146. }
  147. if (!obj.__last) {
  148. ret.tooltip = i18n.t('compute.server_detach_network.only_last_one')
  149. return ret
  150. }
  151. ret.validate = true
  152. return ret
  153. },
  154. hidden: this.$isScopedPolicyMenuHidden('vminstance_hidden_menus.server_detach_nic') || (this.hiddenActions || []).includes('detach_network'),
  155. },
  156. ]
  157. },
  158. },
  159. ]
  160. },
  161. }