AdjustOversoldRatio.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_513')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.host')" :count="params.data.length" :action="$t('compute.text_513')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 2)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('compute.cpu_commit_bound')" v-bind="formItemLayout">
  10. <a-input-number v-decorator="decorators.cpu_cmtbound" :min="0.1" :step="0.1" />
  11. </a-form-item>
  12. <a-form-item :label="$t('compute.memory_commit_bound')" v-bind="formItemLayout">
  13. <template v-if="isOpenPage">
  14. <a-tooltip>
  15. <template slot="title">
  16. {{ $t('compute.host.open_page_size.tooltip') }}
  17. </template>
  18. <a-input-number v-decorator="decorators.mem_cmtbound" :min="0.1" :max="maxMemCmtBound" :step="0.1" :disabled="true" />
  19. </a-tooltip>
  20. </template>
  21. <a-input-number v-else v-decorator="decorators.mem_cmtbound" :min="0.1" :max="maxMemCmtBound" :step="0.1" />
  22. <div style="font-size:12px" class="add-desc">{{$t('compute.text_544')}}</div>
  23. </a-form-item>
  24. <a-form-item :label="$t('compute.memory_reserve_gb')" v-bind="formItemLayout">
  25. <template v-if="isOpenPage">
  26. <a-tooltip>
  27. <template slot="title">
  28. {{ $t('compute.host.open_page_size.tooltip') }}
  29. </template>
  30. <a-input-number v-decorator="decorators.mem_reserved" :min="1" :step="1" :disabled="true" />
  31. </a-tooltip>
  32. </template>
  33. <a-input-number v-else v-decorator="decorators.mem_reserved" :min="1" :step="1" />
  34. </a-form-item>
  35. </a-form>
  36. </div>
  37. <div slot="footer">
  38. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  39. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  40. </div>
  41. </base-dialog>
  42. </template>
  43. <script>
  44. import DialogMixin from '@/mixins/dialog'
  45. import WindowsMixin from '@/mixins/windows'
  46. export default {
  47. name: 'HostAdjustOversoldRatioDialog',
  48. mixins: [DialogMixin, WindowsMixin],
  49. data () {
  50. return {
  51. loading: false,
  52. scope: this.$store.getters.scope,
  53. form: {
  54. fc: this.$form.createForm(this),
  55. },
  56. decorators: {
  57. cpu_cmtbound: [
  58. 'cpu_cmtbound',
  59. {
  60. validateFirst: true,
  61. initialValue: this.params.data[0].cpu_commit_bound,
  62. rules: [
  63. {
  64. required: true,
  65. message: this.$t('compute.text_545'),
  66. },
  67. ],
  68. },
  69. ],
  70. mem_cmtbound: [
  71. 'mem_cmtbound',
  72. {
  73. validateFirst: true,
  74. initialValue: this.params.data[0].mem_commit_bound,
  75. rules: [
  76. {
  77. required: true,
  78. message: this.$t('compute.text_546'),
  79. },
  80. ],
  81. },
  82. ],
  83. mem_reserved: [
  84. 'mem_reserved',
  85. {
  86. validateFirst: true,
  87. initialValue: this.params.data[0].mem_reserved / 1024,
  88. rules: [
  89. {
  90. required: true,
  91. message: this.$t('compute.memory_reserve_gb.placeholder'),
  92. },
  93. ],
  94. },
  95. ],
  96. },
  97. formItemLayout: {
  98. wrapperCol: {
  99. span: 17,
  100. },
  101. labelCol: {
  102. span: 7,
  103. },
  104. },
  105. }
  106. },
  107. computed: {
  108. isOpenPage () {
  109. const firstItem = this.params.data[0]
  110. return firstItem?.page_size_kb > 4
  111. },
  112. maxMemCmtBound () {
  113. for (let i = 0; i < this.params.data.length; i++) {
  114. if (this.params.data[i].host_type !== 'container') {
  115. return 1.0
  116. }
  117. }
  118. return 8.0
  119. },
  120. },
  121. methods: {
  122. doUpdate (data) {
  123. const ids = this.params.data.map(item => item.id)
  124. return this.params.onManager('batchUpdate', {
  125. id: ids,
  126. managerArgs: {
  127. data: { mem_reserved: data.mem_reserved },
  128. },
  129. })
  130. },
  131. doPerformAction (data) {
  132. const ids = this.params.data.map(item => item.id)
  133. return this.params.onManager('batchPerformAction', {
  134. id: ids,
  135. managerArgs: {
  136. action: 'set-commit-bound',
  137. data: { cpu_cmtbound: data.cpu_cmtbound, mem_cmtbound: data.mem_cmtbound },
  138. },
  139. })
  140. },
  141. async handleConfirm () {
  142. this.loading = true
  143. try {
  144. let values = await this.form.fc.validateFields()
  145. values = {
  146. ...values,
  147. // name: this.params.data[0].name,
  148. }
  149. values.mem_reserved = values.mem_reserved * 1024
  150. await this.doUpdate(values)
  151. await this.doPerformAction(values)
  152. this.loading = false
  153. this.cancelDialog()
  154. this.params.refresh()
  155. } catch (error) {
  156. this.loading = false
  157. }
  158. },
  159. },
  160. }
  161. </script>