]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts
3ccf6100254ece192b67da4d725b1cc1710ae072
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rbd.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { map } from 'rxjs/operators';
5
6 import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
7 import { RbdConfigurationService } from '../services/rbd-configuration.service';
8 import { ApiModule } from './api.module';
9 import { RbdPool } from './rbd.model';
10
11 @cdEncode
12 @Injectable({
13 providedIn: ApiModule
14 })
15 export class RbdService {
16 constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {}
17
18 create(rbd) {
19 return this.http.post('api/block/image', rbd, { observe: 'response' });
20 }
21
22 delete(poolName, rbdName) {
23 return this.http.delete(`api/block/image/${poolName}/${rbdName}`, { observe: 'response' });
24 }
25
26 update(poolName, rbdName, rbd) {
27 return this.http.put(`api/block/image/${poolName}/${rbdName}`, rbd, { observe: 'response' });
28 }
29
30 get(poolName, rbdName) {
31 return this.http.get(`api/block/image/${poolName}/${rbdName}`);
32 }
33
34 list() {
35 return this.http.get<RbdPool[]>('api/block/image').pipe(
36 map((pools) =>
37 pools.map((pool) => {
38 pool.value.map((image) => {
39 if (!image.configuration) {
40 return image;
41 }
42 image.configuration.map((option) =>
43 Object.assign(option, this.rbdConfigurationService.getOptionByName(option.name))
44 );
45 return image;
46 });
47 return pool;
48 })
49 )
50 );
51 }
52
53 copy(poolName, rbdName, rbd) {
54 return this.http.post(`api/block/image/${poolName}/${rbdName}/copy`, rbd, {
55 observe: 'response'
56 });
57 }
58
59 flatten(poolName, rbdName) {
60 return this.http.post(`api/block/image/${poolName}/${rbdName}/flatten`, null, {
61 observe: 'response'
62 });
63 }
64
65 defaultFeatures() {
66 return this.http.get('api/block/image/default_features');
67 }
68
69 createSnapshot(poolName, rbdName, @cdEncodeNot snapshotName) {
70 const request = {
71 snapshot_name: snapshotName
72 };
73 return this.http.post(`api/block/image/${poolName}/${rbdName}/snap`, request, {
74 observe: 'response'
75 });
76 }
77
78 renameSnapshot(poolName, rbdName, snapshotName, @cdEncodeNot newSnapshotName) {
79 const request = {
80 new_snap_name: newSnapshotName
81 };
82 return this.http.put(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, request, {
83 observe: 'response'
84 });
85 }
86
87 protectSnapshot(poolName, rbdName, snapshotName, @cdEncodeNot isProtected) {
88 const request = {
89 is_protected: isProtected
90 };
91 return this.http.put(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, request, {
92 observe: 'response'
93 });
94 }
95
96 rollbackSnapshot(poolName, rbdName, snapshotName) {
97 return this.http.post(
98 `api/block/image/${poolName}/${rbdName}/snap/${snapshotName}/rollback`,
99 null,
100 { observe: 'response' }
101 );
102 }
103
104 cloneSnapshot(poolName, rbdName, snapshotName, request) {
105 return this.http.post(
106 `api/block/image/${poolName}/${rbdName}/snap/${snapshotName}/clone`,
107 request,
108 { observe: 'response' }
109 );
110 }
111
112 deleteSnapshot(poolName, rbdName, snapshotName) {
113 return this.http.delete(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, {
114 observe: 'response'
115 });
116 }
117
118 listTrash() {
119 return this.http.get(`api/block/image/trash/`);
120 }
121
122 moveTrash(poolName, rbdName, delay) {
123 return this.http.post(
124 `api/block/image/${poolName}/${rbdName}/move_trash`,
125 { delay: delay },
126 { observe: 'response' }
127 );
128 }
129
130 purgeTrash(poolName) {
131 return this.http.post(`api/block/image/trash/purge/?pool_name=${poolName}`, null, {
132 observe: 'response'
133 });
134 }
135
136 restoreTrash(poolName, imageId, newImageName) {
137 return this.http.post(
138 `api/block/image/trash/${poolName}/${imageId}/restore`,
139 { new_image_name: newImageName },
140 { observe: 'response' }
141 );
142 }
143
144 removeTrash(poolName, imageId, imageName, force = false) {
145 return this.http.delete(
146 `api/block/image/trash/${poolName}/${imageId}/?image_name=${imageName}&force=${force}`,
147 { observe: 'response' }
148 );
149 }
150 }