Network.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div>
  3. <h5>{{ $t('compute.text_600') }}</h5>
  4. <vxe-grid resizable class="mb-2" :data="nicInfo" :columns="columns" />
  5. <h5>BMC{{ this.$t('compute.text_600') }}</h5>
  6. <vxe-grid resizable class="mb-2" :data="ipmiList" :columns="columns" />
  7. </div>
  8. </template>
  9. <script>
  10. import _ from 'lodash'
  11. import { getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  12. import WindowsMixin from '@/mixins/windows'
  13. export default {
  14. name: 'NetworkList',
  15. mixins: [WindowsMixin],
  16. props: {
  17. resId: String,
  18. hostInfo: {
  19. type: Object,
  20. required: true,
  21. },
  22. },
  23. data () {
  24. const cols = [
  25. /*
  26. {
  27. field: 'index',
  28. title: this.$t('compute.text_375'),
  29. formatter: ({ row }) => {
  30. return row.index
  31. },
  32. },
  33. */
  34. getCopyWithContentTableColumn({ field: 'mac', width: 200, title: this.$t('compute.text_385') }),
  35. {
  36. field: 'nic_type',
  37. title: this.$t('compute.text_860'),
  38. width: 100,
  39. formatter: ({ row }) => {
  40. if (row.nic_type === 'admin') {
  41. return this.$t('compute.text_861')
  42. } else if (row.nic_type === 'ipmi') {
  43. return this.$t('compute.text_862')
  44. } else {
  45. return '-'
  46. }
  47. },
  48. },
  49. {
  50. field: 'ip_addr',
  51. title: this.$t('compute.text_386'),
  52. width: 160,
  53. slots: {
  54. default: ({ row }, h) => {
  55. const ret = []
  56. if (row.ip_addr) {
  57. ret.push(
  58. <list-body-cell-wrap copy hideField={true} field='ip_addr' row={row} message={row.ip_addr}>
  59. {row.ip_addr}/{row.masklen}
  60. </list-body-cell-wrap>,
  61. )
  62. }
  63. if (row.ip6_addr) {
  64. ret.push(
  65. <list-body-cell-wrap copy hideField={true} field='ip6_addr' row={row} message={row.ip6_addr}>
  66. {row.ip6_addr}/{row.masklen6}
  67. </list-body-cell-wrap>,
  68. )
  69. }
  70. return ret
  71. },
  72. },
  73. },
  74. getCopyWithContentTableColumn({
  75. field: 'net',
  76. title: this.$t('compute.text_106'),
  77. hideField: true,
  78. slotCallback: row => {
  79. if (!row.net) return '-'
  80. return [
  81. <side-page-trigger permission='networks_get' name='NetworkSidePage' id={row.net_id} vm={this}>{ row.net }</side-page-trigger>,
  82. ]
  83. },
  84. }),
  85. getCopyWithContentTableColumn({
  86. field: 'wire',
  87. title: this.$t('compute.text_844'),
  88. hideField: true,
  89. slotCallback: row => {
  90. if (!row.wire) return '-'
  91. return [
  92. <side-page-trigger permission='wires_get' name='WireSidePage' id={row.wire_id} vm={this}>{ row.wire }</side-page-trigger>,
  93. ]
  94. },
  95. }),
  96. getCopyWithContentTableColumn({ field: 'link_up', title: this.$t('compute.netif_linkup_status') }),
  97. ]
  98. if (this.hostInfo.host_type === 'baremetal') {
  99. cols.push({
  100. field: 'action',
  101. title: this.$t('compute.text_863'),
  102. slots: {
  103. default: ({ row }, h) => {
  104. const ret = []
  105. ret.push(
  106. <a-button type="link" onClick = {() => this.setWire(row)} disabled={ !!row.ip_addr || !!row.ip6_addr }>{ this.$t('compute.text_843') }</a-button>,
  107. )
  108. return ret
  109. },
  110. },
  111. })
  112. }
  113. return {
  114. list: this.$list.createList(this, {
  115. id: 'NetworkListForPhysicalmachineSidePage',
  116. resource: 'networks',
  117. ctx: [['hosts', this.resId]],
  118. getParams: this.getParams,
  119. }),
  120. columns: cols,
  121. }
  122. },
  123. computed: {
  124. nicList () {
  125. return (this.hostInfo.nic_info || []).filter((o) => {
  126. return o.nic_type !== 'ipmi'
  127. })
  128. },
  129. ipmiList () {
  130. return (this.hostInfo.nic_info || []).filter((o) => {
  131. return o.nic_type === 'ipmi'
  132. })
  133. },
  134. nicInfo () {
  135. return _.sortBy(this.nicList, [
  136. (o) => {
  137. return o.mac
  138. },
  139. ])
  140. },
  141. },
  142. methods: {
  143. setWire (obj) {
  144. obj = {
  145. ...obj,
  146. hostId: this.hostInfo.id,
  147. }
  148. this.createDialog('HostSetWireDialog', {
  149. data: [obj],
  150. columns: this.columns,
  151. list: this.list,
  152. callback: () => {
  153. setTimeout(() => {
  154. this.$bus.$emit('refresh-detail')
  155. }, 1000)
  156. },
  157. })
  158. },
  159. },
  160. }
  161. </script>