1 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
5 import { Subscription } from 'rxjs';
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
9 import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
10 import { TableComponent } from '../../../shared/datatable/table/table.component';
11 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
12 import { Icons } from '../../../shared/enum/icons.enum';
13 import { CdTableAction } from '../../../shared/models/cd-table-action';
14 import { CdTableColumn } from '../../../shared/models/cd-table-column';
15 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
16 import { FinishedTask } from '../../../shared/models/finished-task';
17 import { Permissions } from '../../../shared/models/permissions';
18 import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
19 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
20 import { SummaryService } from '../../../shared/services/summary.service';
21 import { TaskListService } from '../../../shared/services/task-list.service';
22 import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
23 import { IscsiTargetDiscoveryModalComponent } from '../iscsi-target-discovery-modal/iscsi-target-discovery-modal.component';
26 selector: 'cd-iscsi-target-list',
27 templateUrl: './iscsi-target-list.component.html',
28 styleUrls: ['./iscsi-target-list.component.scss'],
29 providers: [TaskListService]
31 export class IscsiTargetListComponent implements OnInit, OnDestroy {
32 @ViewChild(TableComponent)
33 table: TableComponent;
35 available: boolean = undefined;
36 columns: CdTableColumn[];
39 permissions: Permissions;
40 selection = new CdTableSelection();
43 summaryDataSubscription: Subscription;
44 tableActions: CdTableAction[];
49 'iscsi/target/create': (metadata) => {
51 target_iqn: metadata['target_iqn']
57 private authStorageService: AuthStorageService,
59 private iscsiService: IscsiService,
60 private taskListService: TaskListService,
61 private cephReleaseNamePipe: CephReleaseNamePipe,
62 private summaryservice: SummaryService,
63 private modalService: BsModalService,
64 private taskWrapper: TaskWrapperService,
65 public actionLabels: ActionLabelsI18n
67 this.permissions = this.authStorageService.getPermissions();
73 routerLink: () => '/block/iscsi/targets/create',
74 name: this.actionLabels.CREATE
79 routerLink: () => `/block/iscsi/targets/edit/${this.selection.first().target_iqn}`,
80 name: this.actionLabels.EDIT
85 click: () => this.deleteIscsiTargetModal(),
86 name: this.actionLabels.DELETE
94 name: this.i18n('Target'),
97 cellTransformation: CellTemplate.executing
100 name: this.i18n('Portals'),
105 name: this.i18n('Images'),
110 name: this.i18n('# Sessions'),
111 prop: 'info.num_sessions',
116 this.iscsiService.status().subscribe((result: any) => {
117 this.available = result.available;
119 if (result.available) {
120 this.taskListService.init(
121 () => this.iscsiService.listTargets(),
122 (resp) => this.prepareResponse(resp),
123 (targets) => (this.targets = targets),
124 () => this.onFetchError(),
130 this.iscsiService.settings().subscribe((settings: any) => {
131 this.settings = settings;
134 const summary = this.summaryservice.getCurrentSummary();
135 const releaseName = this.cephReleaseNamePipe.transform(summary.version);
136 this.docsUrl = `http://docs.ceph.com/docs/${releaseName}/mgr/dashboard/#enabling-iscsi-management`;
137 this.status = result.message;
143 if (this.summaryDataSubscription) {
144 this.summaryDataSubscription.unsubscribe();
148 prepareResponse(resp: any): any[] {
149 resp.forEach((element) => {
150 element.cdPortals = element.portals.map((portal) => `${portal.host}:${portal.ip}`);
151 element.cdImages = element.disks.map((disk) => `${disk.pool}/${disk.image}`);
158 this.table.reset(); // Disable loading indicator.
161 itemFilter(entry, task) {
162 return entry.target_iqn === task.metadata['target_iqn'];
166 return ['iscsi/target/create', 'iscsi/target/edit', 'iscsi/target/delete'].includes(task.name);
169 updateSelection(selection: CdTableSelection) {
170 this.selection = selection;
173 deleteIscsiTargetModal() {
174 const target_iqn = this.selection.first().target_iqn;
176 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
178 itemDescription: this.i18n('iSCSI'),
179 submitActionObservable: () =>
180 this.taskWrapper.wrapTaskAroundCall({
181 task: new FinishedTask('iscsi/target/delete', {
182 target_iqn: target_iqn
184 call: this.iscsiService.deleteTarget(target_iqn)
190 configureDiscoveryAuth() {
191 this.modalService.show(IscsiTargetDiscoveryModalComponent, {});