All files / src/app/shared/api rbd.service.ts

92.06% Statements 58/63
58.33% Branches 7/12
92% Functions 23/25
93.1% Lines 54/58

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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