]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { HttpClient, HttpParams } from '@angular/common/http'; |
2 | import { Injectable } from '@angular/core'; | |
3 | ||
adb31ebb | 4 | import * as _ from 'lodash'; |
9f95a23c TL |
5 | import { Observable } from 'rxjs'; |
6 | ||
7 | import { Daemon } from '../models/daemon.interface'; | |
1911f103 | 8 | import { CephServiceSpec } from '../models/service.interface'; |
9f95a23c TL |
9 | import { ApiModule } from './api.module'; |
10 | ||
11 | @Injectable({ | |
12 | providedIn: ApiModule | |
13 | }) | |
14 | export class CephServiceService { | |
15 | private url = 'api/service'; | |
16 | ||
17 | constructor(private http: HttpClient) {} | |
18 | ||
1911f103 | 19 | list(serviceName?: string): Observable<CephServiceSpec[]> { |
9f95a23c TL |
20 | const options = serviceName |
21 | ? { params: new HttpParams().set('service_name', serviceName) } | |
22 | : {}; | |
1911f103 | 23 | return this.http.get<CephServiceSpec[]>(this.url, options); |
9f95a23c TL |
24 | } |
25 | ||
26 | getDaemons(serviceName?: string): Observable<Daemon[]> { | |
27 | return this.http.get<Daemon[]>(`${this.url}/${serviceName}/daemons`); | |
28 | } | |
adb31ebb TL |
29 | |
30 | create(serviceSpec: { [key: string]: any }) { | |
31 | const serviceName = serviceSpec['service_id'] | |
32 | ? `${serviceSpec['service_type']}.${serviceSpec['service_id']}` | |
33 | : serviceSpec['service_type']; | |
34 | return this.http.post( | |
35 | this.url, | |
36 | { | |
37 | service_name: serviceName, | |
38 | service_spec: serviceSpec | |
39 | }, | |
40 | { observe: 'response' } | |
41 | ); | |
42 | } | |
43 | ||
44 | delete(serviceName: string) { | |
45 | return this.http.delete(`${this.url}/${serviceName}`, { observe: 'response' }); | |
46 | } | |
47 | ||
48 | getKnownTypes(): Observable<string[]> { | |
49 | return this.http.get<string[]>(`${this.url}/known_types`); | |
50 | } | |
9f95a23c | 51 | } |