]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/host.service.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / host.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { Observable } from 'rxjs';
5 import { map } from 'rxjs/operators';
6
7 import { Daemon } from '../models/daemon.interface';
8 import { CdDevice } from '../models/devices';
9 import { SmartDataResponseV1 } from '../models/smart';
10 import { DeviceService } from '../services/device.service';
11 import { ApiModule } from './api.module';
12
13 @Injectable({
14 providedIn: ApiModule
15 })
16 export class HostService {
17 baseURL = 'api/host';
18
19 constructor(private http: HttpClient, private deviceService: DeviceService) {}
20
21 list() {
22 return this.http.get(this.baseURL);
23 }
24
25 create(hostname: string) {
26 return this.http.post(this.baseURL, { hostname: hostname }, { observe: 'response' });
27 }
28
29 delete(hostname: string) {
30 return this.http.delete(`${this.baseURL}/${hostname}`, { observe: 'response' });
31 }
32
33 getDevices(hostname: string): Observable<CdDevice[]> {
34 return this.http
35 .get<CdDevice[]>(`${this.baseURL}/${hostname}/devices`)
36 .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device))));
37 }
38
39 getSmartData(hostname: string) {
40 return this.http.get<SmartDataResponseV1>(`${this.baseURL}/${hostname}/smart`);
41 }
42
43 getDaemons(hostname: string): Observable<Daemon[]> {
44 return this.http.get<Daemon[]>(`${this.baseURL}/${hostname}/daemons`);
45 }
46
47 getLabels(): Observable<string[]> {
48 return this.http.get<string[]>('ui-api/host/labels');
49 }
50
51 update(hostname: string, labels: string[]) {
52 return this.http.put(`${this.baseURL}/${hostname}`, { labels: labels });
53 }
54 }