]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / pool.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 { 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
21 create(pool: any) {
22 return this.http.post(this.apiPath, pool, { observe: 'response' });
23 }
24
25 update(pool: any) {
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
39 delete(name: string) {
40 return this.http.delete(`${this.apiPath}/${name}`, { observe: 'response' });
41 }
42
43 get(poolName: string) {
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
62 getInfo() {
63 return this.http.get(`ui-${this.apiPath}/info`);
64 }
65
66 list(attrs: string[] = []) {
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 }