]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/orchestrator.service.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / orchestrator.service.ts
1 import { HttpClient, HttpParams } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import * as _ from 'lodash';
5 import { Observable, of as observableOf } from 'rxjs';
6 import { mergeMap } from 'rxjs/operators';
7
8 import { InventoryDevice } from '../../ceph/cluster/inventory/inventory-devices/inventory-device.model';
9 import { InventoryHost } from '../../ceph/cluster/inventory/inventory-host.model';
10 import { ApiModule } from './api.module';
11
12 @Injectable({
13 providedIn: ApiModule
14 })
15 export class OrchestratorService {
16 private url = 'api/orchestrator';
17
18 constructor(private http: HttpClient) {}
19
20 status(): Observable<{ available: boolean; description: string }> {
21 return this.http.get<{ available: boolean; description: string }>(`${this.url}/status`);
22 }
23
24 identifyDevice(hostname: string, device: string, duration: number) {
25 return this.http.post(`${this.url}/identify_device`, {
26 hostname,
27 device,
28 duration
29 });
30 }
31
32 inventoryList(hostname?: string): Observable<InventoryHost[]> {
33 const options = hostname ? { params: new HttpParams().set('hostname', hostname) } : {};
34 return this.http.get<InventoryHost[]>(`${this.url}/inventory`, options);
35 }
36
37 inventoryDeviceList(hostname?: string): Observable<InventoryDevice[]> {
38 return this.inventoryList(hostname).pipe(
39 mergeMap((hosts: InventoryHost[]) => {
40 const devices = _.flatMap(hosts, (host) => {
41 return host.devices.map((device) => {
42 device.hostname = host.name;
43 device.uid = device.device_id ? device.device_id : `${device.hostname}-${device.path}`;
44 return device;
45 });
46 });
47 return observableOf(devices);
48 })
49 );
50 }
51 }