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 { TableComponent } from '../../../shared/datatable/table/table.component';
10 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
11 import { CdTableAction } from '../../../shared/models/cd-table-action';
12 import { CdTableColumn } from '../../../shared/models/cd-table-column';
13 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
14 import { FinishedTask } from '../../../shared/models/finished-task';
15 import { Permissions } from '../../../shared/models/permissions';
16 import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
17 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
18 import { SummaryService } from '../../../shared/services/summary.service';
19 import { TaskListService } from '../../../shared/services/task-list.service';
20 import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
21 import { IscsiTargetDiscoveryModalComponent } from '../iscsi-target-discovery-modal/iscsi-target-discovery-modal.component';
24 selector: 'cd-iscsi-target-list',
25 templateUrl: './iscsi-target-list.component.html',
26 styleUrls: ['./iscsi-target-list.component.scss'],
27 providers: [TaskListService]
29 export class IscsiTargetListComponent implements OnInit, OnDestroy {
30 @ViewChild(TableComponent)
31 table: TableComponent;
33 available: boolean = undefined;
34 columns: CdTableColumn[];
37 permissions: Permissions;
38 selection = new CdTableSelection();
41 summaryDataSubscription: Subscription;
42 tableActions: CdTableAction[];
46 'iscsi/target/create': (metadata) => {
48 target_iqn: metadata['target_iqn']
54 private authStorageService: AuthStorageService,
56 private iscsiService: IscsiService,
57 private taskListService: TaskListService,
58 private cephReleaseNamePipe: CephReleaseNamePipe,
59 private summaryservice: SummaryService,
60 private modalService: BsModalService,
61 private taskWrapper: TaskWrapperService
63 this.permissions = this.authStorageService.getPermissions();
69 routerLink: () => '/block/iscsi/targets/add',
70 name: this.i18n('Add')
75 click: () => this.deleteIscsiTargetModal(),
76 name: this.i18n('Delete')
84 name: this.i18n('Target'),
87 cellTransformation: CellTemplate.executing
90 name: this.i18n('Portals'),
95 name: this.i18n('Images'),
101 this.iscsiService.status().subscribe((result: any) => {
102 this.available = result.available;
104 if (result.available) {
105 this.taskListService.init(
106 () => this.iscsiService.listTargets(),
107 (resp) => this.prepareResponse(resp),
108 (targets) => (this.targets = targets),
109 () => this.onFetchError(),
115 this.iscsiService.settings().subscribe((settings: any) => {
116 this.settings = settings;
119 const summary = this.summaryservice.getCurrentSummary();
120 const releaseName = this.cephReleaseNamePipe.transform(summary.version);
121 this.docsUrl = `http://docs.ceph.com/docs/${releaseName}/mgr/dashboard/#enabling-iscsi-management`;
122 this.status = result.message;
128 if (this.summaryDataSubscription) {
129 this.summaryDataSubscription.unsubscribe();
133 prepareResponse(resp: any): any[] {
134 resp.forEach((element) => {
135 element.cdPortals = element.portals.map((portal) => `${portal.host}:${portal.ip}`);
136 element.cdImages = element.disks.map((disk) => `${disk.pool}/${disk.image}`);
143 this.table.reset(); // Disable loading indicator.
146 itemFilter(entry, task) {
147 return entry.target_iqn === task.metadata['target_iqn'];
151 return ['iscsi/target/create', 'iscsi/target/delete'].includes(task.name);
154 updateSelection(selection: CdTableSelection) {
155 this.selection = selection;
158 deleteIscsiTargetModal() {
159 const target_iqn = this.selection.first().target_iqn;
161 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
163 itemDescription: this.i18n('iSCSI'),
164 submitActionObservable: () =>
165 this.taskWrapper.wrapTaskAroundCall({
166 task: new FinishedTask('iscsi/target/delete', {
167 target_iqn: target_iqn
169 call: this.iscsiService.deleteTarget(target_iqn)
175 configureDiscoveryAuth() {
176 this.modalService.show(IscsiTargetDiscoveryModalComponent, {});