| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{$t('compute.text_513')}}</div>
- <div slot="body">
- <dialog-selected-tips :name="$t('dictionary.host')" :count="params.data.length" :action="$t('compute.text_513')" />
- <dialog-table :data="params.data" :columns="params.columns.slice(0, 2)" />
- <a-form
- :form="form.fc">
- <a-form-item :label="$t('compute.cpu_commit_bound')" v-bind="formItemLayout">
- <a-input-number v-decorator="decorators.cpu_cmtbound" :min="0.1" :step="0.1" />
- </a-form-item>
- <a-form-item :label="$t('compute.memory_commit_bound')" v-bind="formItemLayout">
- <template v-if="isOpenPage">
- <a-tooltip>
- <template slot="title">
- {{ $t('compute.host.open_page_size.tooltip') }}
- </template>
- <a-input-number v-decorator="decorators.mem_cmtbound" :min="0.1" :max="maxMemCmtBound" :step="0.1" :disabled="true" />
- </a-tooltip>
- </template>
- <a-input-number v-else v-decorator="decorators.mem_cmtbound" :min="0.1" :max="maxMemCmtBound" :step="0.1" />
- <div style="font-size:12px" class="add-desc">{{$t('compute.text_544')}}</div>
- </a-form-item>
- <a-form-item :label="$t('compute.memory_reserve_gb')" v-bind="formItemLayout">
- <template v-if="isOpenPage">
- <a-tooltip>
- <template slot="title">
- {{ $t('compute.host.open_page_size.tooltip') }}
- </template>
- <a-input-number v-decorator="decorators.mem_reserved" :min="1" :step="1" :disabled="true" />
- </a-tooltip>
- </template>
- <a-input-number v-else v-decorator="decorators.mem_reserved" :min="1" :step="1" />
- </a-form-item>
- </a-form>
- </div>
- <div slot="footer">
- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'HostAdjustOversoldRatioDialog',
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- scope: this.$store.getters.scope,
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- cpu_cmtbound: [
- 'cpu_cmtbound',
- {
- validateFirst: true,
- initialValue: this.params.data[0].cpu_commit_bound,
- rules: [
- {
- required: true,
- message: this.$t('compute.text_545'),
- },
- ],
- },
- ],
- mem_cmtbound: [
- 'mem_cmtbound',
- {
- validateFirst: true,
- initialValue: this.params.data[0].mem_commit_bound,
- rules: [
- {
- required: true,
- message: this.$t('compute.text_546'),
- },
- ],
- },
- ],
- mem_reserved: [
- 'mem_reserved',
- {
- validateFirst: true,
- initialValue: this.params.data[0].mem_reserved / 1024,
- rules: [
- {
- required: true,
- message: this.$t('compute.memory_reserve_gb.placeholder'),
- },
- ],
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 17,
- },
- labelCol: {
- span: 7,
- },
- },
- }
- },
- computed: {
- isOpenPage () {
- const firstItem = this.params.data[0]
- return firstItem?.page_size_kb > 4
- },
- maxMemCmtBound () {
- for (let i = 0; i < this.params.data.length; i++) {
- if (this.params.data[i].host_type !== 'container') {
- return 1.0
- }
- }
- return 8.0
- },
- },
- methods: {
- doUpdate (data) {
- const ids = this.params.data.map(item => item.id)
- return this.params.onManager('batchUpdate', {
- id: ids,
- managerArgs: {
- data: { mem_reserved: data.mem_reserved },
- },
- })
- },
- doPerformAction (data) {
- const ids = this.params.data.map(item => item.id)
- return this.params.onManager('batchPerformAction', {
- id: ids,
- managerArgs: {
- action: 'set-commit-bound',
- data: { cpu_cmtbound: data.cpu_cmtbound, mem_cmtbound: data.mem_cmtbound },
- },
- })
- },
- async handleConfirm () {
- this.loading = true
- try {
- let values = await this.form.fc.validateFields()
- values = {
- ...values,
- // name: this.params.data[0].name,
- }
- values.mem_reserved = values.mem_reserved * 1024
- await this.doUpdate(values)
- await this.doPerformAction(values)
- this.loading = false
- this.cancelDialog()
- this.params.refresh()
- } catch (error) {
- this.loading = false
- }
- },
- },
- }
- </script>
|