]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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 { cdEncode } from '../decorators/cd-encode'; | |
8 | import { RbdConfigurationEntry } from '../models/configuration'; | |
9 | import { RbdConfigurationService } from '../services/rbd-configuration.service'; | |
11fdf7f2 TL |
10 | |
11 | @cdEncode | |
12 | @Injectable({ | |
f67539c2 | 13 | providedIn: 'root' |
11fdf7f2 TL |
14 | }) |
15 | export class PoolService { | |
16 | apiPath = 'api/pool'; | |
17 | ||
18 | constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {} | |
19 | ||
9f95a23c | 20 | create(pool: any) { |
11fdf7f2 TL |
21 | return this.http.post(this.apiPath, pool, { observe: 'response' }); |
22 | } | |
23 | ||
9f95a23c | 24 | update(pool: any) { |
11fdf7f2 TL |
25 | let name: string; |
26 | if (pool.hasOwnProperty('srcpool')) { | |
27 | name = pool.srcpool; | |
28 | delete pool.srcpool; | |
29 | } else { | |
30 | name = pool.pool; | |
31 | delete pool.pool; | |
32 | } | |
33 | return this.http.put(`${this.apiPath}/${encodeURIComponent(name)}`, pool, { | |
34 | observe: 'response' | |
35 | }); | |
36 | } | |
37 | ||
9f95a23c | 38 | delete(name: string) { |
11fdf7f2 TL |
39 | return this.http.delete(`${this.apiPath}/${name}`, { observe: 'response' }); |
40 | } | |
41 | ||
9f95a23c | 42 | get(poolName: string) { |
11fdf7f2 TL |
43 | return this.http.get(`${this.apiPath}/${poolName}`); |
44 | } | |
45 | ||
46 | getList() { | |
47 | return this.http.get(`${this.apiPath}?stats=true`); | |
48 | } | |
49 | ||
50 | getConfiguration(poolName: string): Observable<RbdConfigurationEntry[]> { | |
51 | return this.http.get<RbdConfigurationEntry[]>(`${this.apiPath}/${poolName}/configuration`).pipe( | |
52 | // Add static data maintained in RbdConfigurationService | |
53 | map((values) => | |
54 | values.map((entry) => | |
55 | Object.assign(entry, this.rbdConfigurationService.getOptionByName(entry.name)) | |
56 | ) | |
57 | ) | |
58 | ); | |
59 | } | |
60 | ||
9f95a23c TL |
61 | getInfo() { |
62 | return this.http.get(`ui-${this.apiPath}/info`); | |
11fdf7f2 TL |
63 | } |
64 | ||
9f95a23c | 65 | list(attrs: string[] = []) { |
11fdf7f2 TL |
66 | const attrsStr = attrs.join(','); |
67 | return this.http | |
68 | .get(`${this.apiPath}?attrs=${attrsStr}`) | |
69 | .toPromise() | |
70 | .then((resp: any) => { | |
71 | return resp; | |
72 | }); | |
73 | } | |
74 | } |