Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/config/section/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ export default {
listView: true,
component: () => import('@/views/compute/DeployVM.vue')
},
{
api: 'importUnmanagedInstance',
icon: 'down-square',
label: 'label.vm.import',
listView: true,
popup: true,
Copy link
Member

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

component: () => import('@/views/compute/ImportVM.vue')
},
{
api: 'updateVirtualMachine',
icon: 'edit',
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,7 @@
"label.vm.bootmode": "Boot Mode",
"label.vm.boottype": "Boot Type",
"label.vm.destroy": "Destroy",
"label.vm.import": "Import Instance",
"label.vm.password": "Password of the VM is",
"label.vm.reboot": "Reboot",
"label.vm.snapshots": "VM Snapshots",
Expand Down
215 changes: 215 additions & 0 deletions src/views/compute/ImportVM.vue
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>