@raise_if_no_orchestrator
@handle_orchestrator_error('osd')
@osd_task('delete', {'svc_id': '{svc_id}'})
- def delete(self, svc_id, force=None):
+ def delete(self, svc_id, preserve_id=None, force=None):
+ replace = False
+ check = False
+ try:
+ if preserve_id is not None:
+ replace = str_to_bool(preserve_id)
+ if force is not None:
+ check = not str_to_bool(force)
+ except ValueError:
+ raise DashboardException(
+ component='osd', http_status_code=400, msg='Invalid parameter(s)')
+
orch = OrchClient.instance()
- if not force:
+ if check:
logger.info('Check for removing osd.%s...', svc_id)
check = self._check_delete([svc_id])
if not check['safe']:
logger.error('Unable to remove osd.%s: %s', svc_id, check['message'])
raise DashboardException(component='osd', msg=check['message'])
- logger.info('Start removing osd.%s...', svc_id)
- orch.osds.remove([svc_id])
+
+ logger.info('Start removing osd.%s (replace: %s)...', svc_id, replace)
+ orch.osds.remove([svc_id], replace)
while True:
removal_osds = orch.osds.removing_status()
logger.info('Current removing OSDs %s', removal_osds)
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
+import { FormControl } from '@angular/forms';
import { Router } from '@angular/router';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
import { Icons } from '../../../../shared/enum/icons.enum';
import { NotificationType } from '../../../../shared/enum/notification-type.enum';
+import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
import { CdTableAction } from '../../../../shared/models/cd-table-action';
import { CdTableColumn } from '../../../../shared/models/cd-table-column';
import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
reweightBodyTpl: TemplateRef<any>;
@ViewChild('safeToDestroyBodyTpl')
safeToDestroyBodyTpl: TemplateRef<any>;
+ @ViewChild('deleteOsdExtraTpl')
+ deleteOsdExtraTpl: TemplateRef<any>;
permissions: Permissions;
tableActions: CdTableAction[];
{
name: this.actionLabels.DELETE,
permission: 'delete',
- click: () => {
- this.depCheckerService.checkOrchestratorOrModal(
- this.actionLabels.DELETE,
- this.i18n('OSD'),
- () => {
- this.showCriticalConfirmationModal(
- this.i18n('delete'),
- this.i18n('OSD'),
- this.i18n('deleted'),
- (ids: number[]) => {
- return this.osdService.safeToDelete(JSON.stringify(ids));
- },
- 'is_safe_to_delete',
- (id: number) => {
- this.selection = new CdTableSelection();
- return this.taskWrapper.wrapTaskAroundCall({
- task: new FinishedTask('osd/' + URLVerbs.DELETE, {
- svc_id: id
- }),
- call: this.osdService.delete(id, true)
- });
- },
- true
- );
- }
- );
- },
+ click: () => this.delete(),
disable: () => !this.hasOsdSelected,
icon: Icons.destroy
}
});
}
+ delete() {
+ const deleteFormGroup = new CdFormGroup({
+ preserve: new FormControl(false)
+ });
+
+ this.depCheckerService.checkOrchestratorOrModal(
+ this.actionLabels.DELETE,
+ this.i18n('OSD'),
+ () => {
+ this.showCriticalConfirmationModal(
+ this.i18n('delete'),
+ this.i18n('OSD'),
+ this.i18n('deleted'),
+ (ids: number[]) => {
+ return this.osdService.safeToDelete(JSON.stringify(ids));
+ },
+ 'is_safe_to_delete',
+ (id: number) => {
+ this.selection = new CdTableSelection();
+ return this.taskWrapper.wrapTaskAroundCall({
+ task: new FinishedTask('osd/' + URLVerbs.DELETE, {
+ svc_id: id
+ }),
+ call: this.osdService.delete(id, deleteFormGroup.value.preserve, true)
+ });
+ },
+ true,
+ deleteFormGroup,
+ this.deleteOsdExtraTpl
+ );
+ }
+ );
+ }
+
/**
* Perform check first and display a critical confirmation modal.
* @param {string} actionDescription name of the action.
* @param {Function} check the function is called to check if the action is safe.
* @param {string} checkKey the safe indicator's key in the check response.
* @param {Function} action the action function.
- * @param {boolean} oneshot if true, action function is called with all items as parameter.
- * Otherwise, multiple action functions with individual items are sent.
+ * @param {boolean} taskWrapped if true, hide confirmation modal after action
+ * @param {CdFormGroup} childFormGroup additional child form group to be passed to confirmation modal
+ * @param {TemplateRef<any>} childFormGroupTemplate template for additional child form group
*/
showCriticalConfirmationModal(
actionDescription: string,
check: (ids: number[]) => Observable<any>,
checkKey: string,
action: (id: number | number[]) => Observable<any>,
- taskWrapped: boolean = false
+ taskWrapped: boolean = false,
+ childFormGroup?: CdFormGroup,
+ childFormGroupTemplate?: TemplateRef<any>
): void {
check(this.getSelectedOsdIds()).subscribe((result) => {
const modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
message: result.message,
actionDescription: templateItemDescription
},
+ childFormGroup: childFormGroup,
+ childFormGroupTemplate: childFormGroupTemplate,
submitAction: () => {
const observable = observableForkJoin(
this.getSelectedOsdIds().map((osd: any) => action.call(this.osdService, osd))
-import { HttpClient, HttpParams } from '@angular/common/http';
+import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { I18n } from '@ngx-translate/i18n-polyfill';
return this.http.post(`${this.path}/${id}/destroy`, null);
}
- delete(id: number, force?: boolean) {
- const options = force ? { params: new HttpParams().set('force', 'true') } : {};
- options['observe'] = 'response';
- return this.http.delete(`${this.path}/${id}`, options);
+ delete(id: number, preserveId?: boolean, force?: boolean) {
+ const params = {
+ preserve_id: preserveId ? 'true' : 'false',
+ force: force ? 'true' : 'false'
+ };
+ return this.http.delete(`${this.path}/${id}`, { observe: 'response', params: params });
}
safeToDestroy(ids: string) {