Skip to content

Commit

Permalink
Merge pull request #6372 from swordqiu/automated-cherry-pick-of-#6368…
Browse files Browse the repository at this point in the history
…-upstream-release-3.9

Automated cherry pick of #6368: fix: support associate host and backup storage
  • Loading branch information
easy-mj authored Apr 18, 2024
2 parents 9c2588a + fa0e66b commit ed64b29
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 8 deletions.
8 changes: 7 additions & 1 deletion containers/Compute/views/vminstance/dialogs/BackupCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ export default {
return new this.$Manager(this.isDiskBackup ? 'diskbackups' : 'instancebackups', 'v2')
},
storageParams () {
return {
const params = {
scope: this.scope,
project_domain: this.params.data[0].project_domain,
}
if (this.isDiskBackup) {
params.disk_id = this.selectDisk.id
} else {
params.server_id = this.params.data[0].id
}
return params
},
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<template>
<base-dialog @cancel="cancelDialog">
<div slot="header">{{this.params.title}}</div>
<div slot="body">
<dialog-selected-tips :name="$t('dictionary.blockstorage')" :count="params.data.length" :action="this.params.title" />
<dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
<a-form :form="form.fc" v-bind="formItemLayout">
<a-form-item :label="$t('storage.text_50')">
<a-select :loading="hostsLoading" allowClear showSearch :filterOption="filterOption" mode="multiple" v-decorator="decorators.host" :placeholder="$t('storage.text_51')">
<a-select-option v-for="item in hosts" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
</a-select>
</a-form-item>
</a-form>
</div>
<div slot="footer">
<a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
<a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
</div>
</base-dialog>
</template>

<script>
import DialogMixin from '@/mixins/dialog'
import WindowsMixin from '@/mixins/windows'
export default {
name: 'HostAttachBackupStorageDialog',
mixins: [DialogMixin, WindowsMixin],
data () {
return {
loading: false,
hostsLoading: false,
hosts: [],
form: {
fc: this.$form.createForm(this),
},
formItemLayout: {
labelCol: { span: 4 },
wrapperCol: { span: 20 },
},
}
},
computed: {
decorators () {
return {
host: [
'host',
{
rules: [
{ required: true, message: this.$t('storage.text_54') },
],
},
],
}
},
},
created () {
this.queryHostList()
},
methods: {
filterOption (input, option) {
return (
option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
},
async queryHostList () {
const params = { hypervisor: 'kvm', storage_not_attached: true, backupstorage: this.params.data[0].id }
const manager = new this.$Manager('hosts', 'v2')
this.hostsLoading = true
try {
const { data = {} } = await manager.list({ params })
this.hosts = data.data || []
} catch (err) {
throw err
} finally {
this.hostsLoading = false
}
},
async handleConfirm () {
this.loading = true
try {
const values = await this.form.fc.validateFields()
const manager = new this.$Manager('hosts', 'v2')
await manager.batchPerformAction({
ids: values.host,
action: '',
data: values,
ctx: [['backupstorages', this.params.data[0].id]],
})
this.cancelDialog()
this.params.refresh()
this.loading = false
} catch (error) {
this.loading = false
throw error
}
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- 宿主机列表-取消关联宿主机 -->
<template>
<base-dialog @cancel="cancelDialog">
<div slot="header">{{this.params.title}}</div>
<div slot="body">
<dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="$t('storage.text_50')" />
<dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
</div>
<div slot="footer">
<a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
<a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
</div>
</base-dialog>
</template>

<script>
import DialogMixin from '@/mixins/dialog'
import WindowsMixin from '@/mixins/windows'
export default {
name: 'HostDetachBackupStorageDialog',
mixins: [DialogMixin, WindowsMixin],
data () {
return {
loading: false,
}
},
methods: {
async handleConfirm () {
this.loading = true
try {
await this.params.list.onManager('batchDelete', {
id: this.params.data.map(({ id }) => id),
managerArgs: {
ctx: [['backupstorages', this.params.resId]],
},
})
// this.$bus.$emit('BlockStorageListSingleUpdate', [this.params.resId])
this.cancelDialog()
this.loading = false
} catch (error) {
this.loading = false
throw error
}
},
},
}
</script>
88 changes: 81 additions & 7 deletions containers/Storage/views/backup-storage/sidepage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,115 @@
<actions :options="singleActions" :row="detailData" button-type="link" button-size="small" />
</template>
<component
v-bind="hostListActions"
:is="params.windowData.currentTab"
:data="detailData"
:res-id="data.id"
:id="listId"
:on-manager="onManager"
:columns="columns" />
:refresh="refresh"
@refresh="refresh"
:list="params.list"
:getParams="getParams"
:columns="columns"
:res-id="data.id"
:id="listId" />
</base-side-page>
</template>

<script>
import SingleActionsMixin from '../mixins/singleActions'
import ColumnsMixin from '../mixins/columns'
import BackupStorageDetail from './Detail'
import HostList from '@Compute/views/host/components/List'
import Actions from '@/components/PageList/Actions'
import SidePageMixin from '@/mixins/sidePage'
import WindowsMixin from '@/mixins/windows'
import Actions from '@/components/PageList/Actions'
import BackupStorageDetail from './Detail'
import ColumnsMixin from '../mixins/columns'
import SingleActionsMixin from '../mixins/singleActions'
export default {
name: 'BackupStorageSidePage',
components: {
BackupStorageDetail,
Actions,
HostList,
},
mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
data () {
return {
detailTabs: [
{ label: this.$t('compute.text_238'), key: 'backup-storage-detail' },
{ label: this.$t('storage.text_50'), key: 'host-list' },
{ label: this.$t('compute.text_240'), key: 'event-drawer' },
],
}
},
computed: {
getParams () {
return {
backupstorage: this.data.id,
details: true,
}
},
hostListActions () {
const me = this
return {
// this = hostList
frontGroupActions: function () {
return [
{
label: this.$t('storage.text_66'),
permission: 'hostbackupstorages_create',
action: () => {
this.createDialog('HostAttachBackupStorageDialog', {
data: [me.detailData],
columns: me.columns,
title: this.$t('storage.text_66'),
onManager: this.onManager,
refresh: this.refresh,
})
},
},
{
label: this.$t('storage.text_90'),
permission: 'hostbackupstorages_delete',
action: () => {
this.createDialog('HostDetachBackupStorageDialog', {
title: this.$t('storage.text_90'),
data: this.list.selectedItems,
columns: this.columns,
list: this.list,
resId: me.getParams.backupstorage,
})
},
meta: () => {
return {
validate: this.list.selectedItems.length > 0,
}
},
},
]
},
frontSingleActions: function () {
return [
{
label: this.$t('storage.text_90'),
permission: 'hostbackupstorages_delete',
action: (row) => {
this.createDialog('HostDetachBackupStorageDialog', {
title: this.$t('storage.text_90'),
data: [row],
columns: this.columns,
list: this.list,
resId: me.getParams.backupstorage,
})
},
},
]
},
}
},
listId () {
switch (this.params.windowData.currentTab) {
case 'host-list':
return 'HostListForBlockStorageSidePage'
case 'event-drawer':
return 'EventListForBackupStorageSidePage'
default:
Expand Down

0 comments on commit ed64b29

Please sign in to comment.