]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/osd.service.ts
10a0cf47f0887ed720af19d652f36d235f2e5b0c
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / osd.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import _ from 'lodash';
5 import { Observable } from 'rxjs';
6 import { map } from 'rxjs/operators';
7
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';
14
15 @Injectable({
16 providedIn: 'root'
17 })
18 export class OsdService {
19 private path = 'api/osd';
20 private uiPath = 'ui-api/osd';
21
22 osdDevices: InventoryDeviceType[] = [];
23
24 osdRecvSpeedModalPriorities = {
25 KNOWN_PRIORITIES: [
26 {
27 name: null,
28 text: $localize`-- Select the priority --`,
29 values: {
30 osd_max_backfills: null,
31 osd_recovery_max_active: null,
32 osd_recovery_max_single_start: null,
33 osd_recovery_sleep: null
34 }
35 },
36 {
37 name: 'low',
38 text: $localize`Low`,
39 values: {
40 osd_max_backfills: 1,
41 osd_recovery_max_active: 1,
42 osd_recovery_max_single_start: 1,
43 osd_recovery_sleep: 0.5
44 }
45 },
46 {
47 name: 'default',
48 text: $localize`Default`,
49 values: {
50 osd_max_backfills: 1,
51 osd_recovery_max_active: 3,
52 osd_recovery_max_single_start: 1,
53 osd_recovery_sleep: 0
54 }
55 },
56 {
57 name: 'high',
58 text: $localize`High`,
59 values: {
60 osd_max_backfills: 4,
61 osd_recovery_max_active: 4,
62 osd_recovery_max_single_start: 4,
63 osd_recovery_sleep: 0
64 }
65 }
66 ]
67 };
68
69 constructor(private http: HttpClient, private deviceService: DeviceService) {}
70
71 create(driveGroups: Object[], trackingId: string, method = 'drive_groups') {
72 const request = {
73 method: method,
74 data: driveGroups,
75 tracking_id: trackingId
76 };
77 return this.http.post(this.path, request, { observe: 'response' });
78 }
79
80 getList() {
81 return this.http.get(`${this.path}`);
82 }
83
84 getOsdSettings(): Observable<OsdSettings> {
85 return this.http.get<OsdSettings>(`${this.path}/settings`, {
86 headers: { Accept: 'application/vnd.ceph.api.v0.1+json' }
87 });
88 }
89
90 getDetails(id: number) {
91 interface OsdData {
92 osd_map: { [key: string]: any };
93 osd_metadata: { [key: string]: any };
94 smart: { [device_identifier: string]: any };
95 }
96 return this.http.get<OsdData>(`${this.path}/${id}`);
97 }
98
99 /**
100 * @param id OSD ID
101 */
102 getSmartData(id: number) {
103 return this.http.get<SmartDataResponseV1>(`${this.path}/${id}/smart`);
104 }
105
106 scrub(id: string, deep: boolean) {
107 return this.http.post(`${this.path}/${id}/scrub?deep=${deep}`, null);
108 }
109
110 getDeploymentOptions() {
111 return this.http.get<DeploymentOptions>(`${this.uiPath}/deployment_options`);
112 }
113
114 getFlags() {
115 return this.http.get(`${this.path}/flags`);
116 }
117
118 updateFlags(flags: string[]) {
119 return this.http.put(`${this.path}/flags`, { flags: flags });
120 }
121
122 updateIndividualFlags(flags: { [flag: string]: boolean }, ids: number[]) {
123 return this.http.put(`${this.path}/flags/individual`, { flags: flags, ids: ids });
124 }
125
126 markOut(id: number) {
127 return this.http.put(`${this.path}/${id}/mark`, { action: 'out' });
128 }
129
130 markIn(id: number) {
131 return this.http.put(`${this.path}/${id}/mark`, { action: 'in' });
132 }
133
134 markDown(id: number) {
135 return this.http.put(`${this.path}/${id}/mark`, { action: 'down' });
136 }
137
138 reweight(id: number, weight: number) {
139 return this.http.post(`${this.path}/${id}/reweight`, { weight: weight });
140 }
141
142 update(id: number, deviceClass: string) {
143 return this.http.put(`${this.path}/${id}`, { device_class: deviceClass });
144 }
145
146 markLost(id: number) {
147 return this.http.put(`${this.path}/${id}/mark`, { action: 'lost' });
148 }
149
150 purge(id: number) {
151 return this.http.post(`${this.path}/${id}/purge`, null);
152 }
153
154 destroy(id: number) {
155 return this.http.post(`${this.path}/${id}/destroy`, null);
156 }
157
158 delete(id: number, preserveId?: boolean, force?: boolean) {
159 const params = {
160 preserve_id: preserveId ? 'true' : 'false',
161 force: force ? 'true' : 'false'
162 };
163 return this.http.delete(`${this.path}/${id}`, { observe: 'response', params: params });
164 }
165
166 safeToDestroy(ids: string) {
167 interface SafeToDestroyResponse {
168 is_safe_to_destroy: boolean;
169 message?: string;
170 }
171 return this.http.get<SafeToDestroyResponse>(`${this.path}/safe_to_destroy?ids=${ids}`);
172 }
173
174 safeToDelete(ids: string) {
175 interface SafeToDeleteResponse {
176 is_safe_to_delete: boolean;
177 message?: string;
178 }
179 return this.http.get<SafeToDeleteResponse>(`${this.path}/safe_to_delete?svc_ids=${ids}`);
180 }
181
182 getDevices(osdId: number) {
183 return this.http
184 .get<CdDevice[]>(`${this.path}/${osdId}/devices`)
185 .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device))));
186 }
187 }