1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import { map } from 'rxjs/operators';
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';
15 export class RbdService {
16 constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {}
19 return this.http.post('api/block/image', rbd, { observe: 'response' });
22 delete(poolName, rbdName) {
23 return this.http.delete(`api/block/image/${poolName}/${rbdName}`, { observe: 'response' });
26 update(poolName, rbdName, rbd) {
27 return this.http.put(`api/block/image/${poolName}/${rbdName}`, rbd, { observe: 'response' });
30 get(poolName, rbdName) {
31 return this.http.get(`api/block/image/${poolName}/${rbdName}`);
35 return this.http.get<RbdPool[]>('api/block/image').pipe(
38 pool.value.map((image) => {
39 if (!image.configuration) {
42 image.configuration.map((option) =>
43 Object.assign(option, this.rbdConfigurationService.getOptionByName(option.name))
53 copy(poolName, rbdName, rbd) {
54 return this.http.post(`api/block/image/${poolName}/${rbdName}/copy`, rbd, {
59 flatten(poolName, rbdName) {
60 return this.http.post(`api/block/image/${poolName}/${rbdName}/flatten`, null, {
66 return this.http.get('api/block/image/default_features');
69 createSnapshot(poolName, rbdName, @cdEncodeNot snapshotName) {
71 snapshot_name: snapshotName
73 return this.http.post(`api/block/image/${poolName}/${rbdName}/snap`, request, {
78 renameSnapshot(poolName, rbdName, snapshotName, @cdEncodeNot newSnapshotName) {
80 new_snap_name: newSnapshotName
82 return this.http.put(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, request, {
87 protectSnapshot(poolName, rbdName, snapshotName, @cdEncodeNot isProtected) {
89 is_protected: isProtected
91 return this.http.put(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, request, {
96 rollbackSnapshot(poolName, rbdName, snapshotName) {
97 return this.http.post(
98 `api/block/image/${poolName}/${rbdName}/snap/${snapshotName}/rollback`,
100 { observe: 'response' }
104 cloneSnapshot(poolName, rbdName, snapshotName, request) {
105 return this.http.post(
106 `api/block/image/${poolName}/${rbdName}/snap/${snapshotName}/clone`,
108 { observe: 'response' }
112 deleteSnapshot(poolName, rbdName, snapshotName) {
113 return this.http.delete(`api/block/image/${poolName}/${rbdName}/snap/${snapshotName}`, {
119 return this.http.get(`api/block/image/trash/`);
122 moveTrash(poolName, rbdName, delay) {
123 return this.http.post(
124 `api/block/image/${poolName}/${rbdName}/move_trash`,
126 { observe: 'response' }
130 purgeTrash(poolName) {
131 return this.http.post(`api/block/image/trash/purge/?pool_name=${poolName}`, null, {
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' }
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' }