storage: fix volume actions (#231)

Fixes #225

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Abhishek Kumar 2020-05-05 16:28:06 +05:30 committed by Rohit Yadav
parent 392d104be2
commit 64a1b22c33
2 changed files with 48 additions and 14 deletions

View File

@ -41,7 +41,8 @@ export default {
listView: true,
popup: true,
component: () => import('@/views/storage/CreateVolume.vue')
}, {
},
{
api: 'getUploadParamsForVolume',
icon: 'cloud-upload',
label: 'Upload Local Volume',
@ -67,14 +68,14 @@ export default {
label: 'Attach Volume',
args: ['virtualmachineid'],
dataView: true,
show: (record) => { return !('virtualmachineid' in record) }
show: (record) => { return record.type !== 'ROOT' && record.state !== 'Destroy' && !('virtualmachineid' in record) }
},
{
api: 'detachVolume',
icon: 'link',
label: 'Detach Volume',
dataView: true,
show: (record) => { return 'virtualmachineid' in record && record.virtualmachineid }
show: (record) => { return record.type !== 'ROOT' && 'virtualmachineid' in record && record.virtualmachineid }
},
{
api: 'createSnapshot',
@ -108,6 +109,7 @@ export default {
label: 'Resize Volume',
dataView: true,
popup: true,
show: (record) => { return record.state !== 'Destroy' },
component: () => import('@/views/storage/ResizeVolume.vue')
},
{
@ -116,7 +118,7 @@ export default {
label: 'Migrate Volume',
args: ['volumeid', 'storageid', 'livemigrate'],
dataView: true,
show: (record) => { return record && record.state === 'Ready' },
show: (record, store) => { return record && record.state === 'Ready' && ['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) },
popup: true,
component: () => import('@/views/storage/MigrateVolume.vue'),
mapping: {
@ -133,7 +135,7 @@ export default {
icon: 'cloud-download',
label: 'Download Volume',
dataView: true,
show: (record) => { return record && record.state === 'Ready' },
show: (record) => { return record && record.state === 'Ready' && (record.vmstate === 'Stopped' || record.virtualmachineid == null) && record.state !== 'Destroy' },
args: ['zoneid', 'mode'],
mapping: {
zoneid: {
@ -150,7 +152,7 @@ export default {
icon: 'picture',
label: 'Create Template from Volume',
dataView: true,
show: (record) => { return record.type === 'ROOT' },
show: (record) => { return (record.type === 'ROOT' && record.vmstate === 'Stopped') || (record.type !== 'ROOT' && !('virtualmachineid' in record) && !['Allocated', 'Uploaded', 'Destroy'].includes(record.state)) },
args: ['volumeid', 'name', 'displaytext', 'ostypeid', 'ispublic', 'isfeatured', 'isdynamicallyscalable', 'requireshvm', 'passwordenabled', 'sshkeyenabled'],
mapping: {
volumeid: {
@ -158,12 +160,37 @@ export default {
}
}
},
{
api: 'recoverVolume',
icon: 'medicine-box',
label: 'Recover Volume',
dataView: true,
show: (record, store) => {
return (['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) || store.features.allowuserexpungerecovervolume) && record.state === 'Destroy'
}
},
{
api: 'deleteVolume',
icon: 'delete',
label: 'Delete Volume',
dataView: true,
groupAction: true
groupAction: true,
show: (record, store) => {
return ['Expunging', 'Expunged', 'UploadError'].includes(record.state) ||
((['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) || store.features.allowuserexpungerecovervolume) && record.state === 'Destroy')
}
},
{
api: 'destroyVolume',
icon: 'delete',
label: 'Destroy Volume',
dataView: true,
args: (record, store) => {
return (!['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) && !store.features.allowuserexpungerecovervolumestore) ? [] : ['expunge']
},
show: (record, store) => {
return (!['Creating'].includes(record.state) && record.type !== 'ROOT' && !('virtualmachineid' in record) && record.state !== 'Destroy')
}
}
]
},
@ -206,7 +233,8 @@ export default {
api: 'revertSnapshot',
icon: 'sync',
label: 'Revert Snapshot',
dataView: true
dataView: true,
show: (record) => { return record.revertable }
},
{
api: 'deleteSnapshot',

View File

@ -556,12 +556,18 @@ export default {
return 0
})
this.currentAction.paramFields = []
if (action.args && action.args.length > 0) {
this.currentAction.paramFields = action.args.map(function (arg) {
return paramFields.filter(function (param) {
return param.name.toLowerCase() === arg.toLowerCase()
})[0]
})
if ('args' in action) {
var args = action.args
if (typeof action.args === 'function') {
args = action.args(action.resource, this.$store.getters)
}
if (args.length > 0) {
this.currentAction.paramFields = args.map(function (arg) {
return paramFields.filter(function (param) {
return param.name.toLowerCase() === arg.toLowerCase()
})[0]
})
}
}
this.showAction = true