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