From: Ricardo Marques Date: Fri, 19 Jul 2019 14:13:35 +0000 (+0100) Subject: mgr/dashboard: Prevent deletion of iSCSI IQNs with open sessions X-Git-Tag: v14.2.8~100^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e091a5632f321e2730309cd61638f2b215fd650b;p=ceph.git mgr/dashboard: Prevent deletion of iSCSI IQNs with open sessions Fixes: https://tracker.ceph.com/issues/38332 Signed-off-by: Ricardo Marques (cherry picked from commit 0d2e150e8c1ad24dc0d21345bac3660a0a4eb781) --- diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index ca0eebf7d99..f3146879b50 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -240,6 +240,11 @@ class IscsiTarget(RESTController): raise DashboardException(msg='Target does not exist', code='target_does_not_exist', component='iscsi') + target_info = IscsiClient.instance().get_targetinfo(target_iqn) + if target_info['num_sessions'] > 0: + raise DashboardException(msg='Target has active sessions', + code='target_has_active_sessions', + component='iscsi') IscsiTarget._delete(target_iqn, config, 0, 100) @iscsi_target_task('create', {'target_iqn': '{target_iqn}'}) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts index 8e0e3776d45..03d985f01aa 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts @@ -1,6 +1,7 @@ import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { I18n } from '@ngx-translate/i18n-polyfill'; +import * as _ from 'lodash'; import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; import { Subscription } from 'rxjs'; @@ -82,7 +83,9 @@ export class IscsiTargetListComponent implements OnInit, OnDestroy { permission: 'delete', icon: 'fa-times', click: () => this.deleteIscsiTargetModal(), - name: this.actionLabels.DELETE + name: this.actionLabels.DELETE, + disable: () => !this.selection.first() || !_.isUndefined(this.getDeleteDisableDesc()), + disableDesc: () => this.getDeleteDisableDesc() } ]; } @@ -147,6 +150,12 @@ export class IscsiTargetListComponent implements OnInit, OnDestroy { } } + getDeleteDisableDesc(): string | undefined { + if (this.selection.first() && this.selection.first()['info']['num_sessions']) { + return this.i18n('Target has active sessions'); + } + } + prepareResponse(resp: any): any[] { resp.forEach((element) => { element.cdPortals = element.portals.map((portal) => `${portal.host}:${portal.ip}`);