]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
a85fb75861177a617f2415ac0642ae2bf70772ff
[ceph-ci.git] /
1 import { Component, DestroyRef, OnInit, ViewChild } from '@angular/core';
2 import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4
5 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
6 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
7 import { ActivatedRoute, Router } from '@angular/router';
8 import { Step } from 'carbon-components-angular';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
11 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
12 import { TearsheetComponent } from '~/app/shared/components/tearsheet/tearsheet.component';
13
14 export type SubsystemPayload = {
15   nqn: string;
16   gw_group: string;
17   subsystemDchapKey: string;
18 };
19
20 @Component({
21   selector: 'cd-nvmeof-subsystems-form',
22   templateUrl: './nvmeof-subsystems-form.component.html',
23   styleUrls: ['./nvmeof-subsystems-form.component.scss'],
24   standalone: false
25 })
26 export class NvmeofSubsystemsFormComponent implements OnInit {
27   subsystemForm: CdFormGroup;
28   action: string;
29   group: string;
30   steps: Step[] = [
31     {
32       label: $localize`Subsystem details`,
33       complete: false,
34       invalid: false
35     },
36     {
37       label: $localize`Host access control`,
38       invalid: false
39     },
40     {
41       label: $localize`Authentication`,
42       invalid: false
43     },
44     {
45       label: $localize`Advanced options`,
46       complete: false,
47       secondaryLabel: $localize`Advanced`
48     }
49   ];
50   title: string = $localize`Create Subsystem`;
51   description: string = $localize`Subsytems define how hosts connect to NVMe namespaces and ensure secure access to storage.`;
52   isSubmitLoading: boolean = false;
53
54   @ViewChild(TearsheetComponent) tearsheet!: TearsheetComponent;
55
56   constructor(
57     public actionLabels: ActionLabelsI18n,
58     public activeModal: NgbActiveModal,
59     private route: ActivatedRoute,
60     private destroyRef: DestroyRef,
61     private nvmeofService: NvmeofService,
62     private taskWrapperService: TaskWrapperService,
63     private router: Router
64   ) {}
65
66   ngOnInit() {
67     this.route.queryParams.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
68       this.group = params?.['group'];
69     });
70   }
71
72   onSubmit(payload: SubsystemPayload) {
73     const component = this;
74     const pageURL = 'block/nvmeof/subsystems';
75     let taskUrl = `nvmeof/subsystem/${URLVerbs.CREATE}`;
76     this.isSubmitLoading = true;
77     this.taskWrapperService
78       .wrapTaskAroundCall({
79         task: new FinishedTask(taskUrl, {
80           nqn: payload.nqn
81         }),
82         call: this.nvmeofService.createSubsystem({
83           nqn: payload.nqn,
84           gw_group: this.group,
85           dhchap_key: payload.subsystemDchapKey,
86           enable_ha: true
87         })
88       })
89       .subscribe({
90         error() {
91           component.isSubmitLoading = false;
92         },
93         complete: () => {
94           component.isSubmitLoading = false;
95           this.router.navigate([pageURL, { outlets: { modal: null } }]);
96         }
97       });
98   }
99 }