# -*- coding: utf-8 -*-
+import logging
import os
from collections import defaultdict
'max_files': (int, '')
}
+logger = logging.getLogger("controllers.rgw")
+
@APIRouter('/cephfs', Scope.CEPHFS)
@APIDoc("Cephfs Management API", "Cephfs")
:rtype: str
"""
cfs = self._cephfs_instance(fs_id)
+ list_snaps = cfs.ls_snapshots(path)
+ for snap in list_snaps:
+ if name == snap['name']:
+ raise DashboardException(code='Snapshot name already in use',
+ msg='Snapshot name {} is already in use.'
+ 'Please use another name'.format(name),
+ component='cephfs')
+
return cfs.mk_snapshot(path, name)
@RESTController.Resource('DELETE', path='/snapshot')
import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
-import { Validators } from '@angular/forms';
+import { AbstractControl, Validators } from '@angular/forms';
import {
ITreeOptions,
updateSelection: Function;
};
nodes: any[];
+ alreadyExists: boolean;
constructor(
private authStorageService: AuthStorageService,
type: 'text',
name: 'name',
value: `${moment().toISOString(true)}`,
- required: true
+ required: true,
+ validators: [this.validateValue.bind(this)]
}
],
submitButtonText: $localize`Create Snapshot`,
onSubmit: (values: CephfsSnapshot) => {
- this.cephfsService.mkSnapshot(this.id, path, values.name).subscribe((name) => {
+ if (!this.alreadyExists) {
+ this.cephfsService.mkSnapshot(this.id, path, values.name).subscribe((name) => {
+ this.notificationService.show(
+ NotificationType.success,
+ $localize`Created snapshot '${name}' for '${path}'`
+ );
+ this.forceDirRefresh();
+ });
+ } else {
this.notificationService.show(
- NotificationType.success,
- $localize`Created snapshot '${name}' for '${path}'`
+ NotificationType.error,
+ $localize`Snapshot name '${values.name}' is already in use. Please use another name.`
);
- this.forceDirRefresh();
- });
+ }
}
});
}
+ validateValue(control: AbstractControl) {
+ this.alreadyExists = this.selectedDir.snapshots.some((s) => s.name === control.value);
+ }
+
/**
* Forces an update of the current selected directory
*