]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/orchestrator.service.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / orchestrator.service.ts
CommitLineData
f67539c2 1import { HttpClient } from '@angular/common/http';
9f95a23c
TL
2import { Injectable } from '@angular/core';
3
f67539c2
TL
4import _ from 'lodash';
5import { Observable } from 'rxjs';
9f95a23c 6
f67539c2
TL
7import { OrchestratorFeature } from '../models/orchestrator.enum';
8import { OrchestratorStatus } from '../models/orchestrator.interface';
9f95a23c
TL
9
10@Injectable({
f67539c2 11 providedIn: 'root'
9f95a23c
TL
12})
13export class OrchestratorService {
2a845540 14 private url = 'ui-api/orchestrator';
9f95a23c 15
f67539c2
TL
16 disableMessages = {
17 noOrchestrator: $localize`The feature is disabled because Orchestrator is not available.`,
18 missingFeature: $localize`The Orchestrator backend doesn't support this feature.`
19 };
9f95a23c 20
f67539c2 21 constructor(private http: HttpClient) {}
9f95a23c 22
f67539c2
TL
23 status(): Observable<OrchestratorStatus> {
24 return this.http.get<OrchestratorStatus>(`${this.url}/status`);
9f95a23c
TL
25 }
26
f67539c2
TL
27 hasFeature(status: OrchestratorStatus, features: OrchestratorFeature[]): boolean {
28 return _.every(features, (feature) => _.get(status.features, `${feature}.available`));
9f95a23c
TL
29 }
30
f67539c2
TL
31 getTableActionDisableDesc(
32 status: OrchestratorStatus,
33 features: OrchestratorFeature[]
34 ): boolean | string {
35 if (!status) {
36 return false;
37 }
38 if (!status.available) {
39 return this.disableMessages.noOrchestrator;
40 }
41 if (!this.hasFeature(status, features)) {
42 return this.disableMessages.missingFeature;
43 }
44 return false;
9f95a23c
TL
45 }
46}