Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.

Commit f7d509f

Browse files
authored
Fixing host count for migratevm (#788)
* Revert "Not relying on erroneous count returned by findHostsForMigration (#774)" This reverts commit c662440. * Fixing host count for migratevm * Sorting based on suitability
1 parent 0a7cd7e commit f7d509f

2 files changed

Lines changed: 21 additions & 51 deletions

File tree

src/config/section/compute.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,8 @@ export default {
293293
docHelp: 'adminguide/virtual_machines.html#moving-vms-between-hosts-manual-live-migration',
294294
dataView: true,
295295
show: (record, store) => { return ['Running'].includes(record.state) && ['Admin'].includes(store.userInfo.roletype) },
296-
component: () => import('@/views/compute/MigrateWizard'),
297296
popup: true,
298-
args: ['hostid', 'virtualmachineid'],
299-
mapping: {
300-
virtualmachineid: {
301-
value: (record) => { return record.id }
302-
}
303-
}
297+
component: () => import('@/views/compute/MigrateWizard')
304298
},
305299
{
306300
api: 'migrateVirtualMachine',

src/views/compute/MigrateWizard.vue

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
:placeholder="$t('label.search')"
2222
v-model="searchQuery"
2323
style="margin-bottom: 10px;"
24-
@search="handleSearch" />
24+
@search="fetchData" />
2525
<a-table
2626
size="small"
2727
style="overflow-y: auto"
2828
:loading="loading"
2929
:columns="columns"
30-
:dataSource="items"
30+
:dataSource="hosts"
3131
:pagination="false"
3232
:rowKey="record => record.id">
3333
<div slot="suitability" slot-scope="record">
@@ -95,7 +95,6 @@ export default {
9595
return {
9696
loading: true,
9797
hosts: [],
98-
items: [],
9998
selectedHost: {},
10099
searchQuery: '',
101100
totalCount: 0,
@@ -130,34 +129,23 @@ export default {
130129
},
131130
methods: {
132131
fetchData () {
133-
var page = 1
134-
const hosts = []
135-
const getNextPage = () => {
136-
this.loading = true
137-
api('findHostsForMigration', {
138-
virtualmachineid: this.resource.id,
139-
listAll: true,
140-
details: 'min',
141-
page: page,
142-
pageSize: 500
143-
}).then(response => {
144-
if (response && response.findhostsformigrationresponse && response.findhostsformigrationresponse.host) {
145-
hosts.push(...response.findhostsformigrationresponse.host)
146-
}
147-
if (response.findhostsformigrationresponse.host) {
148-
page++
149-
getNextPage()
150-
}
151-
}).catch(error => {
152-
this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`)
153-
}).finally(() => {
154-
this.hosts = hosts
155-
this.totalCount = this.hosts.length
156-
this.items = this.hosts.slice(0, Math.min(this.totalCount, this.pageSize))
157-
this.loading = false
132+
this.loading = true
133+
api('findHostsForMigration', {
134+
virtualmachineid: this.resource.id,
135+
keyword: this.searchQuery,
136+
page: this.page,
137+
pagesize: this.pageSize
138+
}).then(response => {
139+
this.hosts = response.findhostsformigrationresponse.host || []
140+
this.hosts.sort((a, b) => {
141+
return b.suitableformigration - a.suitableformigration
158142
})
159-
}
160-
getNextPage()
143+
this.totalCount = response.findhostsformigrationresponse.count
144+
}).catch(error => {
145+
this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`)
146+
}).finally(() => {
147+
this.loading = false
148+
})
161149
},
162150
submitForm () {
163151
this.loading = true
@@ -193,27 +181,15 @@ export default {
193181
this.$message.error(`${this.$t('message.migrating.vm.to.host.failed')} ${this.selectedHost.name}`)
194182
})
195183
},
196-
handleSearch () {
197-
this.loading = true
198-
this.page = 1
199-
this.items = this.hosts.filter(x => x.name.toLowerCase().includes(this.searchQuery))
200-
this.totalCount = this.items.length
201-
this.items = this.items.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
202-
this.loading = false
203-
},
204184
handleChangePage (page, pageSize) {
205-
this.loading = true
206185
this.page = page
207186
this.pageSize = pageSize
208-
this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
209-
this.loading = false
187+
this.fetchData()
210188
},
211189
handleChangePageSize (currentPage, pageSize) {
212-
this.loading = true
213190
this.page = currentPage
214191
this.pageSize = pageSize
215-
this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
216-
this.loading = false
192+
this.fetchData()
217193
}
218194
},
219195
filters: {

0 commit comments

Comments
 (0)