]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rbd.service.ts
update ceph source to reef 18.1.2
[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 _ from 'lodash';
5 import { map } from 'rxjs/operators';
6
7 import { ApiClient } from '~/app/shared/api/api-client';
8 import { cdEncode, cdEncodeNot } from '../decorators/cd-encode';
9 import { ImageSpec } from '../models/image-spec';
10 import { RbdConfigurationService } from '../services/rbd-configuration.service';
11 import { RbdPool } from './rbd.model';
12
13 @cdEncode
14 @Injectable({
15 providedIn: 'root'
16 })
17 export class RbdService extends ApiClient {
18 constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {
19 super();
20 }
21
22 isRBDPool(pool: any) {
23 return _.indexOf(pool.application_metadata, 'rbd') !== -1 && !pool.pool_name.includes('/');
24 }
25
26 create(rbd: any) {
27 return this.http.post('api/block/image', rbd, { observe: 'response' });
28 }
29
30 delete(imageSpec: ImageSpec) {
31 return this.http.delete(`api/block/image/${imageSpec.toStringEncoded()}`, {
32 observe: 'response'
33 });
34 }
35
36 update(imageSpec: ImageSpec, rbd: any) {
37 return this.http.put(`api/block/image/${imageSpec.toStringEncoded()}`, rbd, {
38 observe: 'response'
39 });
40 }
41
42 get(imageSpec: ImageSpec) {
43 return this.http.get(`api/block/image/${imageSpec.toStringEncoded()}`);
44 }
45
46 list(params: any) {
47 return this.http
48 .get<RbdPool[]>('api/block/image', {
49 params: params,
50 headers: { Accept: this.getVersionHeaderValue(2, 0) },
51 observe: 'response'
52 })
53 .pipe(
54 map((response: any) => {
55 return response['body'].map((pool: any) => {
56 pool.value.map((image: any) => {
57 if (!image.configuration) {
58 return image;
59 }
60 image.configuration.map((option: any) =>
61 Object.assign(option, this.rbdConfigurationService.getOptionByName(option.name))
62 );
63 return image;
64 });
65 pool['headers'] = response.headers;
66 return pool;
67 });
68 })
69 );
70 }
71
72 copy(imageSpec: ImageSpec, rbd: any) {
73 return this.http.post(`api/block/image/${imageSpec.toStringEncoded()}/copy`, rbd, {
74 observe: 'response'
75 });
76 }
77
78 flatten(imageSpec: ImageSpec) {
79 return this.http.post(`api/block/image/${imageSpec.toStringEncoded()}/flatten`, null, {
80 observe: 'response'
81 });
82 }
83
84 defaultFeatures() {
85 return this.http.get('api/block/image/default_features');
86 }
87
88 cloneFormatVersion() {
89 return this.http.get<number>('api/block/image/clone_format_version');
90 }
91
92 createSnapshot(
93 imageSpec: ImageSpec,
94 @cdEncodeNot snapshotName: string,
95 mirrorImageSnapshot: boolean
96 ) {
97 const request = {
98 snapshot_name: snapshotName,
99 mirrorImageSnapshot: mirrorImageSnapshot
100 };
101 return this.http.post(`api/block/image/${imageSpec.toStringEncoded()}/snap`, request, {
102 observe: 'response'
103 });
104 }
105
106 renameSnapshot(imageSpec: ImageSpec, snapshotName: string, @cdEncodeNot newSnapshotName: string) {
107 const request = {
108 new_snap_name: newSnapshotName
109 };
110 return this.http.put(
111 `api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}`,
112 request,
113 {
114 observe: 'response'
115 }
116 );
117 }
118
119 protectSnapshot(imageSpec: ImageSpec, snapshotName: string, @cdEncodeNot isProtected: boolean) {
120 const request = {
121 is_protected: isProtected
122 };
123 return this.http.put(
124 `api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}`,
125 request,
126 {
127 observe: 'response'
128 }
129 );
130 }
131
132 rollbackSnapshot(imageSpec: ImageSpec, snapshotName: string) {
133 return this.http.post(
134 `api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}/rollback`,
135 null,
136 { observe: 'response' }
137 );
138 }
139
140 cloneSnapshot(imageSpec: ImageSpec, snapshotName: string, request: any) {
141 return this.http.post(
142 `api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}/clone`,
143 request,
144 { observe: 'response' }
145 );
146 }
147
148 deleteSnapshot(imageSpec: ImageSpec, snapshotName: string) {
149 return this.http.delete(`api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}`, {
150 observe: 'response'
151 });
152 }
153
154 listTrash() {
155 return this.http.get(`api/block/image/trash/`);
156 }
157
158 createNamespace(pool: string, namespace: string) {
159 const request = {
160 namespace: namespace
161 };
162 return this.http.post(`api/block/pool/${pool}/namespace`, request, { observe: 'response' });
163 }
164
165 listNamespaces(pool: string) {
166 return this.http.get(`api/block/pool/${pool}/namespace/`);
167 }
168
169 deleteNamespace(pool: string, namespace: string) {
170 return this.http.delete(`api/block/pool/${pool}/namespace/${namespace}`, {
171 observe: 'response'
172 });
173 }
174
175 moveTrash(imageSpec: ImageSpec, delay: number) {
176 return this.http.post(
177 `api/block/image/${imageSpec.toStringEncoded()}/move_trash`,
178 { delay: delay },
179 { observe: 'response' }
180 );
181 }
182
183 purgeTrash(poolName: string) {
184 return this.http.post(`api/block/image/trash/purge/?pool_name=${poolName}`, null, {
185 observe: 'response'
186 });
187 }
188
189 restoreTrash(imageSpec: ImageSpec, @cdEncodeNot newImageName: string) {
190 return this.http.post(
191 `api/block/image/trash/${imageSpec.toStringEncoded()}/restore`,
192 { new_image_name: newImageName },
193 { observe: 'response' }
194 );
195 }
196
197 removeTrash(imageSpec: ImageSpec, force = false) {
198 return this.http.delete(
199 `api/block/image/trash/${imageSpec.toStringEncoded()}/?force=${force}`,
200 { observe: 'response' }
201 );
202 }
203 }