1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import _ from 'lodash';
5 import { Observable } from 'rxjs';
6 import { map } from 'rxjs/operators';
8 import { CdDevice } from '../models/devices';
9 import { InventoryDeviceType } from '../models/inventory-device-type.model';
10 import { DeploymentOptions } from '../models/osd-deployment-options';
11 import { OsdSettings } from '../models/osd-settings';
12 import { SmartDataResponseV1 } from '../models/smart';
13 import { DeviceService } from '../services/device.service';
18 export class OsdService {
19 private path = 'api/osd';
20 private uiPath = 'ui-api/osd';
22 osdDevices: InventoryDeviceType[] = [];
24 osdRecvSpeedModalPriorities = {
28 text: $localize`-- Select the priority --`,
30 osd_max_backfills: null,
31 osd_recovery_max_active: null,
32 osd_recovery_max_single_start: null,
33 osd_recovery_sleep: null
41 osd_recovery_max_active: 1,
42 osd_recovery_max_single_start: 1,
43 osd_recovery_sleep: 0.5
48 text: $localize`Default`,
51 osd_recovery_max_active: 3,
52 osd_recovery_max_single_start: 1,
58 text: $localize`High`,
61 osd_recovery_max_active: 4,
62 osd_recovery_max_single_start: 4,
69 constructor(private http: HttpClient, private deviceService: DeviceService) {}
71 create(driveGroups: Object[], trackingId: string, method = 'drive_groups') {
75 tracking_id: trackingId
77 return this.http.post(this.path, request, { observe: 'response' });
81 return this.http.get(`${this.path}`);
84 getOsdSettings(): Observable<OsdSettings> {
85 return this.http.get<OsdSettings>(`${this.path}/settings`, {
86 headers: { Accept: 'application/vnd.ceph.api.v0.1+json' }
90 getDetails(id: number) {
92 osd_map: { [key: string]: any };
93 osd_metadata: { [key: string]: any };
94 smart: { [device_identifier: string]: any };
96 return this.http.get<OsdData>(`${this.path}/${id}`);
102 getSmartData(id: number) {
103 return this.http.get<SmartDataResponseV1>(`${this.path}/${id}/smart`);
106 scrub(id: string, deep: boolean) {
107 return this.http.post(`${this.path}/${id}/scrub?deep=${deep}`, null);
110 getDeploymentOptions() {
111 return this.http.get<DeploymentOptions>(`${this.uiPath}/deployment_options`);
115 return this.http.get(`${this.path}/flags`);
118 updateFlags(flags: string[]) {
119 return this.http.put(`${this.path}/flags`, { flags: flags });
122 updateIndividualFlags(flags: { [flag: string]: boolean }, ids: number[]) {
123 return this.http.put(`${this.path}/flags/individual`, { flags: flags, ids: ids });
126 markOut(id: number) {
127 return this.http.put(`${this.path}/${id}/mark`, { action: 'out' });
131 return this.http.put(`${this.path}/${id}/mark`, { action: 'in' });
134 markDown(id: number) {
135 return this.http.put(`${this.path}/${id}/mark`, { action: 'down' });
138 reweight(id: number, weight: number) {
139 return this.http.post(`${this.path}/${id}/reweight`, { weight: weight });
142 update(id: number, deviceClass: string) {
143 return this.http.put(`${this.path}/${id}`, { device_class: deviceClass });
146 markLost(id: number) {
147 return this.http.put(`${this.path}/${id}/mark`, { action: 'lost' });
151 return this.http.post(`${this.path}/${id}/purge`, null);
154 destroy(id: number) {
155 return this.http.post(`${this.path}/${id}/destroy`, null);
158 delete(id: number, preserveId?: boolean, force?: boolean) {
160 preserve_id: preserveId ? 'true' : 'false',
161 force: force ? 'true' : 'false'
163 return this.http.delete(`${this.path}/${id}`, { observe: 'response', params: params });
166 safeToDestroy(ids: string) {
167 interface SafeToDestroyResponse {
168 is_safe_to_destroy: boolean;
171 return this.http.get<SafeToDestroyResponse>(`${this.path}/safe_to_destroy?ids=${ids}`);
174 safeToDelete(ids: string) {
175 interface SafeToDeleteResponse {
176 is_safe_to_delete: boolean;
179 return this.http.get<SafeToDeleteResponse>(`${this.path}/safe_to_delete?svc_ids=${ids}`);
182 getDevices(osdId: number) {
184 .get<CdDevice[]>(`${this.path}/${osdId}/devices`)
185 .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device))));