NetSecgroup.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div>
  3. <a-alert type="warning" class="mb-2" :message="$t('compute.nic_secgroups_tips')" />
  4. <secgroup-list
  5. ref="netSecgroupList"
  6. :hiddenActions="['openSecgroupSidepageTab']"
  7. :hiddenColumns="['guest_cnt', 'status']"
  8. :extraColumns="extraColumns"
  9. :hiddenSidepageTabs="['associated-instances']"
  10. :id="id"
  11. :getParams="getParams"
  12. :show-create-action="false"
  13. :customSingleActions="customSingleActions"
  14. frontGroupMethods="coverage"
  15. :frontGroupActions="frontGroupActions"
  16. secgroupType="network" />
  17. </div>
  18. </template>
  19. <script>
  20. import SecgroupList from '@Compute/views/secgroup/components/List'
  21. import WindowsMixin from '@/mixins/windows'
  22. import { SECGROUP_LIST_FOR_VMINSTANCE_SIDEPAGE_REFRESH } from '@/constants/event-bus'
  23. import { getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  24. export default {
  25. name: 'NetworkSecgroupListForVminstanceSidepage',
  26. components: {
  27. SecgroupList,
  28. },
  29. mixins: [WindowsMixin],
  30. props: {
  31. id: String,
  32. data: Object,
  33. getParams: [Function, Object],
  34. serverColumns: {
  35. type: Array,
  36. default () {
  37. return []
  38. },
  39. },
  40. },
  41. data () {
  42. const that = this
  43. return {
  44. frontGroupActions: function () {
  45. return [
  46. {
  47. label: this.$t('common.remove'),
  48. action: () => {
  49. const nics = that.data.nics || []
  50. const mac = nics.length > 0 ? nics[0].mac : null
  51. if (!mac) {
  52. this.$message.warning(this.$t('compute.text_193'))
  53. return
  54. }
  55. this.createDialog('VmSidepageRevokeNetworkSecgroupDialog', {
  56. detailData: that.data,
  57. data: this.list.selectedItems,
  58. mac: mac,
  59. secgroupType: 'network',
  60. refresh: () => {
  61. this.$bus.$emit(SECGROUP_LIST_FOR_VMINSTANCE_SIDEPAGE_REFRESH)
  62. },
  63. })
  64. },
  65. meta: () => {
  66. const ret = { validate: true }
  67. if (!this.list.selectedItems?.length) {
  68. ret.validate = false
  69. return ret
  70. }
  71. if (this.list.selectedItems.some(item => item.network_index !== this.list.selectedItems[0].network_index)) {
  72. ret.validate = false
  73. ret.tooltip = this.$t('compute.secgroup.remove_secgroup.group_actions.same_network_index_tooltip')
  74. return ret
  75. }
  76. return ret
  77. },
  78. },
  79. ]
  80. },
  81. customSingleActions: [
  82. {
  83. label: this.$t('common.remove'),
  84. action: (obj) => {
  85. const nics = this.data.nics || []
  86. const mac = nics.length > 0 ? nics[0].mac : null
  87. if (!mac) {
  88. this.$message.warning(this.$t('compute.text_193'))
  89. return
  90. }
  91. this.createDialog('VmSidepageRevokeNetworkSecgroupDialog', {
  92. detailData: this.data,
  93. data: [obj],
  94. mac: mac,
  95. secgroupType: 'network',
  96. refresh: () => {
  97. this.$bus.$emit(SECGROUP_LIST_FOR_VMINSTANCE_SIDEPAGE_REFRESH)
  98. },
  99. })
  100. },
  101. },
  102. ],
  103. extraColumns: [
  104. {
  105. field: 'network_index',
  106. title: this.$t('compute.network_index'),
  107. width: 80,
  108. },
  109. getCopyWithContentTableColumn({ field: 'ifname', title: this.$t('compute.text_384'), sortable: true }),
  110. getCopyWithContentTableColumn({ field: 'mac_addr', title: this.$t('compute.text_385'), sortable: true }),
  111. {
  112. field: 'ip_addr',
  113. title: this.$t('compute.text_386'),
  114. sortable: true,
  115. showOverflow: 'ellipsis',
  116. minWidth: 100,
  117. slots: {
  118. default: ({ row }, h) => {
  119. if (row.ip_addr) {
  120. const addrs = [
  121. <div>{this.$t('compute.text_386')}: {row.ip_addr}/{row.guest_ip_mask}</div>,
  122. <div>{this.$t('network.ipv4.gateway')}: {row.guest_gateway}</div>,
  123. ]
  124. if (row.mapped_ip_addr) {
  125. addrs.push(<div>{this.$t('compute.vpc.mapped_addr')}: {row.mapped_ip_addr}</div>)
  126. }
  127. const ret = [
  128. <a-popover>
  129. <template slot="content">
  130. {addrs}
  131. </template>
  132. <list-body-cell-wrap copy row={row} field="ip_addr" hideField={true}>
  133. {row.ip_addr}/{row.guest_ip_mask}
  134. </list-body-cell-wrap>
  135. </a-popover>,
  136. ]
  137. return ret
  138. }
  139. return '-'
  140. },
  141. },
  142. },
  143. {
  144. field: 'ip6_addr',
  145. title: this.$t('compute.ipv6.address'),
  146. sortable: true,
  147. showOverflow: 'ellipsis',
  148. minWidth: 200,
  149. slots: {
  150. default: ({ row }, h) => {
  151. if (row.ip6_addr) {
  152. const addrs = [
  153. <div>{this.$t('compute.ipv6.address')}: {row.ip6_addr}/{row.guest_ip6_mask}</div>,
  154. <div>{this.$t('network.ipv6.gateway')}: {row.guest_gateway6}</div>,
  155. ]
  156. if (row.mapped_ip6_addr) {
  157. addrs.push(<div>{this.$t('compute.vpc.mapped_addr')}: {row.mapped_ip6_addr}</div>)
  158. }
  159. const ret = [
  160. <a-popover>
  161. <template slot="content">
  162. {addrs}
  163. </template>
  164. <list-body-cell-wrap copy row={row} field="ip6_addr" hideField={true}>
  165. {row.ip6_addr}/{row.guest_ip6_mask}
  166. </list-body-cell-wrap>
  167. </a-popover>,
  168. ]
  169. return ret
  170. }
  171. return '-'
  172. },
  173. },
  174. },
  175. {
  176. field: 'network_id',
  177. title: this.$t('compute.text_106'),
  178. slots: {
  179. default: ({ row }) => {
  180. return [<side-page-trigger permission='networks_get' name='NetworkSidePage' id={row.network_id} vm={this}>{row.network_name}</side-page-trigger>]
  181. },
  182. },
  183. },
  184. ],
  185. }
  186. },
  187. created () {
  188. this.$bus.$on(SECGROUP_LIST_FOR_VMINSTANCE_SIDEPAGE_REFRESH, () => {
  189. const secgroupListVm = this.$refs.netSecgroupList
  190. secgroupListVm && secgroupListVm.refresh()
  191. })
  192. },
  193. }
  194. </script>