InstallAgent.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips
  6. :name="$t('dictionary.server')"
  7. :count="params.data.length"
  8. :action="action" />
  9. <detect-ssh-table
  10. ref="endpointsTable"
  11. @onDetecting="handleDetectStatusChange"
  12. :params="params"
  13. :key="detectTableKey"
  14. :ansibleTasks="ansibleTasks"
  15. :remote="true" />
  16. <setup-ssh-form ref="stepForm" :servers="servers" @tasks="handleSetupSSHTasks" v-show="showForm" />
  17. </div>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading" :disabled="disabled">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import SetupSshForm from '../create/form/SetupSSHForm'
  26. import { DetectSshTable } from './DetectSSH'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. export default {
  30. name: 'InstallAgentDialog',
  31. components: {
  32. DetectSshTable,
  33. SetupSshForm,
  34. },
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. showForm: false,
  40. detectTableKey: 0,
  41. action: this.$t('compute.vminstance.monitor.install_agent'),
  42. ansibleTasks: {},
  43. }
  44. },
  45. computed: {
  46. servers () {
  47. return this.params.data.map((i) => { return i.id })
  48. },
  49. disabled () {
  50. return !this.params.data || this.params.data.length === 0
  51. },
  52. },
  53. methods: {
  54. handleSetupSSHTasks (tasks) {
  55. this.ansibleTasks = tasks
  56. },
  57. allServerSshable () {
  58. return this.params.data.every((server) => { return server.sshable_status === 'available' })
  59. },
  60. handleDetectStatusChange (e) {
  61. this.loading = e
  62. if (!e) {
  63. this.showForm = !this.allServerSshable()
  64. }
  65. },
  66. async handleConfirm () {
  67. this.loading = true
  68. try {
  69. if (!this.allServerSshable()) {
  70. await this.$refs.stepForm.submit().then((res) => {
  71. this.detectTableKey += 1
  72. })
  73. } else {
  74. const data = {
  75. auto_choose_proxy_endpoint: true,
  76. server_id: this.params.data[0].id,
  77. }
  78. const ret = await new this.$Manager('scripts').performAction({ id: 'monitor agent', action: 'apply', data: data })
  79. this.loading = false
  80. if (this.params.callback && typeof this.params.callback === 'function') {
  81. this.params.callback(ret.data.script_apply_id)
  82. }
  83. this.cancelDialog()
  84. }
  85. } catch (error) {
  86. this.loading = false
  87. }
  88. },
  89. },
  90. }
  91. </script>