Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
feat(vm-snapshot): manage maximum VM snapshots amount in config.json (#…
Browse files Browse the repository at this point in the history
…1523)

PR close #1415
  • Loading branch information
HeyRoach committed Jan 28, 2019
1 parent f0a5745 commit 0ba17bf
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 2 deletions.
15 changes: 15 additions & 0 deletions config-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/config/default-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const customizableProperties: Readonly<CustomizableConfig> = {
serviceOfferingAvailability: {
filterOfferings: false,
},
vmSnapLimit: {
enable: false,
snapshotsLimit: 0,
},
};

export const nonCustomizableProperties: Readonly<NonCustomizableConfig> = {
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/config/validation-schemes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,6 +38,7 @@ export {
resourceLimits,
// Virtual machines settings
vmColors,
vmSnapLimit,
// User app settings
defaultFirstDayOfWeek,
defaultInterfaceLanguage,
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/config/validation-schemes/vm-snap-limit.scheme.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -75,8 +76,20 @@ export class VmSnapshotsEffects {
@Effect()
createVmSnapshotDialog$: Observable<Action> = this.actions$.pipe(
ofType<Create>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const getVmSnapshotsForSelectedVm = createSelector(
(vmSnapshots, selectedVmId) =>
vmSnapshots.filter(snapshot => snapshot.virtualmachineid === selectedVmId),
);

export const getVmSnapshotsNumberForSelectedVm = createSelector(
getVmSnapshotsForSelectedVm,
snapshots => snapshots.length,
);
1 change: 1 addition & 0 deletions src/app/shared/models/config/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface CustomizableConfig {
* Virtual machines settings
*/
vmColors: { value: string }[];
vmSnapLimit: { enable: boolean; snapshotsLimit: number };
/*
* Firewall (Security groups) settings
*/
Expand Down
4 changes: 4 additions & 0 deletions src/config/config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{ "value": "#673AB7" },
{ "value": "#3F51B5" }
],
"vmSnapLimit": {
"enable": false,
"snapshotsLimit": 0
},
"securityGroupTemplates": [
{
"id": "templateTCP",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
"ISO": {
"VMS_IN_USE": "Unable to delete the ISO as it's used by the following VMs:<br>{{ 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",
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
"ISO": {
"VMS_IN_USE": "Невозможно удалить ISO файл, так как он используется следующими машинами:<br>{{ vms }}"
},
"VM_SNAPSHOT": {
"LIMIT_EXCEEDED": "Максимальное количество снимков ВМ превышено. Проверьте конфигурации"
},
"SNAPSHOT": {
"LIMIT_EXCEEDED": "Лимит снимков превышен. Для создания новых снимков Вам необходимо удалить какие-либо из ранее созданных снимков.",
"CREATION_UNAVAILABLE_FOR_STOPPED": "Создание снимков ВМ недоступно для остановленных ВМ",
Expand Down

0 comments on commit 0ba17bf

Please sign in to comment.