VmUpdateNetworkAttr.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('compute.text_247') }}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <div slot="message">
  7. {{ $t('compute.update_network.alert') }}
  8. </div>
  9. </a-alert>
  10. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_247')" />
  11. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  12. <a-form :form="form.fc" hideRequiredMark v-bind="formItemLayout">
  13. <a-form-item :label="$t('compute.num_queues')">
  14. <a-tooltip placement="top" :title="$t('compute.num_queues')">
  15. <a-input-number
  16. v-decorator="decorators.num_queues"
  17. :min="1"
  18. :max="16" />
  19. </a-tooltip>
  20. </a-form-item>
  21. <a-form-item :label="$t('compute.text_860')">
  22. <a-select v-decorator="decorators.driver">
  23. <a-select-option v-for="item of driverArr" :key="item.key" :value="item.key">{{item.label}}</a-select-option>
  24. </a-select>
  25. </a-form-item>
  26. <a-form-item :label="$t('compute.nics.is_default')">
  27. <a-switch v-decorator="decorators.is_default" :disabled="is_default_on_init" />
  28. </a-form-item>
  29. </a-form>
  30. </div>
  31. <div slot="footer">
  32. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  33. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  34. </div>
  35. </base-dialog>
  36. </template>
  37. <script>
  38. import DialogMixin from '@/mixins/dialog'
  39. import WindowsMixin from '@/mixins/windows'
  40. export default {
  41. name: 'VmUpdateNetworkAttrDialog',
  42. mixins: [DialogMixin, WindowsMixin],
  43. data () {
  44. return {
  45. loading: false,
  46. form: {
  47. fc: this.$form.createForm(this),
  48. },
  49. decorators: {
  50. num_queues: [
  51. 'num_queues',
  52. {
  53. initialValue: this.params.data[0].num_queues || 1,
  54. },
  55. ],
  56. driver: [
  57. 'driver',
  58. {
  59. initialValue: this.params.data[0].driver || 'virtio',
  60. },
  61. ],
  62. is_default: [
  63. 'is_default',
  64. {
  65. valuePropName: 'checked',
  66. initialValue: this.params.data[0].is_default || false,
  67. },
  68. ],
  69. },
  70. driverArr: [
  71. { key: 'virtio', label: 'virtio' },
  72. { key: 'e1000', label: 'e1000' },
  73. { key: 'vmxnet3', label: 'vmxnet3' },
  74. { key: 'rtl8139', label: 'rtl8139' },
  75. ],
  76. formItemLayout: {
  77. wrapperCol: {
  78. span: 21,
  79. },
  80. labelCol: {
  81. span: 3,
  82. },
  83. },
  84. }
  85. },
  86. computed: {
  87. selectedItems () {
  88. return this.params.data
  89. },
  90. is_default_on_init () {
  91. return this.params.data[0].is_default || this.params.data[0].virtual
  92. },
  93. },
  94. methods: {
  95. async doUpdateNetworkAttr (values) {
  96. const manager = new this.$Manager('servers')
  97. const sid = this.params.resId
  98. const nid = this.params.data[0].network_id
  99. const data = {
  100. num_queues: values.num_queues,
  101. driver: values.driver,
  102. is_default: values.is_default,
  103. }
  104. const params = {
  105. mac: this.params.data[0].mac_addr,
  106. }
  107. return manager.update({
  108. id: `${sid}/networks/${nid}`,
  109. data,
  110. params,
  111. })
  112. },
  113. async handleConfirm () {
  114. this.loading = true
  115. try {
  116. const values = await this.form.fc.validateFields()
  117. await this.doUpdateNetworkAttr(values)
  118. this.params.refresh()
  119. this.cancelDialog()
  120. this.$message.success(this.$t('compute.text_423'))
  121. } finally {
  122. this.loading = false
  123. }
  124. },
  125. },
  126. }
  127. </script>