From 0ba17bf3044145378c58eb33c859f003e6a90f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=80=D0=B8=D1=81=D1=82=D0=B8=D0=BD=D0=B0=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D1=89=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 28 Jan 2019 08:35:22 +0700 Subject: [PATCH] feat(vm-snapshot): manage maximum VM snapshots amount in config.json (#1523) PR close #1415 --- config-guide.md | 15 +++++++++++++++ src/app/core/config/default-configuration.ts | 4 ++++ src/app/core/config/validation-schemes/index.ts | 2 ++ .../vm-snap-limit.scheme.json | 16 ++++++++++++++++ .../vm-snapshots/vm-snapshots.effects.ts | 17 +++++++++++++++-- .../vm-snapshots/vm-snapshots.selectors.ts | 5 +++++ .../shared/models/config/config.interface.ts | 1 + src/config/config-example.json | 4 ++++ src/i18n/en.json | 3 +++ src/i18n/ru.json | 3 +++ 10 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/app/core/config/validation-schemes/vm-snap-limit.scheme.json diff --git a/config-guide.md b/config-guide.md index 80b1a63d12..52fba60eae 100644 --- a/config-guide.md +++ b/config-guide.md @@ -11,6 +11,7 @@ You can see examples of the configurations in the [config-example.json](https:// - [Resource Limits Plugin](#resource-limits-plugin) - [Virtual Machines Settings](#virtual-machines-settings) - [VM Colors](#vm-colors) + - [VM Snapshots Limit](#vm-snapshots-limit) - [Firewall (Security Groups) Settings](#firewall-security-groups-settings) - [Security Group Templates](#security-group-templates) - [Default Security Group Name](#default-security-group-name) @@ -141,6 +142,20 @@ For example, ] ``` +### VM Snapshots Limit + +Allows you to set the maximum number of VM snapshots. You can enable feature like this``` "enable": true ```. By default, this feature is disabled. The minimum value for snapshots limit is 0. + +For example, + +``` +"vmSnapLimit": { + "enable": false, + "snapshotsLimit": 0 +} + +``` + ## Firewall (Security Groups) Settings ### Security Group Templates diff --git a/src/app/core/config/default-configuration.ts b/src/app/core/config/default-configuration.ts index dda6267206..af66fa9bf9 100644 --- a/src/app/core/config/default-configuration.ts +++ b/src/app/core/config/default-configuration.ts @@ -88,6 +88,10 @@ export const customizableProperties: Readonly = { serviceOfferingAvailability: { filterOfferings: false, }, + vmSnapLimit: { + enable: false, + snapshotsLimit: 0, + }, }; export const nonCustomizableProperties: Readonly = { diff --git a/src/app/core/config/validation-schemes/index.ts b/src/app/core/config/validation-schemes/index.ts index 348f988fec..b4a6231a6b 100644 --- a/src/app/core/config/validation-schemes/index.ts +++ b/src/app/core/config/validation-schemes/index.ts @@ -23,6 +23,7 @@ import * as securityGroupTemplates from './security-group-templates.scheme.json' import * as imageGroups from './image-groups.scheme.json'; import * as defaultSecurityGroupName from './default-security-group-name.scheme.json'; +import * as vmSnapLimit from './vm-snap-limit.scheme.json'; import * as autoGenerateUserKeys from './auto-generate-user-keys.scheme.json'; export { @@ -37,6 +38,7 @@ export { resourceLimits, // Virtual machines settings vmColors, + vmSnapLimit, // User app settings defaultFirstDayOfWeek, defaultInterfaceLanguage, diff --git a/src/app/core/config/validation-schemes/vm-snap-limit.scheme.json b/src/app/core/config/validation-schemes/vm-snap-limit.scheme.json new file mode 100644 index 0000000000..2d614836a6 --- /dev/null +++ b/src/app/core/config/validation-schemes/vm-snap-limit.scheme.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "vmSnapLimit", + "type": "object", + "additionalProperties": false, + "required": ["enable", "snapshotsLimit"], + "properties": { + "enable": { + "type": "boolean" + }, + "snapshotsLimit": { + "type": "number", + "minimum": 0 + } + } +} diff --git a/src/app/root-store/server-data/vm-snapshots/vm-snapshots.effects.ts b/src/app/root-store/server-data/vm-snapshots/vm-snapshots.effects.ts index c05fbd1c2b..d225b6a7ac 100644 --- a/src/app/root-store/server-data/vm-snapshots/vm-snapshots.effects.ts +++ b/src/app/root-store/server-data/vm-snapshots/vm-snapshots.effects.ts @@ -58,6 +58,7 @@ import { } from './vm-snapshots.actions'; import * as vmSnapshotSelectors from './vm-snapshots.selectors'; import { VmState } from '../../../vm'; +import { configSelectors } from '../../config'; @Injectable() export class VmSnapshotsEffects { @@ -75,8 +76,20 @@ export class VmSnapshotsEffects { @Effect() createVmSnapshotDialog$: Observable = this.actions$.pipe( ofType(VmSnapshotActionTypes.Create), - withLatestFrom(this.store.pipe(select(fromVM.getSelectedVM))), - exhaustMap(([action, selectedVM]) => { + withLatestFrom( + this.store.pipe(select(fromVM.getSelectedVM)), + this.store.pipe(select(configSelectors.get('vmSnapLimit'))), + this.store.pipe(select(vmSnapshotSelectors.getVmSnapshotsNumberForSelectedVm)), + ), + exhaustMap(([action, selectedVM, vmSnapLimit, snapshotsNumber]) => { + if (vmSnapLimit.enable) { + if (vmSnapLimit.snapshotsLimit <= snapshotsNumber) { + const message = 'ERRORS.VM_SNAPSHOT.LIMIT_EXCEEDED'; + this.dialogService.showNotificationsOnFail({ message }, message); + return of(new CreateCanceled()); + } + } + if (selectedVM.state === VmState.Stopped) { const message = 'ERRORS.SNAPSHOT.CREATION_UNAVAILABLE_FOR_STOPPED'; this.dialogService.showNotificationsOnFail({ message }, message); diff --git a/src/app/root-store/server-data/vm-snapshots/vm-snapshots.selectors.ts b/src/app/root-store/server-data/vm-snapshots/vm-snapshots.selectors.ts index f2baa856da..c57bbf9244 100644 --- a/src/app/root-store/server-data/vm-snapshots/vm-snapshots.selectors.ts +++ b/src/app/root-store/server-data/vm-snapshots/vm-snapshots.selectors.ts @@ -20,3 +20,8 @@ export const getVmSnapshotsForSelectedVm = createSelector( (vmSnapshots, selectedVmId) => vmSnapshots.filter(snapshot => snapshot.virtualmachineid === selectedVmId), ); + +export const getVmSnapshotsNumberForSelectedVm = createSelector( + getVmSnapshotsForSelectedVm, + snapshots => snapshots.length, +); diff --git a/src/app/shared/models/config/config.interface.ts b/src/app/shared/models/config/config.interface.ts index b0c05c2afe..3151a60a93 100644 --- a/src/app/shared/models/config/config.interface.ts +++ b/src/app/shared/models/config/config.interface.ts @@ -38,6 +38,7 @@ export interface CustomizableConfig { * Virtual machines settings */ vmColors: { value: string }[]; + vmSnapLimit: { enable: boolean; snapshotsLimit: number }; /* * Firewall (Security groups) settings */ diff --git a/src/config/config-example.json b/src/config/config-example.json index b09d0902cf..7053659ec1 100644 --- a/src/config/config-example.json +++ b/src/config/config-example.json @@ -23,6 +23,10 @@ { "value": "#673AB7" }, { "value": "#3F51B5" } ], + "vmSnapLimit": { + "enable": false, + "snapshotsLimit": 0 + }, "securityGroupTemplates": [ { "id": "templateTCP", diff --git a/src/i18n/en.json b/src/i18n/en.json index 2d5ac774cc..c9964ac6ef 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -108,6 +108,9 @@ "ISO": { "VMS_IN_USE": "Unable to delete the ISO as it's used by the following VMs:
{{ vms }}" }, + "VM_SNAPSHOT": { + "LIMIT_EXCEEDED": "The maximum amount of VM snapshots is exceeded. Please check your configurations" + }, "SNAPSHOT": { "LIMIT_EXCEEDED": "Snapshot limit has been exceeded. You need to delete some of your previous snapshots first.", "CREATION_UNAVAILABLE_FOR_STOPPED": "VM snapshot creation is unavailable for stopped VMs", diff --git a/src/i18n/ru.json b/src/i18n/ru.json index 178d186224..c57b33baed 100644 --- a/src/i18n/ru.json +++ b/src/i18n/ru.json @@ -108,6 +108,9 @@ "ISO": { "VMS_IN_USE": "Невозможно удалить ISO файл, так как он используется следующими машинами:
{{ vms }}" }, + "VM_SNAPSHOT": { + "LIMIT_EXCEEDED": "Максимальное количество снимков ВМ превышено. Проверьте конфигурации" + }, "SNAPSHOT": { "LIMIT_EXCEEDED": "Лимит снимков превышен. Для создания новых снимков Вам необходимо удалить какие-либо из ранее созданных снимков.", "CREATION_UNAVAILABLE_FOR_STOPPED": "Создание снимков ВМ недоступно для остановленных ВМ",