]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rgw-zone.service.ts
1 import { HttpClient, HttpParams } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3 import { Observable } from 'rxjs';
4 import { RgwRealm, RgwZone, RgwZonegroup } from '~/app/ceph/rgw/models/rgw-multisite';
5 import { Icons } from '../enum/icons.enum';
6
7 @Injectable({
8 providedIn: 'root'
9 })
10 export class RgwZoneService {
11 private url = 'api/rgw/zone';
12
13 constructor(private http: HttpClient) {}
14
15 create(
16 zone: RgwZone,
17 zonegroup: RgwZonegroup,
18 defaultZone: boolean,
19 master: boolean,
20 endpoints: string
21 ) {
22 let params = new HttpParams();
23 params = params.appendAll({
24 zone_name: zone.name,
25 zonegroup_name: zonegroup.name,
26 default: defaultZone,
27 master: master,
28 zone_endpoints: endpoints,
29 access_key: zone.system_key.access_key,
30 secret_key: zone.system_key.secret_key
31 });
32 return this.http.post(`${this.url}`, null, { params: params });
33 }
34
35 list(): Observable<object> {
36 return this.http.get<object>(`${this.url}`);
37 }
38
39 get(zone: RgwZone): Observable<object> {
40 return this.http.get(`${this.url}/${zone.name}`);
41 }
42
43 getAllZonesInfo(): Observable<object> {
44 return this.http.get(`${this.url}/get_all_zones_info`);
45 }
46
47 delete(
48 zoneName: string,
49 deletePools: boolean,
50 pools: Set<string>,
51 zonegroupName: string
52 ): Observable<any> {
53 let params = new HttpParams();
54 params = params.appendAll({
55 zone_name: zoneName,
56 delete_pools: deletePools,
57 pools: Array.from(pools.values()),
58 zonegroup_name: zonegroupName
59 });
60 return this.http.delete(`${this.url}/${zoneName}`, { params: params });
61 }
62
63 update(
64 zone: RgwZone,
65 zonegroup: RgwZonegroup,
66 newZoneName: string,
67 defaultZone?: boolean,
68 master?: boolean,
69 endpoints?: string,
70 placementTarget?: string,
71 dataPool?: string,
72 indexPool?: string,
73 dataExtraPool?: string,
74 storageClass?: string,
75 dataPoolClass?: string,
76 compression?: string
77 ) {
78 let requestBody = {
79 zone_name: zone.name,
80 zonegroup_name: zonegroup.name,
81 new_zone_name: newZoneName,
82 default: defaultZone,
83 master: master,
84 zone_endpoints: endpoints,
85 access_key: zone.system_key.access_key,
86 secret_key: zone.system_key.secret_key,
87 placement_target: placementTarget,
88 data_pool: dataPool,
89 index_pool: indexPool,
90 data_extra_pool: dataExtraPool,
91 storage_class: storageClass,
92 data_pool_class: dataPoolClass,
93 compression: compression
94 };
95 return this.http.put(`${this.url}/${zone.name}`, requestBody);
96 }
97
98 getZoneTree(
99 zone: RgwZone,
100 defaultZoneId: string,
101 zones: RgwZone[],
102 zonegroup?: RgwZonegroup,
103 realm?: RgwRealm
104 ) {
105 let nodes = {};
106 let zoneIds = [];
107 nodes['id'] = zone.id;
108 zoneIds.push(zone.id);
109 nodes['name'] = zone.name;
110 nodes['type'] = 'zone';
111 nodes['name'] = zone.name;
112 nodes['info'] = zone;
113 nodes['icon'] = Icons.deploy;
114 nodes['zone_zonegroup'] = zonegroup;
115 nodes['parent'] = zonegroup ? zonegroup.name : '';
116 nodes['second_parent'] = realm ? realm.name : '';
117 nodes['is_default'] = zone.id === defaultZoneId ? true : false;
118 nodes['endpoints'] = zone.endpoints;
119 nodes['is_master'] = zonegroup && zonegroup.master_zone === zone.id ? true : false;
120 nodes['type'] = 'zone';
121 const zoneNames = zones.map((zone: RgwZone) => {
122 return zone['name'];
123 });
124 nodes['secondary_zone'] = !zoneNames.includes(zone.name) ? true : false;
125 const zoneInfo = zones.filter((zoneInfo) => zoneInfo.name === zone.name);
126 if (zoneInfo && zoneInfo.length > 0) {
127 const access_key = zoneInfo[0].system_key['access_key'];
128 const secret_key = zoneInfo[0].system_key['secret_key'];
129 nodes['access_key'] = access_key ? access_key : '';
130 nodes['secret_key'] = secret_key ? secret_key : '';
131 nodes['user'] = access_key && access_key !== '' ? true : false;
132 }
133 if (nodes['access_key'] === '' || nodes['access_key'] === 'null') {
134 nodes['show_warning'] = true;
135 nodes['warning_message'] = 'Access/Secret keys not found';
136 } else {
137 nodes['show_warning'] = false;
138 }
139 if (nodes['endpoints'] && nodes['endpoints'].length === 0) {
140 nodes['show_warning'] = true;
141 nodes['warning_message'] = nodes['warning_message'] + '\n' + 'Endpoints not configured';
142 }
143 return {
144 nodes: nodes,
145 zoneIds: zoneIds
146 };
147 }
148
149 getPoolNames() {
150 return this.http.get(`${this.url}/get_pool_names`);
151 }
152
153 createSystemUser(userName: string, zone: string) {
154 let requestBody = {
155 userName: userName,
156 zoneName: zone
157 };
158 return this.http.put(`${this.url}/create_system_user`, requestBody);
159 }
160
161 getUserList(zoneName: string) {
162 let params = new HttpParams();
163 params = params.appendAll({
164 zoneName: zoneName
165 });
166 return this.http.get(`${this.url}/get_user_list`, { params: params });
167 }
168 }