2626 class =" top-spaced"
2727 :placeholder =" $t('label.search')"
2828 v-model:value =" searchQuery"
29- @search =" fetchData "
29+ @search =" fetchHostsForMigration "
3030 v-focus =" true" />
3131 <a-table
3232 class =" top-spaced"
9797 </a-pagination >
9898
9999 <a-form-item
100- v-if =" isUserVm"
100+ v-if =" isUserVm && hasVolumes "
101101 class =" top-spaced" >
102102 <template #label >
103103 <tooltip-label :title =" $t('label.migrate.with.storage')" :tooltip =" $t('message.migrate.with.storage')" />
106106 v-model:checked =" migrateWithStorage"
107107 :disabled =" !selectedHost || !selectedHost.id || selectedHost.id === -1" />
108108 </a-form-item >
109+
110+ <a-radio-group
111+ v-if =" migrateWithStorage"
112+ v-model:value =" migrateMode"
113+ @change =" e => { handleMigrateModeChange(e.target.value) }" >
114+ <a-radio class =" radio-style" :value =" 1" >
115+ {{ $t('label.migrate.instance.single.storage') }}
116+ </a-radio >
117+ <a-radio class =" radio-style" :value =" 2" >
118+ {{ $t('label.migrate.instance.specific.storages') }}
119+ </a-radio >
120+ </a-radio-group >
121+
122+ <div v-if =" migrateWithStorage && migrateMode == 1" >
123+ <storage-pool-select-view
124+ ref =" storagePoolSelection"
125+ :autoAssignAllowed =" false"
126+ :resource =" resource"
127+ @select =" handleStoragePoolChange" />
128+ </div >
109129 <instance-volumes-storage-pool-select-list-view
110130 ref =" volumeToPoolSelect"
111- v-if =" migrateWithStorage"
131+ v-if =" migrateWithStorage && migrateMode !== 1 "
112132 class =" top-spaced"
113133 :resource =" resource"
114134 :clusterId =" selectedHost.id ? selectedHost.clusterid : null"
118138
119139 <div class =" actions" >
120140 <a-button @click =" closeModal" >{{ $t('label.cancel') }}</a-button >
121- <a-button type =" primary" ref =" submit" :disabled =" !selectedHost.id" @click =" submitForm" >{{ $t('label.ok') }}</a-button >
141+ <a-button type =" primary" ref =" submit" :disabled =" !selectedHost.id || (migrateWithStorage && migrateMode === 1 && !volumeToPoolSelection.length) " @click =" submitForm" >{{ $t('label.ok') }}</a-button >
122142 </div >
123143 </div >
124144</template >
125145
126146<script >
127147import { api } from ' @/api'
128148import TooltipLabel from ' @/components/widgets/TooltipLabel'
149+ import StoragePoolSelectView from ' @/components/view/StoragePoolSelectView'
129150import InstanceVolumesStoragePoolSelectListView from ' @/components/view/InstanceVolumesStoragePoolSelectListView'
130151
131152export default {
132153 name: ' VMMigrateWizard' ,
133154 components: {
134155 TooltipLabel,
156+ StoragePoolSelectView,
135157 InstanceVolumesStoragePoolSelectListView
136158 },
137159 props: {
@@ -188,6 +210,7 @@ export default {
188210 }
189211 ],
190212 migrateWithStorage: false ,
213+ migrateMode: 1 ,
191214 volumeToPoolSelection: [],
192215 volumes: []
193216 }
@@ -198,6 +221,9 @@ export default {
198221 computed: {
199222 isUserVm () {
200223 return this .$route .meta .resourceType === ' UserVm'
224+ },
225+ hasVolumes () {
226+ return this .volumes && this .volumes .length > 0
201227 }
202228 },
203229 watch: {
@@ -212,6 +238,10 @@ export default {
212238 return array !== null && array !== undefined && Array .isArray (array) && array .length > 0
213239 },
214240 fetchData () {
241+ this .fetchHostsForMigration ()
242+ this .fetchVolumes ()
243+ },
244+ fetchHostsForMigration () {
215245 this .loading = true
216246 api (' findHostsForMigration' , {
217247 virtualmachineid: this .resource .id ,
@@ -239,17 +269,16 @@ export default {
239269 handleChangePage (page , pageSize ) {
240270 this .page = page
241271 this .pageSize = pageSize
242- this .fetchData ()
272+ this .fetchHostsForMigration ()
243273 },
244274 handleChangePageSize (currentPage , pageSize ) {
245275 this .page = currentPage
246276 this .pageSize = pageSize
247- this .fetchData ()
277+ this .fetchHostsForMigration ()
248278 },
249279 handleSelectedHostChange (host ) {
250280 if (host .id === - 1 ) {
251281 this .migrateWithStorage = false
252- this .fetchVolumes ()
253282 }
254283 this .selectedHost = host
255284 this .selectedVolumeForStoragePoolSelection = {}
@@ -258,6 +287,17 @@ export default {
258287 this .$refs .volumeToPoolSelect .resetSelection ()
259288 }
260289 },
290+ handleMigrateModeChange () {
291+ this .volumeToPoolSelection = []
292+ },
293+ handleStoragePoolChange (storagePool ) {
294+ this .volumeToPoolSelection = []
295+ for (const volume of this .volumes ) {
296+ if (storagePool && storagePool .id && storagePool .id !== - 1 ) {
297+ this .volumeToPoolSelection .push ({ volume: volume .id , pool: storagePool .id })
298+ }
299+ }
300+ },
261301 handleVolumeToPoolChange (volumeToPool ) {
262302 this .volumeToPoolSelection = volumeToPool
263303 },
@@ -268,7 +308,7 @@ export default {
268308 listAll: true ,
269309 virtualmachineid: this .resource .id
270310 }).then (response => {
271- this .volumes = response .listvolumesresponse .volume
311+ this .volumes = response? .listvolumesresponse ? .volume || []
272312 }).finally (() => {
273313 this .loading = false
274314 })
@@ -277,7 +317,7 @@ export default {
277317 if (this .selectedHost .requiresStorageMotion || this .volumeToPoolSelection .length > 0 ) {
278318 return true
279319 }
280- if (this .selectedHost .id === - 1 && this .volumes && this . volumes . length > 0 ) {
320+ if (this .selectedHost .id === - 1 && this .hasVolumes ) {
281321 for (var volume of this .volumes ) {
282322 if (volume .storagetype === ' local' ) {
283323 return true
@@ -305,7 +345,7 @@ export default {
305345 var params = this .selectedHost .id === - 1
306346 ? { autoselect: true , virtualmachineid: this .resource .id }
307347 : { hostid: this .selectedHost .id , virtualmachineid: this .resource .id }
308- if (this .migrateWithStorage ) {
348+ if (this .migrateWithStorage && this . volumeToPoolSelection && this . volumeToPoolSelection . length > 0 ) {
309349 for (var i = 0 ; i < this .volumeToPoolSelection .length ; i++ ) {
310350 const mapping = this .volumeToPoolSelection [i]
311351 params[' migrateto[' + i + ' ].volume' ] = mapping .volume
0 commit comments