1 import { HttpClient, HttpParams } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import * as _ from 'lodash';
5 import { Observable, of as observableOf } from 'rxjs';
6 import { mergeMap } from 'rxjs/operators';
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';
15 export class OrchestratorService {
16 private url = 'api/orchestrator';
18 constructor(private http: HttpClient) {}
20 status(): Observable<{ available: boolean; description: string }> {
21 return this.http.get<{ available: boolean; description: string }>(`${this.url}/status`);
24 identifyDevice(hostname: string, device: string, duration: number) {
25 return this.http.post(`${this.url}/identify_device`, {
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);
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}`;
47 return observableOf(devices);