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