This repository was archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
vm: backend migration changes support #789
Open
shwstppr
wants to merge
12
commits into
apache:master
Choose a base branch
from
shapeblue:vm-migrate-backend-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
506bcf6
vm: backend migration changes support
shwstppr 5910756
add missing file
shwstppr 92dd3c7
show storage migration required
shwstppr 48e02d9
show cluster, pod name
shwstppr 53603ac
fix vm storage migration
shwstppr a4b457f
fix
shwstppr 9ae20c5
wip changes
shwstppr a9099bc
fix
shwstppr 186d36b
Merge branch 'master' into vm-migrate-backend-improvements
shwstppr 271fb2c
Merge branch 'master' into vm-migrate-backend-improvements
shwstppr ef965cd
change storage migration reqd label key
shwstppr 45ca67f
Merge branch 'master' into vm-migrate-backend-improvements
shwstppr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| <template> | ||
| <div class="form-layout"> | ||
| <a-spin :spinning="loading"> | ||
| <a-form | ||
| :form="form" | ||
| @submit="handleSubmit" | ||
| layout="vertical"> | ||
| <a-form-item> | ||
| <span slot="label"> | ||
| {{ $t('label.storageid') }} | ||
| <a-tooltip :title="apiParams.storageid.description" v-if="!(apiParams.hostid && apiParams.hostid.required === false)"> | ||
| <a-icon type="info-circle" style="color: rgba(0,0,0,.45)" /> | ||
| </a-tooltip> | ||
| </span> | ||
| <a-select | ||
| :loading="loading" | ||
| v-decorator="['storageid', { | ||
| rules: [{ required: true, message: `${this.$t('message.error.required.input')}` }] | ||
| }]"> | ||
| <a-select-option v-for="storagePool in storagePools" :key="storagePool.id"> | ||
| {{ storagePool.name || storagePool.id }} | ||
| </a-select-option> | ||
| </a-select> | ||
| </a-form-item> | ||
|
|
||
| <div :span="24" class="action-button"> | ||
| <a-button @click="closeAction">{{ this.$t('label.cancel') }}</a-button> | ||
| <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('label.ok') }}</a-button> | ||
| </div> | ||
| </a-form> | ||
| </a-spin> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { api } from '@/api' | ||
|
|
||
| export default { | ||
| name: 'MigrateVMStorage', | ||
| props: { | ||
| resource: { | ||
| type: Object, | ||
| required: true | ||
| } | ||
| }, | ||
| data () { | ||
| return { | ||
| loading: false, | ||
| storagePools: [] | ||
| } | ||
| }, | ||
| beforeCreate () { | ||
| this.form = this.$form.createForm(this) | ||
| this.apiParams = {} | ||
| if (this.$route.meta.name === 'vm') { | ||
| this.apiConfig = this.$store.getters.apis.migrateVirtualMachineWithVolume || {} | ||
| this.apiConfig.params.forEach(param => { | ||
| this.apiParams[param.name] = param | ||
| }) | ||
| this.apiConfig = this.$store.getters.apis.migrateVirtualMachine || {} | ||
| this.apiConfig.params.forEach(param => { | ||
| if (!(param.name in this.apiParams)) { | ||
| this.apiParams[param.name] = param | ||
| } | ||
| }) | ||
| } else { | ||
| this.apiConfig = this.$store.getters.apis.migrateSystemVm || {} | ||
| this.apiConfig.params.forEach(param => { | ||
| if (!(param.name in this.apiParams)) { | ||
| this.apiParams[param.name] = param | ||
| } | ||
| }) | ||
| } | ||
| }, | ||
| created () { | ||
| }, | ||
| mounted () { | ||
| this.fetchData() | ||
| }, | ||
| methods: { | ||
| fetchData () { | ||
| this.loading = true | ||
| api('listStoragePools', { | ||
| zoneid: this.resource.zoneid | ||
| }).then(response => { | ||
| if (this.arrayHasItems(response.liststoragepoolsresponse.storagepool)) { | ||
| this.storagePools = response.liststoragepoolsresponse.storagepool | ||
| } | ||
| }).finally(() => { | ||
| this.loading = false | ||
| }) | ||
| }, | ||
| isValidValueForKey (obj, key) { | ||
| return key in obj && obj[key] != null | ||
| }, | ||
| arrayHasItems (array) { | ||
| return array !== null && array !== undefined && Array.isArray(array) && array.length > 0 | ||
| }, | ||
| isObjectEmpty (obj) { | ||
| return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object) | ||
| }, | ||
| handleSubmit (e) { | ||
| e.preventDefault() | ||
| this.form.validateFields((err, values) => { | ||
| if (err) { | ||
| return | ||
| } | ||
| this.loading = true | ||
| var isUserVm = true | ||
| if (this.$route.meta.name !== 'vm') { | ||
| isUserVm = false | ||
| } | ||
| var migrateApi = isUserVm ? 'migrateVirtualMachine' : 'migrateSystemVm' | ||
| if (isUserVm && this.apiParams.hostid && this.apiParams.hostid.required === false) { | ||
| migrateApi = 'migrateVirtualMachineWithVolume' | ||
| var rootVolume = null | ||
| api('listVolumes', { | ||
| listAll: true, | ||
| virtualmachineid: this.resource.id | ||
| }).then(response => { | ||
| var volumes = response.listvolumesresponse.volume | ||
| if (volumes && volumes.length > 0) { | ||
| volumes = volumes.filter(item => item.type === 'ROOT') | ||
| if (volumes && volumes.length > 0) { | ||
| rootVolume = volumes[0] | ||
| } | ||
| if (rootVolume == null) { | ||
| this.$message.error('Failed to find ROOT volume for the VM ' + this.resource.id) | ||
| this.closeAction() | ||
| } | ||
| this.migrateVm(migrateApi, values.storageid, rootVolume.id) | ||
| } | ||
| }) | ||
| return | ||
| } | ||
| this.migrateVm(migrateApi, values.storageid, null) | ||
| }) | ||
| }, | ||
| migrateVm (migrateApi, storageId, rootVolumeId) { | ||
| var params = { | ||
| virtualmachineid: this.resource.id, | ||
| storageid: storageId | ||
| } | ||
| if (rootVolumeId !== null) { | ||
| params = { | ||
| virtualmachineid: this.resource.id, | ||
| 'migrateto[0].volume': rootVolumeId, | ||
| 'migrateto[0].pool': storageId | ||
| } | ||
| } | ||
| api(migrateApi, params).then(response => { | ||
| var jobId = '' | ||
| if (migrateApi === 'migrateVirtualMachineWithVolume') { | ||
| jobId = response.migratevirtualmachinewithvolumeresponse.jobid | ||
| } else if (migrateApi === 'migrateSystemVm') { | ||
| jobId = response.migratesystemvmresponse.jobid | ||
| } else { | ||
| jobId = response.migratevirtualmachine.jobid | ||
| } | ||
| this.$store.dispatch('AddAsyncJob', { | ||
| title: `${this.$t('label.migrating')} ${this.resource.name}`, | ||
| jobid: jobId, | ||
| description: this.resource.name, | ||
| status: 'progress' | ||
| }) | ||
| this.$pollJob({ | ||
| jobId: jobId, | ||
| successMessage: `${this.$t('message.success.migrating')} ${this.resource.name}`, | ||
| successMethod: () => { | ||
| this.$parent.$parent.close() | ||
| }, | ||
| errorMessage: this.$t('message.migrating.failed'), | ||
| errorMethod: () => { | ||
| this.$parent.$parent.close() | ||
| }, | ||
| loadingMessage: `${this.$t('message.migrating.processing')} ${this.resource.name}`, | ||
| catchMessage: this.$t('error.fetching.async.job.result'), | ||
| catchMethod: () => { | ||
| this.$parent.$parent.close() | ||
| } | ||
| }) | ||
| this.$parent.$parent.close() | ||
| }).catch(error => { | ||
| console.error(error) | ||
| this.$message.error(`${this.$t('message.migrating.vm.to.storage.failed')} ${storageId}`) | ||
| }) | ||
| }, | ||
| closeAction () { | ||
| this.$emit('close-action') | ||
| } | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| <style scoped lang="less"> | ||
| .form-layout { | ||
| width: 60vw; | ||
|
|
||
| @media (min-width: 500px) { | ||
| width: 450px; | ||
| } | ||
| } | ||
|
|
||
| .action-button { | ||
| text-align: right; | ||
|
|
||
| button { | ||
| margin-right: 5px; | ||
| } | ||
| } | ||
| </style> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"label.storage.migration.required" key might look better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sureshanaparti done