ChangeBandwidth.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1185')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1185')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" hideRequiredMark v-bind="formItemLayout">
  8. <a-form-item :label="$t('compute.bandwidth.symmetric.title')">
  9. <a-checkbox v-model="symmetricBandwidth" />
  10. </a-form-item>
  11. <a-form-item :label="$t('compute.bandwidth.title')" v-if="symmetricBandwidth">
  12. <a-tooltip placement="top" :title="$t('compute.text_1338', [[bandwidthMax]])">
  13. <a-input-number v-decorator="decorators.bandwidth" :parser="getParser" :min="0" :max="bandwidthMax" />
  14. Mbps
  15. </a-tooltip>
  16. </a-form-item>
  17. <a-form-item :label="$t('compute.bandwidth.tx.title')" v-if="!symmetricBandwidth">
  18. <a-tooltip placement="top" :title="$t('compute.text_1338', [[bandwidthMax]])">
  19. <a-input-number v-decorator="decorators.tx_bw_limit" :parser="getParser" :min="0" :max="bandwidthMax" />
  20. Mbps
  21. </a-tooltip>
  22. </a-form-item>
  23. <a-form-item :label="$t('compute.bandwidth.rx.title')" v-if="!symmetricBandwidth">
  24. <a-tooltip placement="top" :title="$t('compute.text_1338', [[bandwidthMax]])">
  25. <a-input-number v-decorator="decorators.rx_bw_limit" :parser="getParser" :min="0" :max="bandwidthMax" />
  26. Mbps
  27. </a-tooltip>
  28. </a-form-item>
  29. <a-form-item :label="$t('compute.text_1041')" v-if="isOpenWorkflow">
  30. <a-input v-decorator="decorators.reason" :placeholder="$t('compute.text_1105')" />
  31. </a-form-item>
  32. </a-form>
  33. </div>
  34. <div slot="footer">
  35. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  36. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  37. </div>
  38. </base-dialog>
  39. </template>
  40. <script>
  41. import { mapGetters } from 'vuex'
  42. import DialogMixin from '@/mixins/dialog'
  43. import WindowsMixin from '@/mixins/windows'
  44. import WorkflowMixin from '@/mixins/workflow'
  45. export default {
  46. name: 'VmChangeBandwidthDialog',
  47. mixins: [DialogMixin, WindowsMixin, WorkflowMixin],
  48. data () {
  49. return {
  50. loading: false,
  51. form: {
  52. fc: this.$form.createForm(this),
  53. },
  54. decorators: {
  55. bandwidth: [
  56. 'bandwidth',
  57. {
  58. initialValue: this.params.data[0].bw_limit || 0,
  59. rules: [
  60. { required: true, message: this.$t('compute.text_1188') },
  61. ],
  62. },
  63. ],
  64. tx_bw_limit: [
  65. 'tx_bw_limit',
  66. {
  67. initialValue: this.params.data[0].tx_bw_limit || 0,
  68. },
  69. ],
  70. rx_bw_limit: [
  71. 'rx_bw_limit',
  72. {
  73. initialValue: this.params.data[0].rx_bw_limit || 0,
  74. },
  75. ],
  76. reason: [
  77. 'reason',
  78. {
  79. initialValue: '',
  80. },
  81. ],
  82. },
  83. formItemLayout: {
  84. wrapperCol: {
  85. span: 21,
  86. },
  87. labelCol: {
  88. span: 3,
  89. },
  90. },
  91. bandwidthMax: 100000,
  92. symmetricBandwidth: !this.params.data[0].tx_bw_limit || !this.params.data[0].rx_bw_limit,
  93. }
  94. },
  95. computed: {
  96. ...mapGetters(['isAdminMode', 'scope', 'userInfo']),
  97. selectedItems () {
  98. return this.params.data
  99. },
  100. isOpenWorkflow () {
  101. return this.checkWorkflowEnabled(this.WORKFLOW_TYPES.APPLY_SERVER_CHANGECONFIG)
  102. },
  103. },
  104. methods: {
  105. async doChangeBandwidth (values) {
  106. const manager = new this.$Manager('servers')
  107. const ids = this.params.data.map(item => item.guest_id)
  108. const data = {
  109. bandwidth: values.bandwidth,
  110. tx_bw_limit: values.tx_bw_limit,
  111. rx_bw_limit: values.rx_bw_limit,
  112. mac: this.params.data[0].mac_addr,
  113. }
  114. return manager.batchPerformAction({
  115. ids,
  116. action: 'change-bandwidth',
  117. data,
  118. })
  119. },
  120. async doChangeBandwidthByWorkflow (values) {
  121. const curData = this.params.data[0]
  122. const params = {
  123. bandwidth: values.bandwidth,
  124. mac: curData.mac_addr,
  125. }
  126. const resData = this.params.resData
  127. const serverConf = resData.map((item) => {
  128. return {
  129. name: item.name,
  130. project: item.tenant,
  131. ip_addr: curData.ip_addr,
  132. before: {
  133. bw_limit: curData.bw_limit,
  134. tx_bw_limit: curData.tx_bw_limit,
  135. rx_bw_limit: curData.rx_bw_limit,
  136. },
  137. after: {
  138. bw_limit: values.bandwidth,
  139. tx_bw_limit: values.tx_bw_limit,
  140. rx_bw_limit: values.rx_bw_limit,
  141. },
  142. }
  143. })
  144. params.project_id = this.userInfo.projectId
  145. params.domain = this.userInfo.projectDomainId
  146. const variables = {
  147. change_type: 'change-bandwidth',
  148. project: resData[0].tenant_id,
  149. project_domain: resData[0].domain_id,
  150. process_definition_key: this.WORKFLOW_TYPES.APPLY_SERVER_CHANGECONFIG,
  151. initiator: this.userInfo.id,
  152. 'change-bandwidth-paramter': JSON.stringify(params),
  153. ids: resData[0].id,
  154. serverConf: JSON.stringify(serverConf),
  155. description: values.reason,
  156. }
  157. await this.createWorkflow(variables)
  158. this.$message.success(this.$t('common.worflow_tip', [this.$t('compute.text_1185')]))
  159. this.$router.push('/workflow')
  160. },
  161. async handleConfirm () {
  162. this.loading = true
  163. try {
  164. const values = await this.form.fc.validateFields()
  165. if (this.isOpenWorkflow) {
  166. await this.doChangeBandwidthByWorkflow(values)
  167. } else {
  168. await this.doChangeBandwidth(values)
  169. }
  170. this.params.refresh()
  171. this.cancelDialog()
  172. this.$message.success(this.$t('compute.text_423'))
  173. } finally {
  174. this.loading = false
  175. }
  176. },
  177. getParser (val) {
  178. if (isNaN(val)) {
  179. return 0
  180. }
  181. return Math.round(val)
  182. },
  183. },
  184. }
  185. </script>