rhtyd commented on a change in pull request #67: VM Migration Action form URL: https://github.com/apache/cloudstack-primate/pull/67#discussion_r356772382
########## File path: src/views/compute/MigrateWizard.vue ########## @@ -36,12 +85,146 @@ export default { }, data () { return { + loading: true, + hosts: [], + selectedIndex: null, + searchQuery: '' } }, + mounted () { + this.fetchData() + }, methods: { + fetchData () { + this.loading = true + api('findHostsForMigration', { + virtualmachineid: this.resource.id, + keyword: this.searchQuery + }).then(response => { + this.hosts = response.findhostsformigrationresponse.host + this.loading = false + }).catch(error => { + this.$message.error('Failed to load hosts: ' + error) + }) + }, + submitForm () { + this.loading = true + api('migrateVirtualMachine', { + hostid: this.hosts[this.selectedIndex].id, + virtualmachineid: this.resource.id + }).then(response => { + this.pollActionCompletion(response.migratevirtualmachineresponse.jobid) + }).catch(error => { + console.error(error) + this.$message.error('Failed to migrate host.') + }) + }, + pollActionCompletion (jobId) { + api('queryAsyncJobResult', { jobId }).then(json => { + const result = json.queryasyncjobresultresponse + if (result.jobstatus === 1) { + this.$message.success(`Migration completed successfully for ${this.resource.name}`) + this.$parent.$parent.close() + } else if (result.jobstatus === 2) { + this.$message.error(`Migration failed for ${this.resource.name}`) + this.fetchData() + } else if (result.jobstatus === 0) { + this.$message + .loading(`Migration in progress for ${this.resource.name}`, 3) + .then(() => this.pollActionCompletion(jobId)) Review comment: How about we close the form, irrespective of success or failure like others for consistency? Alternatively, at least on errors show the full error message from the job response? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services