]>
Commit | Line | Data |
---|---|---|
39ae355f | 1 | import { HttpParams } from '@angular/common/http'; |
a4b75251 | 2 | import { Component, Input, OnInit, ViewChild } from '@angular/core'; |
adb31ebb | 3 | import { AbstractControl, Validators } from '@angular/forms'; |
a4b75251 | 4 | import { ActivatedRoute, Router } from '@angular/router'; |
adb31ebb | 5 | |
a4b75251 | 6 | import { NgbActiveModal, NgbTypeahead } from '@ng-bootstrap/ng-bootstrap'; |
f67539c2 TL |
7 | import _ from 'lodash'; |
8 | import { merge, Observable, Subject } from 'rxjs'; | |
9 | import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators'; | |
adb31ebb | 10 | |
f67539c2 TL |
11 | import { CephServiceService } from '~/app/shared/api/ceph-service.service'; |
12 | import { HostService } from '~/app/shared/api/host.service'; | |
13 | import { PoolService } from '~/app/shared/api/pool.service'; | |
14 | import { SelectMessages } from '~/app/shared/components/select/select-messages.model'; | |
15 | import { SelectOption } from '~/app/shared/components/select/select-option.model'; | |
16 | import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants'; | |
17 | import { CdForm } from '~/app/shared/forms/cd-form'; | |
18 | import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder'; | |
19 | import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; | |
20 | import { CdValidators } from '~/app/shared/forms/cd-validators'; | |
21 | import { FinishedTask } from '~/app/shared/models/finished-task'; | |
b3b6e05e | 22 | import { CephServiceSpec } from '~/app/shared/models/service.interface'; |
f67539c2 | 23 | import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; |
adb31ebb TL |
24 | |
25 | @Component({ | |
26 | selector: 'cd-service-form', | |
27 | templateUrl: './service-form.component.html', | |
28 | styleUrls: ['./service-form.component.scss'] | |
29 | }) | |
f67539c2 | 30 | export class ServiceFormComponent extends CdForm implements OnInit { |
522d829b | 31 | readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/; |
39ae355f | 32 | readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/; |
20effc67 TL |
33 | readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/; |
34 | readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g; | |
2a845540 | 35 | readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs']; |
f67539c2 TL |
36 | @ViewChild(NgbTypeahead, { static: false }) |
37 | typeahead: NgbTypeahead; | |
38 | ||
a4b75251 TL |
39 | @Input() hiddenServices: string[] = []; |
40 | ||
41 | @Input() editing = false; | |
42 | ||
43 | @Input() serviceName: string; | |
44 | ||
45 | @Input() serviceType: string; | |
46 | ||
adb31ebb TL |
47 | serviceForm: CdFormGroup; |
48 | action: string; | |
49 | resource: string; | |
50 | serviceTypes: string[] = []; | |
2a845540 | 51 | serviceIds: string[] = []; |
adb31ebb TL |
52 | hosts: any; |
53 | labels: string[]; | |
f67539c2 TL |
54 | labelClick = new Subject<string>(); |
55 | labelFocus = new Subject<string>(); | |
adb31ebb | 56 | pools: Array<object>; |
b3b6e05e | 57 | services: Array<CephServiceSpec> = []; |
a4b75251 | 58 | pageURL: string; |
2a845540 | 59 | serviceList: CephServiceSpec[]; |
adb31ebb | 60 | |
adb31ebb TL |
61 | constructor( |
62 | public actionLabels: ActionLabelsI18n, | |
63 | private cephServiceService: CephServiceService, | |
64 | private formBuilder: CdFormBuilder, | |
65 | private hostService: HostService, | |
adb31ebb TL |
66 | private poolService: PoolService, |
67 | private router: Router, | |
a4b75251 TL |
68 | private taskWrapperService: TaskWrapperService, |
69 | private route: ActivatedRoute, | |
70 | public activeModal: NgbActiveModal | |
adb31ebb | 71 | ) { |
f67539c2 TL |
72 | super(); |
73 | this.resource = $localize`service`; | |
adb31ebb TL |
74 | this.hosts = { |
75 | options: [], | |
f67539c2 TL |
76 | messages: new SelectMessages({ |
77 | empty: $localize`There are no hosts.`, | |
78 | filter: $localize`Filter hosts` | |
79 | }) | |
adb31ebb TL |
80 | }; |
81 | this.createForm(); | |
82 | } | |
83 | ||
84 | createForm() { | |
85 | this.serviceForm = this.formBuilder.group({ | |
86 | // Global | |
87 | service_type: [null, [Validators.required]], | |
88 | service_id: [ | |
89 | null, | |
90 | [ | |
39ae355f TL |
91 | CdValidators.composeIf( |
92 | { | |
93 | service_type: 'mds' | |
94 | }, | |
95 | [ | |
96 | Validators.required, | |
97 | CdValidators.custom('mdsPattern', (value: string) => { | |
98 | if (_.isEmpty(value)) { | |
99 | return false; | |
100 | } | |
101 | return !this.MDS_SVC_ID_PATTERN.test(value); | |
102 | }) | |
103 | ] | |
104 | ), | |
adb31ebb TL |
105 | CdValidators.requiredIf({ |
106 | service_type: 'nfs' | |
107 | }), | |
108 | CdValidators.requiredIf({ | |
109 | service_type: 'iscsi' | |
110 | }), | |
b3b6e05e TL |
111 | CdValidators.requiredIf({ |
112 | service_type: 'ingress' | |
113 | }), | |
adb31ebb TL |
114 | CdValidators.composeIf( |
115 | { | |
116 | service_type: 'rgw' | |
117 | }, | |
118 | [ | |
119 | Validators.required, | |
120 | CdValidators.custom('rgwPattern', (value: string) => { | |
121 | if (_.isEmpty(value)) { | |
122 | return false; | |
123 | } | |
522d829b | 124 | return !this.RGW_SVC_ID_PATTERN.test(value); |
adb31ebb TL |
125 | }) |
126 | ] | |
2a845540 TL |
127 | ), |
128 | CdValidators.custom('uniqueName', (service_id: string) => { | |
129 | return this.serviceIds && this.serviceIds.includes(service_id); | |
130 | }) | |
adb31ebb TL |
131 | ] |
132 | ], | |
133 | placement: ['hosts'], | |
134 | label: [ | |
135 | null, | |
136 | [ | |
137 | CdValidators.requiredIf({ | |
138 | placement: 'label', | |
139 | unmanaged: false | |
140 | }) | |
141 | ] | |
142 | ], | |
143 | hosts: [[]], | |
20effc67 | 144 | count: [null, [CdValidators.number(false)]], |
adb31ebb | 145 | unmanaged: [false], |
a4b75251 | 146 | // iSCSI |
adb31ebb TL |
147 | pool: [ |
148 | null, | |
149 | [ | |
adb31ebb | 150 | CdValidators.requiredIf({ |
2a845540 | 151 | service_type: 'iscsi' |
adb31ebb TL |
152 | }) |
153 | ] | |
154 | ], | |
adb31ebb | 155 | // RGW |
20effc67 | 156 | rgw_frontend_port: [null, [CdValidators.number(false)]], |
adb31ebb TL |
157 | // iSCSI |
158 | trusted_ip_list: [null], | |
20effc67 | 159 | api_port: [null, [CdValidators.number(false)]], |
adb31ebb TL |
160 | api_user: [ |
161 | null, | |
162 | [ | |
163 | CdValidators.requiredIf({ | |
164 | service_type: 'iscsi', | |
165 | unmanaged: false | |
166 | }) | |
167 | ] | |
168 | ], | |
169 | api_password: [ | |
170 | null, | |
171 | [ | |
172 | CdValidators.requiredIf({ | |
173 | service_type: 'iscsi', | |
174 | unmanaged: false | |
175 | }) | |
176 | ] | |
177 | ], | |
b3b6e05e TL |
178 | // Ingress |
179 | backend_service: [ | |
180 | null, | |
181 | [ | |
182 | CdValidators.requiredIf({ | |
2a845540 | 183 | service_type: 'ingress' |
b3b6e05e TL |
184 | }) |
185 | ] | |
186 | ], | |
187 | virtual_ip: [ | |
188 | null, | |
189 | [ | |
190 | CdValidators.requiredIf({ | |
2a845540 TL |
191 | service_type: 'ingress' |
192 | }) | |
193 | ] | |
194 | ], | |
195 | frontend_port: [ | |
196 | null, | |
197 | [ | |
198 | CdValidators.number(false), | |
199 | CdValidators.requiredIf({ | |
200 | service_type: 'ingress' | |
201 | }) | |
202 | ] | |
203 | ], | |
204 | monitor_port: [ | |
205 | null, | |
206 | [ | |
207 | CdValidators.number(false), | |
208 | CdValidators.requiredIf({ | |
209 | service_type: 'ingress' | |
b3b6e05e TL |
210 | }) |
211 | ] | |
212 | ], | |
b3b6e05e TL |
213 | virtual_interface_networks: [null], |
214 | // RGW, Ingress & iSCSI | |
adb31ebb TL |
215 | ssl: [false], |
216 | ssl_cert: [ | |
217 | '', | |
218 | [ | |
219 | CdValidators.composeIf( | |
220 | { | |
221 | service_type: 'rgw', | |
222 | unmanaged: false, | |
223 | ssl: true | |
224 | }, | |
522d829b | 225 | [Validators.required, CdValidators.pemCert()] |
adb31ebb TL |
226 | ), |
227 | CdValidators.composeIf( | |
228 | { | |
229 | service_type: 'iscsi', | |
230 | unmanaged: false, | |
231 | ssl: true | |
232 | }, | |
233 | [Validators.required, CdValidators.sslCert()] | |
33c7a0ef TL |
234 | ), |
235 | CdValidators.composeIf( | |
236 | { | |
237 | service_type: 'ingress', | |
238 | unmanaged: false, | |
239 | ssl: true | |
240 | }, | |
241 | [Validators.required, CdValidators.pemCert()] | |
adb31ebb TL |
242 | ) |
243 | ] | |
244 | ], | |
245 | ssl_key: [ | |
246 | '', | |
247 | [ | |
adb31ebb TL |
248 | CdValidators.composeIf( |
249 | { | |
250 | service_type: 'iscsi', | |
251 | unmanaged: false, | |
252 | ssl: true | |
253 | }, | |
254 | [Validators.required, CdValidators.sslPrivKey()] | |
255 | ) | |
256 | ] | |
20effc67 TL |
257 | ], |
258 | // snmp-gateway | |
259 | snmp_version: [ | |
260 | null, | |
261 | [ | |
262 | CdValidators.requiredIf({ | |
263 | service_type: 'snmp-gateway' | |
264 | }) | |
265 | ] | |
266 | ], | |
267 | snmp_destination: [ | |
268 | null, | |
269 | { | |
270 | validators: [ | |
271 | CdValidators.requiredIf({ | |
272 | service_type: 'snmp-gateway' | |
273 | }), | |
274 | CdValidators.custom('snmpDestinationPattern', (value: string) => { | |
275 | if (_.isEmpty(value)) { | |
276 | return false; | |
277 | } | |
278 | return !this.SNMP_DESTINATION_PATTERN.test(value); | |
279 | }) | |
280 | ] | |
281 | } | |
282 | ], | |
283 | engine_id: [ | |
284 | null, | |
285 | [ | |
286 | CdValidators.requiredIf({ | |
287 | service_type: 'snmp-gateway' | |
288 | }), | |
289 | CdValidators.custom('snmpEngineIdPattern', (value: string) => { | |
290 | if (_.isEmpty(value)) { | |
291 | return false; | |
292 | } | |
293 | return !this.SNMP_ENGINE_ID_PATTERN.test(value); | |
294 | }) | |
295 | ] | |
296 | ], | |
297 | auth_protocol: [ | |
298 | 'SHA', | |
299 | [ | |
300 | CdValidators.requiredIf({ | |
301 | service_type: 'snmp-gateway' | |
302 | }) | |
303 | ] | |
304 | ], | |
305 | privacy_protocol: [null], | |
306 | snmp_community: [ | |
307 | null, | |
308 | [ | |
309 | CdValidators.requiredIf({ | |
310 | snmp_version: 'V2c' | |
311 | }) | |
312 | ] | |
313 | ], | |
314 | snmp_v3_auth_username: [ | |
315 | null, | |
316 | [ | |
317 | CdValidators.requiredIf({ | |
318 | service_type: 'snmp-gateway' | |
319 | }) | |
320 | ] | |
321 | ], | |
322 | snmp_v3_auth_password: [ | |
323 | null, | |
324 | [ | |
325 | CdValidators.requiredIf({ | |
326 | service_type: 'snmp-gateway' | |
327 | }) | |
328 | ] | |
329 | ], | |
330 | snmp_v3_priv_password: [ | |
331 | null, | |
332 | [ | |
333 | CdValidators.requiredIf({ | |
334 | privacy_protocol: { op: '!empty' } | |
335 | }) | |
336 | ] | |
adb31ebb TL |
337 | ] |
338 | }); | |
339 | } | |
340 | ||
341 | ngOnInit(): void { | |
342 | this.action = this.actionLabels.CREATE; | |
a4b75251 TL |
343 | if (this.router.url.includes('services/(modal:create')) { |
344 | this.pageURL = 'services'; | |
345 | } else if (this.router.url.includes('services/(modal:edit')) { | |
346 | this.editing = true; | |
347 | this.pageURL = 'services'; | |
348 | this.route.params.subscribe((params: { type: string; name: string }) => { | |
349 | this.serviceName = params.name; | |
350 | this.serviceType = params.type; | |
351 | }); | |
352 | } | |
2a845540 | 353 | |
39ae355f TL |
354 | this.cephServiceService |
355 | .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } })) | |
356 | .observable.subscribe((services: CephServiceSpec[]) => { | |
357 | this.serviceList = services; | |
358 | this.services = services.filter((service: any) => | |
359 | this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type) | |
360 | ); | |
361 | }); | |
2a845540 | 362 | |
adb31ebb | 363 | this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => { |
f67539c2 TL |
364 | // Remove service types: |
365 | // osd - This is deployed a different way. | |
366 | // container - This should only be used in the CLI. | |
a4b75251 TL |
367 | this.hiddenServices.push('osd', 'container'); |
368 | ||
369 | this.serviceTypes = _.difference(resp, this.hiddenServices).sort(); | |
adb31ebb | 370 | }); |
a4b75251 | 371 | this.hostService.list('false').subscribe((resp: object[]) => { |
adb31ebb TL |
372 | const options: SelectOption[] = []; |
373 | _.forEach(resp, (host: object) => { | |
374 | if (_.get(host, 'sources.orchestrator', false)) { | |
375 | const option = new SelectOption(false, _.get(host, 'hostname'), ''); | |
376 | options.push(option); | |
377 | } | |
378 | }); | |
379 | this.hosts.options = [...options]; | |
380 | }); | |
381 | this.hostService.getLabels().subscribe((resp: string[]) => { | |
382 | this.labels = resp; | |
383 | }); | |
384 | this.poolService.getList().subscribe((resp: Array<object>) => { | |
385 | this.pools = resp; | |
386 | }); | |
a4b75251 TL |
387 | |
388 | if (this.editing) { | |
389 | this.action = this.actionLabels.EDIT; | |
390 | this.disableForEditing(this.serviceType); | |
39ae355f TL |
391 | this.cephServiceService |
392 | .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName) | |
393 | .observable.subscribe((response: CephServiceSpec[]) => { | |
394 | const formKeys = ['service_type', 'service_id', 'unmanaged']; | |
395 | formKeys.forEach((keys) => { | |
396 | this.serviceForm.get(keys).setValue(response[0][keys]); | |
397 | }); | |
398 | if (!response[0]['unmanaged']) { | |
399 | const placementKey = Object.keys(response[0]['placement'])[0]; | |
400 | let placementValue: string; | |
401 | ['hosts', 'label'].indexOf(placementKey) >= 0 | |
402 | ? (placementValue = placementKey) | |
403 | : (placementValue = 'hosts'); | |
404 | this.serviceForm.get('placement').setValue(placementValue); | |
405 | this.serviceForm.get('count').setValue(response[0]['placement']['count']); | |
406 | if (response[0]?.placement[placementValue]) { | |
407 | this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]); | |
a4b75251 | 408 | } |
39ae355f TL |
409 | } |
410 | switch (this.serviceType) { | |
411 | case 'iscsi': | |
412 | const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port']; | |
413 | specKeys.forEach((key) => { | |
414 | this.serviceForm.get(key).setValue(response[0].spec[key]); | |
415 | }); | |
416 | this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure); | |
417 | if (response[0].spec?.api_secure) { | |
418 | this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert); | |
419 | this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key); | |
420 | } | |
421 | break; | |
422 | case 'rgw': | |
a4b75251 | 423 | this.serviceForm |
39ae355f TL |
424 | .get('rgw_frontend_port') |
425 | .setValue(response[0].spec?.rgw_frontend_port); | |
426 | this.serviceForm.get('ssl').setValue(response[0].spec?.ssl); | |
427 | if (response[0].spec?.ssl) { | |
428 | this.serviceForm | |
429 | .get('ssl_cert') | |
430 | .setValue(response[0].spec?.rgw_frontend_ssl_certificate); | |
431 | } | |
432 | break; | |
433 | case 'ingress': | |
434 | const ingressSpecKeys = [ | |
435 | 'backend_service', | |
436 | 'virtual_ip', | |
437 | 'frontend_port', | |
438 | 'monitor_port', | |
439 | 'virtual_interface_networks', | |
440 | 'ssl' | |
20effc67 | 441 | ]; |
39ae355f TL |
442 | ingressSpecKeys.forEach((key) => { |
443 | this.serviceForm.get(key).setValue(response[0].spec[key]); | |
20effc67 | 444 | }); |
39ae355f TL |
445 | if (response[0].spec?.ssl) { |
446 | this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert); | |
447 | this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key); | |
448 | } | |
449 | break; | |
450 | case 'snmp-gateway': | |
451 | const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination']; | |
452 | snmpCommonSpecKeys.forEach((key) => { | |
453 | this.serviceForm.get(key).setValue(response[0].spec[key]); | |
454 | }); | |
455 | if (this.serviceForm.getValue('snmp_version') === 'V3') { | |
456 | const snmpV3SpecKeys = [ | |
457 | 'engine_id', | |
458 | 'auth_protocol', | |
459 | 'privacy_protocol', | |
460 | 'snmp_v3_auth_username', | |
461 | 'snmp_v3_auth_password', | |
462 | 'snmp_v3_priv_password' | |
463 | ]; | |
464 | snmpV3SpecKeys.forEach((key) => { | |
465 | if (key !== null) { | |
466 | if ( | |
467 | key === 'snmp_v3_auth_username' || | |
468 | key === 'snmp_v3_auth_password' || | |
469 | key === 'snmp_v3_priv_password' | |
470 | ) { | |
471 | this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]); | |
472 | } else { | |
473 | this.serviceForm.get(key).setValue(response[0].spec[key]); | |
474 | } | |
475 | } | |
476 | }); | |
477 | } else { | |
478 | this.serviceForm | |
479 | .get('snmp_community') | |
480 | .setValue(response[0].spec['credentials']['snmp_community']); | |
481 | } | |
482 | break; | |
483 | } | |
484 | }); | |
a4b75251 | 485 | } |
adb31ebb TL |
486 | } |
487 | ||
2a845540 TL |
488 | getServiceIds(selectedServiceType: string) { |
489 | this.serviceIds = this.serviceList | |
39ae355f | 490 | ?.filter((service) => service['service_type'] === selectedServiceType) |
2a845540 TL |
491 | .map((service) => service['service_id']); |
492 | } | |
493 | ||
a4b75251 TL |
494 | disableForEditing(serviceType: string) { |
495 | const disableForEditKeys = ['service_type', 'service_id']; | |
496 | disableForEditKeys.forEach((key) => { | |
497 | this.serviceForm.get(key).disable(); | |
498 | }); | |
499 | switch (serviceType) { | |
500 | case 'ingress': | |
501 | this.serviceForm.get('backend_service').disable(); | |
502 | } | |
adb31ebb TL |
503 | } |
504 | ||
f67539c2 TL |
505 | searchLabels = (text$: Observable<string>) => { |
506 | return merge( | |
507 | text$.pipe(debounceTime(200), distinctUntilChanged()), | |
508 | this.labelFocus, | |
509 | this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen())) | |
510 | ).pipe( | |
511 | map((value) => | |
512 | this.labels | |
513 | .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1) | |
514 | .slice(0, 10) | |
515 | ) | |
516 | ); | |
517 | }; | |
518 | ||
adb31ebb TL |
519 | fileUpload(files: FileList, controlName: string) { |
520 | const file: File = files[0]; | |
521 | const reader = new FileReader(); | |
f67539c2 | 522 | reader.addEventListener('load', (event: ProgressEvent<FileReader>) => { |
adb31ebb | 523 | const control: AbstractControl = this.serviceForm.get(controlName); |
f67539c2 | 524 | control.setValue(event.target.result); |
adb31ebb TL |
525 | control.markAsDirty(); |
526 | control.markAsTouched(); | |
527 | control.updateValueAndValidity(); | |
528 | }); | |
529 | reader.readAsText(file, 'utf8'); | |
530 | } | |
531 | ||
b3b6e05e TL |
532 | prePopulateId() { |
533 | const control: AbstractControl = this.serviceForm.get('service_id'); | |
534 | const backendService = this.serviceForm.getValue('backend_service'); | |
535 | // Set Id as read-only | |
536 | control.reset({ value: backendService, disabled: true }); | |
537 | } | |
538 | ||
adb31ebb TL |
539 | onSubmit() { |
540 | const self = this; | |
a4b75251 | 541 | const values: object = this.serviceForm.getRawValue(); |
adb31ebb | 542 | const serviceType: string = values['service_type']; |
a4b75251 TL |
543 | let taskUrl = `service/${URLVerbs.CREATE}`; |
544 | if (this.editing) { | |
545 | taskUrl = `service/${URLVerbs.EDIT}`; | |
546 | } | |
adb31ebb TL |
547 | const serviceSpec: object = { |
548 | service_type: serviceType, | |
549 | placement: {}, | |
550 | unmanaged: values['unmanaged'] | |
551 | }; | |
522d829b TL |
552 | let svcId: string; |
553 | if (serviceType === 'rgw') { | |
554 | const svcIdMatch = values['service_id'].match(this.RGW_SVC_ID_PATTERN); | |
555 | svcId = svcIdMatch[1]; | |
556 | if (svcIdMatch[3]) { | |
557 | serviceSpec['rgw_realm'] = svcIdMatch[3]; | |
558 | serviceSpec['rgw_zone'] = svcIdMatch[4]; | |
559 | } | |
560 | } else { | |
561 | svcId = values['service_id']; | |
562 | } | |
563 | const serviceId: string = svcId; | |
adb31ebb TL |
564 | let serviceName: string = serviceType; |
565 | if (_.isString(serviceId) && !_.isEmpty(serviceId)) { | |
566 | serviceName = `${serviceType}.${serviceId}`; | |
567 | serviceSpec['service_id'] = serviceId; | |
568 | } | |
2a845540 TL |
569 | |
570 | // These services has some fields to be | |
571 | // filled out even if unmanaged is true | |
572 | switch (serviceType) { | |
573 | case 'ingress': | |
574 | serviceSpec['backend_service'] = values['backend_service']; | |
575 | serviceSpec['service_id'] = values['backend_service']; | |
576 | if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) { | |
577 | serviceSpec['frontend_port'] = values['frontend_port']; | |
578 | } | |
579 | if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) { | |
580 | serviceSpec['virtual_ip'] = values['virtual_ip'].trim(); | |
581 | } | |
582 | if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) { | |
583 | serviceSpec['monitor_port'] = values['monitor_port']; | |
584 | } | |
585 | break; | |
586 | ||
587 | case 'iscsi': | |
588 | serviceSpec['pool'] = values['pool']; | |
589 | break; | |
590 | ||
591 | case 'snmp-gateway': | |
592 | serviceSpec['credentials'] = {}; | |
593 | serviceSpec['snmp_version'] = values['snmp_version']; | |
594 | serviceSpec['snmp_destination'] = values['snmp_destination']; | |
595 | if (values['snmp_version'] === 'V3') { | |
596 | serviceSpec['engine_id'] = values['engine_id']; | |
597 | serviceSpec['auth_protocol'] = values['auth_protocol']; | |
598 | serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username']; | |
599 | serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password']; | |
600 | if (values['privacy_protocol'] !== null) { | |
601 | serviceSpec['privacy_protocol'] = values['privacy_protocol']; | |
602 | serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password']; | |
603 | } | |
604 | } else { | |
605 | serviceSpec['credentials']['snmp_community'] = values['snmp_community']; | |
606 | } | |
607 | break; | |
608 | } | |
609 | ||
adb31ebb TL |
610 | if (!values['unmanaged']) { |
611 | switch (values['placement']) { | |
612 | case 'hosts': | |
613 | if (values['hosts'].length > 0) { | |
614 | serviceSpec['placement']['hosts'] = values['hosts']; | |
615 | } | |
616 | break; | |
617 | case 'label': | |
618 | serviceSpec['placement']['label'] = values['label']; | |
619 | break; | |
620 | } | |
621 | if (_.isNumber(values['count']) && values['count'] > 0) { | |
622 | serviceSpec['placement']['count'] = values['count']; | |
623 | } | |
624 | switch (serviceType) { | |
adb31ebb TL |
625 | case 'rgw': |
626 | if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) { | |
627 | serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port']; | |
628 | } | |
629 | serviceSpec['ssl'] = values['ssl']; | |
630 | if (values['ssl']) { | |
a4b75251 | 631 | serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim(); |
adb31ebb TL |
632 | } |
633 | break; | |
634 | case 'iscsi': | |
adb31ebb | 635 | if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) { |
f67539c2 | 636 | serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim(); |
adb31ebb TL |
637 | } |
638 | if (_.isNumber(values['api_port']) && values['api_port'] > 0) { | |
639 | serviceSpec['api_port'] = values['api_port']; | |
640 | } | |
641 | serviceSpec['api_user'] = values['api_user']; | |
642 | serviceSpec['api_password'] = values['api_password']; | |
643 | serviceSpec['api_secure'] = values['ssl']; | |
644 | if (values['ssl']) { | |
a4b75251 TL |
645 | serviceSpec['ssl_cert'] = values['ssl_cert']?.trim(); |
646 | serviceSpec['ssl_key'] = values['ssl_key']?.trim(); | |
adb31ebb TL |
647 | } |
648 | break; | |
b3b6e05e | 649 | case 'ingress': |
b3b6e05e TL |
650 | serviceSpec['ssl'] = values['ssl']; |
651 | if (values['ssl']) { | |
a4b75251 TL |
652 | serviceSpec['ssl_cert'] = values['ssl_cert']?.trim(); |
653 | serviceSpec['ssl_key'] = values['ssl_key']?.trim(); | |
b3b6e05e TL |
654 | } |
655 | serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks']; | |
656 | break; | |
adb31ebb TL |
657 | } |
658 | } | |
a4b75251 | 659 | |
adb31ebb TL |
660 | this.taskWrapperService |
661 | .wrapTaskAroundCall({ | |
a4b75251 | 662 | task: new FinishedTask(taskUrl, { |
adb31ebb TL |
663 | service_name: serviceName |
664 | }), | |
2a845540 TL |
665 | call: this.editing |
666 | ? this.cephServiceService.update(serviceSpec) | |
667 | : this.cephServiceService.create(serviceSpec) | |
adb31ebb TL |
668 | }) |
669 | .subscribe({ | |
670 | error() { | |
671 | self.serviceForm.setErrors({ cdSubmitButton: true }); | |
672 | }, | |
a4b75251 TL |
673 | complete: () => { |
674 | this.pageURL === 'services' | |
675 | ? this.router.navigate([this.pageURL, { outlets: { modal: null } }]) | |
676 | : this.activeModal.close(); | |
adb31ebb TL |
677 | } |
678 | }); | |
679 | } | |
20effc67 TL |
680 | |
681 | clearValidations() { | |
682 | const snmpVersion = this.serviceForm.getValue('snmp_version'); | |
683 | const privacyProtocol = this.serviceForm.getValue('privacy_protocol'); | |
684 | if (snmpVersion === 'V3') { | |
685 | this.serviceForm.get('snmp_community').clearValidators(); | |
686 | } else { | |
687 | this.serviceForm.get('engine_id').clearValidators(); | |
688 | this.serviceForm.get('auth_protocol').clearValidators(); | |
689 | this.serviceForm.get('privacy_protocol').clearValidators(); | |
690 | this.serviceForm.get('snmp_v3_auth_username').clearValidators(); | |
691 | this.serviceForm.get('snmp_v3_auth_password').clearValidators(); | |
692 | } | |
693 | if (privacyProtocol === null) { | |
694 | this.serviceForm.get('snmp_v3_priv_password').clearValidators(); | |
695 | } | |
696 | } | |
adb31ebb | 697 | } |