1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

F #5422: Add option to delete images on template (#2005)

This commit is contained in:
Sergio Betanzos 2022-05-11 11:25:44 +02:00 committed by GitHub
parent 20456090e2
commit 2e63fc77f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 9 deletions

View File

@ -0,0 +1,24 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems *
* *
* Licensed 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. *
* ------------------------------------------------------------------------- */
import { createForm } from 'client/utils'
import {
SCHEMA,
FIELDS,
} from 'client/components/Forms/VmTemplate/DeleteForm/schema'
const DeleteForm = createForm(SCHEMA, FIELDS)
export default DeleteForm

View File

@ -0,0 +1,32 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems *
* *
* Licensed 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. *
* ------------------------------------------------------------------------- */
import { object, boolean } from 'yup'
import { T, INPUT_TYPES } from 'client/constants'
import { getValidationFromFields } from 'client/utils'
const DELETE_IMAGE = {
name: 'image',
label: T.DeleteAllImages,
type: INPUT_TYPES.SWITCH,
tooltip: T.DeleteAllImagesConcept,
validation: boolean()
.notRequired()
.default(() => false),
}
export const FIELDS = [DELETE_IMAGE]
export const SCHEMA = object(getValidationFromFields(FIELDS))

View File

@ -31,6 +31,13 @@ const CloneForm = (configProps) =>
const CreateForm = (configProps) =>
AsyncLoadForm({ formPath: 'VmTemplate/CreateForm' }, configProps)
/**
* @param {ConfigurationProps} configProps - Configuration
* @returns {ReactElement|CreateStepsCallback} Asynchronous loaded form
*/
const DeleteForm = (configProps) =>
AsyncLoadForm({ formPath: 'VmTemplate/DeleteForm' }, configProps)
/**
* @param {ConfigurationProps} configProps - Configuration
* @returns {ReactElement|CreateStepsCallback} Asynchronous loaded form
@ -38,4 +45,4 @@ const CreateForm = (configProps) =>
const InstantiateForm = (configProps) =>
AsyncLoadForm({ formPath: 'VmTemplate/InstantiateForm' }, configProps)
export { CloneForm, CreateForm, InstantiateForm }
export { CloneForm, CreateForm, DeleteForm, InstantiateForm }

View File

@ -37,7 +37,7 @@ import {
} from 'client/features/OneApi/vmTemplate'
import { ChangeUserForm, ChangeGroupForm } from 'client/components/Forms/Vm'
import { CloneForm } from 'client/components/Forms/VmTemplate'
import { CloneForm, DeleteForm } from 'client/components/Forms/VmTemplate'
import {
createActions,
GlobalAction,
@ -318,14 +318,26 @@ const Actions = () => {
color: 'error',
options: [
{
isConfirmDialog: true,
dialogProps: {
title: T.Delete,
children: MessageToConfirmAction,
title: (rows) => {
const isMultiple = rows?.length > 1
const { ID, NAME } = rows?.[0]?.original ?? {}
return [
Tr(
isMultiple ? T.DeleteSeveralTemplates : T.DeleteTemplate
),
!isMultiple && `#${ID} ${NAME}`,
]
.filter(Boolean)
.join(' - ')
},
},
onSubmit: (rows) => async () => {
form: DeleteForm,
onSubmit: (rows) => async (formData) => {
const { image } = formData ?? {}
const ids = rows?.map?.(({ original }) => original?.ID)
await Promise.all(ids.map((id) => remove({ id })))
await Promise.all(ids.map((id) => remove({ id, image })))
},
},
],

View File

@ -63,7 +63,10 @@ module.exports = {
Delete: 'Delete',
DeleteDb: 'Delete database',
DeleteScheduleAction: 'Delete schedule action: %s',
DeleteSeveralTemplates: 'Delete several Templates',
DeleteTemplate: 'Delete Template',
DeleteSomething: 'Delete: %s',
DeleteAllImages: 'Delete all images',
Deploy: 'Deploy',
Detach: 'Detach',
DetachSomething: 'Detach: %s',
@ -733,6 +736,8 @@ module.exports = {
Number of virtual CPUs. This value is optional, the default
hypervisor behavior is used, usually one virtual CPU`,
/* VM Template schema - actions */
DeleteAllImagesConcept:
'Enable to delete the template plus any image defined in DISK',
CopyOf: 'Copy of ',
PrefixMultipleConcept:
'Several templates are selected, please choose prefix to name the new copies',

View File

@ -33,7 +33,7 @@ import {
import { LockLevel, FilterFlag, Permission, VmTemplate } from 'client/constants'
const { TEMPLATE } = ONE_RESOURCES
const { TEMPLATE_POOL, VM_POOL } = ONE_RESOURCES_POOL
const { TEMPLATE_POOL, VM_POOL, IMAGE_POOL } = ONE_RESOURCES_POOL
const vmTemplateApi = oneApi.injectEndpoints({
endpoints: (builder) => ({
@ -163,7 +163,11 @@ const vmTemplateApi = oneApi.injectEndpoints({
return { params, command }
},
invalidatesTags: [TEMPLATE_POOL],
invalidatesTags: (_, __, { id, image }) => [
TEMPLATE_POOL,
{ type: TEMPLATE, id },
...(image ? [IMAGE_POOL] : []),
],
}),
instantiateTemplate: builder.mutation({
/**