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 36
compute: import vm #426
Draft
shwstppr
wants to merge
1
commit into
apache:master
Choose a base branch
from
shapeblue:feature-vm-import
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.
Draft
compute: import vm #426
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| // 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 :label="$t('label.cluster')"> | ||
| <a-select | ||
| v-decorator="['clusterid', { | ||
| rules: [{ required: true }] | ||
| }]" | ||
| showSearch | ||
| optionFilterProp="children" | ||
| :filterOption="(input, option) => { | ||
| return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 | ||
| }" | ||
| :loading="clusterLoading" | ||
| :placeholder="apiParams.clusterid.description" | ||
| @change="val => { this.handleClusterChange(this.clusters[val]) }"> | ||
| <a-select-option v-for="(opt, optIndex) in this.clusters" :key="optIndex"> | ||
| {{ opt.name || opt.description }} | ||
| </a-select-option> | ||
| </a-select> | ||
| </a-form-item> | ||
| <a-form-item :label="$t('label.virtual.machine')"> | ||
| <a-select | ||
| v-decorator="['unmanagedinstance', { | ||
| rules: [{ required: true }] | ||
| }]" | ||
| showSearch | ||
| optionFilterProp="children" | ||
| :filterOption="(input, option) => { | ||
| return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 | ||
| }" | ||
| :loading="unmanagedInstanceLoading" | ||
| :placeholder="apiParams.name.description"> | ||
| <a-select-option v-for="(opt, optIndex) in this.unmanagedInstances" :key="optIndex"> | ||
| {{ opt.name || opt.description }} | ||
| </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: 'ImportVM', | ||
| props: { | ||
| resource: { | ||
| type: Object, | ||
| required: true | ||
| } | ||
| }, | ||
| data () { | ||
| return { | ||
| loading: false, | ||
| clusters: [], | ||
| clusterLoading: false, | ||
| selectedCluster: {}, | ||
| unmanagedInstances: [], | ||
| unmanagedInstanceLoading: false, | ||
| selectedUnmanagedInstance: {} | ||
| } | ||
| }, | ||
| beforeCreate () { | ||
| this.form = this.$form.createForm(this) | ||
| this.apiConfig = this.$store.getters.apis.importUnmanagedInstance || {} | ||
| this.apiParams = {} | ||
| this.apiConfig.params.forEach(param => { | ||
| this.apiParams[param.name] = param | ||
| }) | ||
| }, | ||
| created () { | ||
| }, | ||
| mounted () { | ||
| this.fetchData() | ||
| }, | ||
| methods: { | ||
| fetchData () { | ||
| this.fetchClusterData() | ||
| }, | ||
| 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) | ||
| }, | ||
| fetchClusterData () { | ||
| this.clusters = [] | ||
| this.selectedCluster = {} | ||
| this.unmanagedInstances = [] | ||
| this.selectedUnmanagedInstance = {} | ||
| this.clusterLoading = true | ||
| api('listClusters', {}).then(json => { | ||
| const listClusters = json.listclustersresponse.cluster | ||
| if (this.arrayHasItems(listClusters)) { | ||
| for (var cluster of listClusters) { | ||
| if (cluster.hypervisortype === 'VMware') { | ||
| this.clusters.push(cluster) | ||
| } | ||
| } | ||
| } | ||
| }).finally(() => { | ||
| this.clusterLoading = false | ||
| if (this.arrayHasItems(this.clusters)) { | ||
| this.form.setFieldsValue({ | ||
| clusterid: 0 | ||
| }) | ||
| this.handleClusterChange(this.clusters[0]) | ||
| } | ||
| }) | ||
| }, | ||
| handleClusterChange (cluster) { | ||
| this.selectedCluster = cluster | ||
| this.fetchUnmanagedInstanceData() | ||
| }, | ||
| fetchUnmanagedInstanceData () { | ||
| this.unmanagedInstances = [] | ||
| this.selectedUnmanagedInstance = {} | ||
| if (this.isObjectEmpty(this.selectedCluster)) { | ||
| return | ||
| } | ||
| const params = { | ||
| clusterid: this.selectedCluster.id | ||
| } | ||
| this.unmanagedInstanceLoading = true | ||
| api('listUnmanagedInstances', params).then(json => { | ||
| const instanceObjs = json.listunmanagedinstancesresponse.unmanagedinstance | ||
| if (this.arrayHasItems(instanceObjs)) { | ||
| this.unmanagedInstances = this.unmanagedInstances.concat(instanceObjs) | ||
| } | ||
| }).finally(() => { | ||
| this.unmanagedInstanceLoading = false | ||
| if (this.arrayHasItems(this.unmanagedInstances)) { | ||
| this.form.setFieldsValue({ | ||
| unmanagedinstance: 0 | ||
| }) | ||
| this.handleUnmanagedInstanceChange(this.unmanagedInstances[0]) | ||
| } | ||
| }) | ||
| }, | ||
| handleUnmanagedInstanceChange (unmanagedInstance) { | ||
| this.selectedUnmanagedInstance = unmanagedInstance | ||
| }, | ||
| handleSubmit (e) { | ||
| e.preventDefault() | ||
| this.form.validateFields((err, values) => { | ||
| if (err) { | ||
| return | ||
| } | ||
| this.loading = true | ||
| const params = { | ||
| clusterid: this.clusters[values.clusterid].id, | ||
| name: this.unmanagedInstances[values.instance].name | ||
| } | ||
| console.log(params) | ||
| this.$emit('refresh-data') | ||
| this.loading = false | ||
| this.closeAction() | ||
| }) | ||
| }, | ||
| 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> |
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.
show/guard/show only for VMware