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';
10 export class RgwZoneService {
11 private url = 'api/rgw/zone';
13 constructor(private http: HttpClient) {}
17 zonegroup: RgwZonegroup,
22 let params = new HttpParams();
23 params = params.appendAll({
25 zonegroup_name: zonegroup.name,
28 zone_endpoints: endpoints,
29 access_key: zone.system_key.access_key,
30 secret_key: zone.system_key.secret_key
32 return this.http.post(`${this.url}`, null, { params: params });
35 list(): Observable<object> {
36 return this.http.get<object>(`${this.url}`);
39 get(zone: RgwZone): Observable<object> {
40 return this.http.get(`${this.url}/${zone.name}`);
43 getAllZonesInfo(): Observable<object> {
44 return this.http.get(`${this.url}/get_all_zones_info`);
53 let params = new HttpParams();
54 params = params.appendAll({
56 delete_pools: deletePools,
57 pools: Array.from(pools.values()),
58 zonegroup_name: zonegroupName
60 return this.http.delete(`${this.url}/${zoneName}`, { params: params });
65 zonegroup: RgwZonegroup,
67 defaultZone?: boolean,
70 placementTarget?: string,
73 dataExtraPool?: string,
74 storageClass?: string,
75 dataPoolClass?: string,
80 zonegroup_name: zonegroup.name,
81 new_zone_name: newZoneName,
84 zone_endpoints: endpoints,
85 access_key: zone.system_key.access_key,
86 secret_key: zone.system_key.secret_key,
87 placement_target: placementTarget,
89 index_pool: indexPool,
90 data_extra_pool: dataExtraPool,
91 storage_class: storageClass,
92 data_pool_class: dataPoolClass,
93 compression: compression
95 return this.http.put(`${this.url}/${zone.name}`, requestBody);
100 defaultZoneId: string,
102 zonegroup?: RgwZonegroup,
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) => {
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;
133 if (nodes['access_key'] === '' || nodes['access_key'] === 'null') {
134 nodes['show_warning'] = true;
135 nodes['warning_message'] = 'Access/Secret keys not found';
137 nodes['show_warning'] = false;
139 if (nodes['endpoints'] && nodes['endpoints'].length === 0) {
140 nodes['show_warning'] = true;
141 nodes['warning_message'] = nodes['warning_message'] + '\n' + 'Endpoints not configured';
150 return this.http.get(`${this.url}/get_pool_names`);
153 createSystemUser(userName: string, zone: string) {
158 return this.http.put(`${this.url}/create_system_user`, requestBody);
161 getUserList(zoneName: string) {
162 let params = new HttpParams();
163 params = params.appendAll({
166 return this.http.get(`${this.url}/get_user_list`, { params: params });