]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
2b6ddeee0e09d419548e2b1e30e2ca8878874600
[ceph-ci.git] /
1 import { HttpParams } from '@angular/common/http';
2 import { Component, Input, OnInit, ViewChild } from '@angular/core';
3 import { AbstractControl, UntypedFormControl, Validators } from '@angular/forms';
4 import { ActivatedRoute, Router } from '@angular/router';
5
6 import { NgbActiveModal, NgbModalRef, NgbTypeahead } from '@ng-bootstrap/ng-bootstrap';
7 import { ListItem } from 'carbon-components-angular';
8 import _ from 'lodash';
9 import { forkJoin, merge, Observable, Subject, Subscription } from 'rxjs';
10 import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators';
11 import { Pool } from '~/app/ceph/pool/pool';
12 import { CreateRgwServiceEntitiesComponent } from '~/app/ceph/rgw/create-rgw-service-entities/create-rgw-service-entities.component';
13 import { RgwRealm, RgwZonegroup, RgwZone } from '~/app/ceph/rgw/models/rgw-multisite';
14
15 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
16 import { HostService } from '~/app/shared/api/host.service';
17 import { PoolService } from '~/app/shared/api/pool.service';
18 import { RbdService } from '~/app/shared/api/rbd.service';
19 import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
20 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
21 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
22 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
23 import { SelectMessages } from '~/app/shared/components/select/select-messages.model';
24 import { SelectOption } from '~/app/shared/components/select/select-option.model';
25 import {
26   ActionLabelsI18n,
27   TimerServiceInterval,
28   URLVerbs,
29   SSL_PROTOCOLS,
30   SSL_CIPHERS
31 } from '~/app/shared/constants/app.constants';
32 import { CdForm } from '~/app/shared/forms/cd-form';
33 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
34 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
35 import { CdValidators } from '~/app/shared/forms/cd-validators';
36 import { FinishedTask } from '~/app/shared/models/finished-task';
37 import { Host } from '~/app/shared/models/host.interface';
38 import { CephServiceSpec, QatOptions, QatSepcs } from '~/app/shared/models/service.interface';
39 import { ModalService } from '~/app/shared/services/modal.service';
40 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
41 import { TimerService } from '~/app/shared/services/timer.service';
42
43 @Component({
44   selector: 'cd-service-form',
45   templateUrl: './service-form.component.html',
46   styleUrls: ['./service-form.component.scss']
47 })
48 export class ServiceFormComponent extends CdForm implements OnInit {
49   public sub = new Subscription();
50
51   readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
52   readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
53   readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
54   readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
55   readonly SMB_CONFIG_URI_PATTERN = /^(http:|https:|rados:|rados:mon-config-key:)/;
56   readonly OAUTH2_ISSUER_URL_PATTERN = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)(:[0-9]{1,5})?(\/.*)?$/;
57   readonly SSL_CIPHERS_PATTERN = /^[a-zA-Z0-9\-:]+$/;
58   readonly DEFAULT_SSL_PROTOCOL_ITEM = [{ content: 'TLSv1.3', selected: true }];
59   @ViewChild(NgbTypeahead, { static: false })
60   typeahead: NgbTypeahead;
61
62   @Input() hiddenServices: string[] = [];
63
64   @Input() editing = false;
65
66   @Input() serviceName: string;
67
68   @Input() serviceType: string;
69
70   serviceForm: CdFormGroup;
71   action: string;
72   resource: string;
73   serviceTypes: string[] = [];
74   serviceIds: string[] = [];
75   hosts: any;
76   labels: string[];
77   labelClick = new Subject<string>();
78   labelFocus = new Subject<string>();
79   pools: Array<Pool>;
80   rbdPools: Array<Pool>;
81   services: Array<CephServiceSpec> = [];
82   pageURL: string;
83   serviceList: CephServiceSpec[];
84   multisiteInfo: object[] = [];
85   defaultRealmId = '';
86   defaultZonegroupId = '';
87   defaultZoneId = '';
88   realmList: RgwRealm[] = [];
89   zonegroupList: RgwZonegroup[] = [];
90   zoneList: RgwZone[] = [];
91   bsModalRef: NgbModalRef;
92   defaultZonegroup: RgwZonegroup;
93   showRealmCreationForm = false;
94   defaultsInfo: { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string };
95   realmNames: string[];
96   zonegroupNames: string[];
97   zoneNames: string[];
98   smbFeaturesList = ['domain'];
99   currentURL: string;
100   port: number = 443;
101   sslProtocolsItems: Array<ListItem> = Object.values(SSL_PROTOCOLS).map((protocol) => ({
102     content: protocol,
103     selected: true
104   }));
105   sslCiphersItems: Array<ListItem> = Object.values(SSL_CIPHERS).map((cipher) => ({
106     content: cipher,
107     selected: false
108   }));
109   showMgmtGatewayMessage: boolean = false;
110   qatCompressionOptions = [
111     { value: QatOptions.hw, label: 'Hardware' },
112     { value: QatOptions.sw, label: 'Software' },
113     { value: QatOptions.none, label: 'None' }
114   ];
115
116   constructor(
117     public actionLabels: ActionLabelsI18n,
118     private cephServiceService: CephServiceService,
119     private formBuilder: CdFormBuilder,
120     private hostService: HostService,
121     private poolService: PoolService,
122     private rbdService: RbdService,
123     private router: Router,
124     private taskWrapperService: TaskWrapperService,
125     public timerService: TimerService,
126     public timerServiceVariable: TimerServiceInterval,
127     public rgwRealmService: RgwRealmService,
128     public rgwZonegroupService: RgwZonegroupService,
129     public rgwZoneService: RgwZoneService,
130     public rgwMultisiteService: RgwMultisiteService,
131     private route: ActivatedRoute,
132     public activeModal: NgbActiveModal,
133     public modalService: ModalService
134   ) {
135     super();
136     this.resource = $localize`service`;
137     this.hosts = {
138       options: [],
139       messages: new SelectMessages({
140         empty: $localize`There are no hosts.`,
141         filter: $localize`Filter hosts`
142       })
143     };
144     this.createForm();
145   }
146
147   createForm() {
148     this.serviceForm = this.formBuilder.group({
149       // Global
150       service_type: [null, [Validators.required]],
151       service_id: [
152         null,
153         [
154           CdValidators.composeIf(
155             {
156               service_type: 'mds'
157             },
158             [
159               Validators.required,
160               CdValidators.custom('mdsPattern', (value: string) => {
161                 if (_.isEmpty(value)) {
162                   return false;
163                 }
164                 return !this.MDS_SVC_ID_PATTERN.test(value);
165               })
166             ]
167           ),
168           CdValidators.requiredIf({
169             service_type: 'nfs'
170           }),
171           CdValidators.requiredIf({
172             service_type: 'iscsi'
173           }),
174           CdValidators.requiredIf({
175             service_type: 'nvmeof'
176           }),
177           CdValidators.requiredIf({
178             service_type: 'ingress'
179           }),
180           CdValidators.requiredIf({
181             service_type: 'smb'
182           }),
183           CdValidators.composeIf(
184             {
185               service_type: 'rgw'
186             },
187             [Validators.required]
188           ),
189           CdValidators.custom('uniqueName', (service_id: string) => {
190             return this.serviceIds && this.serviceIds.includes(service_id);
191           })
192         ]
193       ],
194       placement: ['hosts'],
195       label: [
196         null,
197         [
198           CdValidators.requiredIf({
199             placement: 'label',
200             unmanaged: false
201           })
202         ]
203       ],
204       hosts: [[]],
205       count: [null, [CdValidators.number(false)]],
206       unmanaged: [false],
207       // iSCSI
208       // NVMe/TCP
209       pool: [
210         null,
211         [
212           CdValidators.requiredIf({
213             service_type: 'iscsi'
214           }),
215           CdValidators.requiredIf({
216             service_type: 'nvmeof'
217           })
218         ]
219       ],
220       group: [
221         'default',
222         CdValidators.requiredIf({
223           service_type: 'nvmeof'
224         })
225       ],
226       enable_mtls: [false],
227       root_ca_cert: [
228         null,
229         [
230           CdValidators.composeIf(
231             {
232               service_type: 'nvmeof',
233               enable_mtls: true
234             },
235             [Validators.required]
236           )
237         ]
238       ],
239       client_cert: [
240         null,
241         [
242           CdValidators.composeIf(
243             {
244               service_type: 'nvmeof',
245               enable_mtls: true
246             },
247             [Validators.required]
248           )
249         ]
250       ],
251       client_key: [
252         null,
253         [
254           CdValidators.composeIf(
255             {
256               service_type: 'nvmeof',
257               enable_mtls: true
258             },
259             [Validators.required]
260           )
261         ]
262       ],
263       server_cert: [
264         null,
265         [
266           CdValidators.composeIf(
267             {
268               service_type: 'nvmeof',
269               enable_mtls: true
270             },
271             [Validators.required]
272           )
273         ]
274       ],
275       server_key: [
276         null,
277         [
278           CdValidators.composeIf(
279             {
280               service_type: 'nvmeof',
281               enable_mtls: true
282             },
283             [Validators.required]
284           )
285         ]
286       ],
287       // RGW
288       rgw_frontend_port: [null, [CdValidators.number(false)]],
289       realm_name: [null],
290       zonegroup_name: [null],
291       zone_name: [null],
292       qat: new CdFormGroup({
293         compression: new UntypedFormControl(QatOptions.none)
294       }),
295       // iSCSI
296       trusted_ip_list: [null],
297       api_port: [null, [CdValidators.number(false)]],
298       api_user: [
299         null,
300         [
301           CdValidators.requiredIf({
302             service_type: 'iscsi',
303             unmanaged: false
304           })
305         ]
306       ],
307       api_password: [
308         null,
309         [
310           CdValidators.requiredIf({
311             service_type: 'iscsi',
312             unmanaged: false
313           })
314         ]
315       ],
316       // smb
317       cluster_id: [
318         null,
319         [
320           CdValidators.requiredIf({
321             service_type: 'smb'
322           })
323         ]
324       ],
325       features: new CdFormGroup(
326         this.smbFeaturesList.reduce((acc: object, e) => {
327           acc[e] = new UntypedFormControl(false);
328           return acc;
329         }, {})
330       ),
331       config_uri: [
332         null,
333         [
334           CdValidators.composeIf(
335             {
336               service_type: 'smb'
337             },
338             [
339               Validators.required,
340               CdValidators.custom('configUriPattern', (value: string) => {
341                 if (_.isEmpty(value)) {
342                   return false;
343                 }
344                 return !this.SMB_CONFIG_URI_PATTERN.test(value);
345               })
346             ]
347           )
348         ]
349       ],
350       custom_dns: [null],
351       join_sources: [null],
352       user_sources: [null],
353       include_ceph_users: [null],
354       // Ingress
355       backend_service: [
356         null,
357         [
358           CdValidators.requiredIf({
359             service_type: 'ingress'
360           })
361         ]
362       ],
363       virtual_ip: [
364         null,
365         [
366           CdValidators.requiredIf({
367             service_type: 'ingress'
368           })
369         ]
370       ],
371       frontend_port: [
372         null,
373         [
374           CdValidators.number(false),
375           CdValidators.requiredIf({
376             service_type: 'ingress'
377           })
378         ]
379       ],
380       monitor_port: [
381         null,
382         [
383           CdValidators.number(false),
384           CdValidators.requiredIf({
385             service_type: 'ingress'
386           })
387         ]
388       ],
389       virtual_interface_networks: [null],
390       ssl_protocols: [this.DEFAULT_SSL_PROTOCOL_ITEM],
391       ssl_ciphers: [
392         null,
393         [
394           CdValidators.custom('invalidPattern', (ciphers: string) => {
395             if (_.isEmpty(ciphers)) {
396               return false;
397             }
398             return !this.SSL_CIPHERS_PATTERN.test(ciphers);
399           })
400         ]
401       ],
402       // RGW, Ingress & iSCSI
403       ssl: [false],
404       ssl_cert: [
405         '',
406         [
407           CdValidators.composeIf(
408             {
409               service_type: 'rgw',
410               unmanaged: false,
411               ssl: true
412             },
413             [Validators.required, CdValidators.pemCert()]
414           ),
415           CdValidators.composeIf(
416             {
417               service_type: 'iscsi',
418               unmanaged: false,
419               ssl: true
420             },
421             [Validators.required, CdValidators.sslCert()]
422           ),
423           CdValidators.composeIf(
424             {
425               service_type: 'ingress',
426               unmanaged: false,
427               ssl: true
428             },
429             [Validators.required, CdValidators.pemCert()]
430           ),
431           CdValidators.composeIf(
432             {
433               service_type: 'oauth2-proxy',
434               unmanaged: false,
435               ssl: true
436             },
437             [Validators.required, CdValidators.sslCert()]
438           ),
439           CdValidators.composeIf(
440             {
441               service_type: 'mgmt-gateway',
442               unmanaged: false,
443               ssl: false
444             },
445             [CdValidators.sslCert()]
446           )
447         ]
448       ],
449       ssl_key: [
450         '',
451         [
452           CdValidators.composeIf(
453             {
454               service_type: 'iscsi',
455               unmanaged: false,
456               ssl: true
457             },
458             [Validators.required, CdValidators.sslPrivKey()]
459           ),
460           CdValidators.composeIf(
461             {
462               service_type: 'oauth2-proxy',
463               unmanaged: false,
464               ssl: true
465             },
466             [Validators.required, CdValidators.sslPrivKey()]
467           ),
468           CdValidators.composeIf(
469             {
470               service_type: 'mgmt-gateway',
471               unmanaged: false,
472               ssl: false
473             },
474             [CdValidators.sslPrivKey()]
475           )
476         ]
477       ],
478       // mgmt-gateway
479       enable_auth: [null],
480       port: [443, [CdValidators.number(false)]],
481       // snmp-gateway
482       snmp_version: [
483         null,
484         [
485           CdValidators.requiredIf({
486             service_type: 'snmp-gateway'
487           })
488         ]
489       ],
490       snmp_destination: [
491         null,
492         {
493           validators: [
494             CdValidators.requiredIf({
495               service_type: 'snmp-gateway'
496             }),
497             CdValidators.custom('snmpDestinationPattern', (value: string) => {
498               if (_.isEmpty(value)) {
499                 return false;
500               }
501               return !this.SNMP_DESTINATION_PATTERN.test(value);
502             })
503           ]
504         }
505       ],
506       engine_id: [
507         null,
508         [
509           CdValidators.requiredIf({
510             service_type: 'snmp-gateway'
511           }),
512           CdValidators.custom('snmpEngineIdPattern', (value: string) => {
513             if (_.isEmpty(value)) {
514               return false;
515             }
516             return !this.SNMP_ENGINE_ID_PATTERN.test(value);
517           })
518         ]
519       ],
520       auth_protocol: [
521         'SHA',
522         [
523           CdValidators.requiredIf({
524             service_type: 'snmp-gateway'
525           })
526         ]
527       ],
528       privacy_protocol: [null],
529       snmp_community: [
530         null,
531         [
532           CdValidators.requiredIf({
533             snmp_version: 'V2c'
534           })
535         ]
536       ],
537       snmp_v3_auth_username: [
538         null,
539         [
540           CdValidators.requiredIf({
541             service_type: 'snmp-gateway'
542           })
543         ]
544       ],
545       snmp_v3_auth_password: [
546         null,
547         [
548           CdValidators.requiredIf({
549             service_type: 'snmp-gateway'
550           })
551         ]
552       ],
553       snmp_v3_priv_password: [
554         null,
555         [
556           CdValidators.requiredIf({
557             privacy_protocol: { op: '!empty' }
558           })
559         ]
560       ],
561       grafana_port: [null, [CdValidators.number(false)]],
562       grafana_admin_password: [null],
563       // oauth2-proxy
564       provider_display_name: [
565         'My OIDC provider',
566         [
567           CdValidators.requiredIf({
568             service_type: 'oauth2-proxy'
569           })
570         ]
571       ],
572       client_id: [
573         null,
574         [
575           CdValidators.requiredIf({
576             service_type: 'oauth2-proxy'
577           })
578         ]
579       ],
580       client_secret: [
581         null,
582         [
583           CdValidators.requiredIf({
584             service_type: 'oauth2-proxy'
585           })
586         ]
587       ],
588       oidc_issuer_url: [
589         null,
590         [
591           CdValidators.requiredIf({
592             service_type: 'oauth2-proxy'
593           }),
594           CdValidators.custom('validUrl', (url: string) => {
595             if (_.isEmpty(url)) {
596               return false;
597             }
598             return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
599           })
600         ]
601       ],
602       https_address: [null, [CdValidators.oauthAddressTest()]],
603       redirect_url: [null],
604       allowlist_domains: [null]
605     });
606   }
607
608   resolveRoute() {
609     if (this.router.url.includes('services/(modal:create')) {
610       this.pageURL = 'services';
611       this.route.params.subscribe((params: { type: string }) => {
612         if (params?.type) {
613           this.serviceType = params.type;
614           this.serviceForm.get('service_type').setValue(this.serviceType);
615         }
616       });
617     } else if (this.router.url.includes('services/(modal:edit')) {
618       this.editing = true;
619       this.pageURL = 'services';
620       this.route.params.subscribe((params: { type: string; name: string }) => {
621         this.serviceName = params.name;
622         this.serviceType = params.type;
623       });
624     }
625   }
626
627   ngOnInit(): void {
628     this.action = this.actionLabels.CREATE;
629     this.resolveRoute();
630
631     this.cephServiceService
632       .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
633       .observable.subscribe((services: CephServiceSpec[]) => {
634         this.serviceList = services;
635         this.services = services.filter((service: any) =>
636           this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
637         );
638       });
639
640     this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
641       // Remove service types:
642       // osd       - This is deployed a different way.
643       // container - This should only be used in the CLI.
644       this.hiddenServices.push('osd', 'container');
645
646       this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
647     });
648     this.hostService.getAllHosts().subscribe((resp: Host[]) => {
649       const options: SelectOption[] = [];
650       _.forEach(resp, (host: Host) => {
651         if (_.get(host, 'sources.orchestrator', false)) {
652           const option = new SelectOption(false, _.get(host, 'hostname'), '');
653           options.push(option);
654         }
655       });
656       this.hosts.options = [...options];
657     });
658     this.hostService.getLabels().subscribe((resp: string[]) => {
659       this.labels = resp;
660     });
661     this.poolService.getList().subscribe((resp: Pool[]) => {
662       this.pools = resp;
663       this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
664       if (!this.editing && this.serviceType) {
665         this.onServiceTypeChange(this.serviceType);
666       }
667     });
668
669     if (this.editing) {
670       this.action = this.actionLabels.EDIT;
671       this.disableForEditing(this.serviceType);
672       this.cephServiceService
673         .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
674         .observable.subscribe((response: CephServiceSpec[]) => {
675           const formKeys = ['service_type', 'service_id', 'unmanaged'];
676           formKeys.forEach((keys) => {
677             this.serviceForm.get(keys).setValue(response[0][keys]);
678           });
679           if (!response[0]['unmanaged']) {
680             const placementKey = Object.keys(response[0]['placement'])[0];
681             let placementValue: string;
682             ['hosts', 'label'].indexOf(placementKey) >= 0
683               ? (placementValue = placementKey)
684               : (placementValue = 'hosts');
685             this.serviceForm.get('placement').setValue(placementValue);
686             this.serviceForm.get('count').setValue(response[0]['placement']['count']);
687             if (response[0]?.placement[placementValue]) {
688               this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
689             }
690           }
691           switch (this.serviceType) {
692             case 'iscsi':
693               const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
694               specKeys.forEach((key) => {
695                 this.serviceForm.get(key).setValue(response[0].spec[key]);
696               });
697               this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
698               if (response[0].spec?.api_secure) {
699                 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
700                 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
701               }
702               break;
703             case 'nvmeof':
704               this.serviceForm.get('pool').setValue(response[0].spec.pool);
705               this.serviceForm.get('group').setValue(response[0].spec.group);
706               this.serviceForm.get('enable_mtls').setValue(response[0].spec?.enable_auth);
707               this.serviceForm.get('root_ca_cert').setValue(response[0].spec?.root_ca_cert);
708               this.serviceForm.get('client_cert').setValue(response[0].spec?.client_cert);
709               this.serviceForm.get('client_key').setValue(response[0].spec?.client_key);
710               this.serviceForm.get('server_cert').setValue(response[0].spec?.server_cert);
711               this.serviceForm.get('server_key').setValue(response[0].spec?.server_key);
712               break;
713             case 'rgw':
714               this.serviceForm
715                 .get('rgw_frontend_port')
716                 .setValue(response[0].spec?.rgw_frontend_port);
717               this.setRgwFields(
718                 response[0].spec?.rgw_realm,
719                 response[0].spec?.rgw_zonegroup,
720                 response[0].spec?.rgw_zone,
721                 response[0].spec?.qat
722               );
723               this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
724               if (response[0].spec?.ssl) {
725                 this.serviceForm
726                   .get('ssl_cert')
727                   .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
728               }
729               break;
730             case 'ingress':
731               const ingressSpecKeys = [
732                 'backend_service',
733                 'virtual_ip',
734                 'frontend_port',
735                 'monitor_port',
736                 'virtual_interface_networks',
737                 'ssl'
738               ];
739               ingressSpecKeys.forEach((key) => {
740                 this.serviceForm.get(key).setValue(response[0].spec[key]);
741               });
742               if (response[0].spec?.ssl) {
743                 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
744                 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
745               }
746               break;
747             case 'mgmt-gateway':
748               let hrefSplitted = window.location.href.split(':');
749               this.currentURL = hrefSplitted[0] + hrefSplitted[1];
750               this.port = response[0].spec?.port;
751
752               if (response[0].spec?.ssl_protocols) {
753                 let selectedValues: Array<ListItem> = [];
754                 for (const value of response[0].spec.ssl_protocols) {
755                   selectedValues.push({ content: value, selected: true });
756                 }
757                 this.serviceForm.get('ssl_protocols').setValue(selectedValues);
758               }
759               if (response[0].spec?.ssl_ciphers) {
760                 this.serviceForm
761                   .get('ssl_ciphers')
762                   .setValue(response[0].spec?.ssl_ciphers.join(':'));
763               }
764               if (response[0].spec?.ssl_cert) {
765                 this.serviceForm.get('ssl_cert').setValue(response[0].spec.ssl_cert);
766               }
767               if (response[0].spec?.ssl_key) {
768                 this.serviceForm.get('ssl_key').setValue(response[0].spec.ssl_key);
769               }
770               if (response[0].spec?.enable_auth) {
771                 this.serviceForm.get('enable_auth').setValue(response[0].spec.enable_auth);
772               }
773               if (response[0].spec?.port) {
774                 this.serviceForm.get('port').setValue(response[0].spec.port);
775               }
776               break;
777             case 'smb':
778               const smbSpecKeys = [
779                 'cluster_id',
780                 'config_uri',
781                 'features',
782                 'join_sources',
783                 'user_sources',
784                 'custom_dns',
785                 'include_ceph_users'
786               ];
787               smbSpecKeys.forEach((key) => {
788                 if (key === 'features') {
789                   if (response[0].spec?.features) {
790                     response[0].spec.features.forEach((feature) => {
791                       this.serviceForm.get(`features.${feature}`).setValue(true);
792                     });
793                   }
794                 } else {
795                   this.serviceForm.get(key).setValue(response[0].spec[key]);
796                 }
797               });
798               break;
799             case 'snmp-gateway':
800               const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
801               snmpCommonSpecKeys.forEach((key) => {
802                 this.serviceForm.get(key).setValue(response[0].spec[key]);
803               });
804               if (this.serviceForm.getValue('snmp_version') === 'V3') {
805                 const snmpV3SpecKeys = [
806                   'engine_id',
807                   'auth_protocol',
808                   'privacy_protocol',
809                   'snmp_v3_auth_username',
810                   'snmp_v3_auth_password',
811                   'snmp_v3_priv_password'
812                 ];
813                 snmpV3SpecKeys.forEach((key) => {
814                   if (key !== null) {
815                     if (
816                       key === 'snmp_v3_auth_username' ||
817                       key === 'snmp_v3_auth_password' ||
818                       key === 'snmp_v3_priv_password'
819                     ) {
820                       this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
821                     } else {
822                       this.serviceForm.get(key).setValue(response[0].spec[key]);
823                     }
824                   }
825                 });
826               } else {
827                 this.serviceForm
828                   .get('snmp_community')
829                   .setValue(response[0].spec['credentials']['snmp_community']);
830               }
831               break;
832             case 'grafana':
833               this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
834               this.serviceForm
835                 .get('grafana_admin_password')
836                 .setValue(response[0].spec.initial_admin_password);
837               break;
838             case 'oauth2-proxy':
839               const oauth2SpecKeys = [
840                 'https_address',
841                 'provider_display_name',
842                 'client_id',
843                 'client_secret',
844                 'oidc_issuer_url',
845                 'redirect_url',
846                 'allowlist_domains'
847               ];
848               oauth2SpecKeys.forEach((key) => {
849                 this.serviceForm.get(key).setValue(response[0].spec[key]);
850               });
851               if (response[0].spec?.ssl) {
852                 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
853                 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
854               }
855           }
856         });
857     }
858     this.detectChanges();
859   }
860
861   detectChanges(): void {
862     const service_type = this.serviceForm.get('service_type');
863     if (service_type) {
864       service_type.valueChanges.subscribe((value) => {
865         if (value === 'mgmt-gateway') {
866           const port = this.serviceForm.get('port');
867           if (port) {
868             port.valueChanges.subscribe((_) => {
869               this.showMgmtGatewayMessage = true;
870             });
871           }
872           const ssl_protocols = this.serviceForm.get('ssl_protocols');
873           if (ssl_protocols) {
874             ssl_protocols.valueChanges.subscribe((_) => {
875               this.showMgmtGatewayMessage = true;
876             });
877           }
878           const ssl_ciphers = this.serviceForm.get('ssl_ciphers');
879           if (ssl_ciphers) {
880             ssl_ciphers.valueChanges.subscribe((_) => {
881               this.showMgmtGatewayMessage = true;
882             });
883           }
884         }
885       });
886     }
887   }
888
889   getDefaultsEntitiesForRgw(
890     defaultRealmId: string,
891     defaultZonegroupId: string,
892     defaultZoneId: string
893   ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
894     const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
895     const defaultZonegroup = this.zonegroupList.find(
896       (x: { id: string }) => x.id === defaultZonegroupId
897     );
898     const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
899     const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
900     const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
901     const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
902     if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
903       const defaultZonegroup = new RgwZonegroup();
904       defaultZonegroup.name = 'default';
905       this.zonegroupList.push(defaultZonegroup);
906     }
907     if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
908       const defaultZone = new RgwZone();
909       defaultZone.name = 'default';
910       this.zoneList.push(defaultZone);
911     }
912     return {
913       defaultRealmName: defaultRealmName,
914       defaultZonegroupName: defaultZonegroupName,
915       defaultZoneName: defaultZoneName
916     };
917   }
918
919   getDefaultPlacementCount(serviceType: string) {
920     /**
921      * `defaults` from src/pybind/mgr/cephadm/module.py
922      */
923     switch (serviceType) {
924       case 'mon':
925         this.serviceForm.get('count').setValue(5);
926         break;
927       case 'mgr':
928       case 'mds':
929       case 'rgw':
930       case 'ingress':
931       case 'rbd-mirror':
932         this.serviceForm.get('count').setValue(2);
933         break;
934       case 'iscsi':
935       case 'cephfs-mirror':
936       case 'nfs':
937       case 'grafana':
938       case 'alertmanager':
939       case 'prometheus':
940       case 'loki':
941       case 'container':
942       case 'snmp-gateway':
943       case 'elastic-serach':
944       case 'jaeger-collector':
945       case 'jaeger-query':
946       case 'smb':
947       case 'oauth2-proxy':
948       case 'mgmt-gateway':
949         this.serviceForm.get('count').setValue(1);
950         break;
951       default:
952         this.serviceForm.get('count').setValue(null);
953     }
954   }
955
956   setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string, qat?: QatSepcs) {
957     const observables = [
958       this.rgwRealmService.getAllRealmsInfo(),
959       this.rgwZonegroupService.getAllZonegroupsInfo(),
960       this.rgwZoneService.getAllZonesInfo()
961     ];
962     this.sub = forkJoin(observables).subscribe(
963       (multisiteInfo: [object, object, object]) => {
964         this.multisiteInfo = multisiteInfo;
965         this.realmList =
966           this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
967             ? this.multisiteInfo[0]['realms']
968             : [];
969         this.zonegroupList =
970           this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
971             ? this.multisiteInfo[1]['zonegroups']
972             : [];
973         this.zoneList =
974           this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
975             ? this.multisiteInfo[2]['zones']
976             : [];
977         this.realmNames = this.realmList.map((realm) => {
978           return realm['name'];
979         });
980         this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
981           return zonegroup['name'];
982         });
983         this.zoneNames = this.zoneList.map((zone) => {
984           return zone['name'];
985         });
986         this.defaultRealmId = multisiteInfo[0]['default_realm'];
987         this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
988         this.defaultZoneId = multisiteInfo[2]['default_zone'];
989         this.defaultsInfo = this.getDefaultsEntitiesForRgw(
990           this.defaultRealmId,
991           this.defaultZonegroupId,
992           this.defaultZoneId
993         );
994         if (!this.editing) {
995           this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
996           this.serviceForm
997             .get('zonegroup_name')
998             .setValue(this.defaultsInfo['defaultZonegroupName']);
999           this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
1000         } else {
1001           if (realm_name && !this.realmNames.includes(realm_name)) {
1002             const realm = new RgwRealm();
1003             realm.name = realm_name;
1004             this.realmList.push(realm);
1005           }
1006           if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
1007             const zonegroup = new RgwZonegroup();
1008             zonegroup.name = zonegroup_name;
1009             this.zonegroupList.push(zonegroup);
1010           }
1011           if (zone_name && !this.zoneNames.includes(zone_name)) {
1012             const zone = new RgwZone();
1013             zone.name = zone_name;
1014             this.zoneList.push(zone);
1015           }
1016           if (zonegroup_name === undefined && zone_name === undefined) {
1017             zonegroup_name = 'default';
1018             zone_name = 'default';
1019           }
1020           this.serviceForm.get('realm_name').setValue(realm_name);
1021           this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
1022           this.serviceForm.get('zone_name').setValue(zone_name);
1023         }
1024         if (qat) {
1025           this.serviceForm.get(`qat.compression`)?.setValue(qat['compression']);
1026         }
1027         if (this.realmList.length === 0) {
1028           this.showRealmCreationForm = true;
1029         } else {
1030           this.showRealmCreationForm = false;
1031         }
1032       },
1033       (_error) => {
1034         const defaultZone = new RgwZone();
1035         defaultZone.name = 'default';
1036         const defaultZonegroup = new RgwZonegroup();
1037         defaultZonegroup.name = 'default';
1038         this.zoneList.push(defaultZone);
1039         this.zonegroupList.push(defaultZonegroup);
1040       }
1041     );
1042   }
1043
1044   setNvmeServiceId() {
1045     const pool = this.serviceForm.get('pool').value;
1046     const group = this.serviceForm.get('group').value;
1047     if (pool && group) {
1048       this.serviceForm.get('service_id').setValue(`${pool}.${group}`);
1049     } else if (pool) {
1050       this.serviceForm.get('service_id').setValue(pool);
1051     } else if (group) {
1052       this.serviceForm.get('service_id').setValue(group);
1053     } else {
1054       this.serviceForm.get('service_id').setValue(null);
1055     }
1056   }
1057
1058   setNvmeDefaultPool() {
1059     const defaultPool =
1060       this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')?.pool_name ||
1061       this.rbdPools?.[0].pool_name;
1062     this.serviceForm.get('pool').setValue(defaultPool);
1063   }
1064
1065   requiresServiceId(serviceType: string) {
1066     return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
1067   }
1068
1069   setServiceId(serviceId: string): void {
1070     const requiresServiceId: boolean = this.requiresServiceId(serviceId);
1071     if (requiresServiceId && serviceId === 'nvmeof') {
1072       this.setNvmeDefaultPool();
1073       this.setNvmeServiceId();
1074     } else if (requiresServiceId) {
1075       this.serviceForm.get('service_id').setValue(null);
1076     } else {
1077       this.serviceForm.get('service_id').setValue(serviceId);
1078     }
1079   }
1080
1081   onServiceTypeChange(selectedServiceType: string) {
1082     this.setServiceId(selectedServiceType);
1083
1084     this.serviceIds = this.serviceList
1085       ?.filter((service) => service['service_type'] === selectedServiceType)
1086       .map((service) => service['service_id']);
1087
1088     this.getDefaultPlacementCount(selectedServiceType);
1089
1090     if (selectedServiceType === 'rgw') {
1091       this.setRgwFields();
1092     }
1093     if (selectedServiceType === 'mgmt-gateway') {
1094       let hrefSplitted = window.location.href.split(':');
1095       this.currentURL = hrefSplitted[0] + hrefSplitted[1];
1096       // mgmt-gateway lacks HA for now
1097       this.serviceForm.get('count').disable();
1098     } else {
1099       this.serviceForm.get('count').enable();
1100     }
1101   }
1102
1103   onPlacementChange(selected: string) {
1104     if (selected === 'label') {
1105       this.serviceForm.get('count').setValue(null);
1106     }
1107   }
1108
1109   disableForEditing(serviceType: string) {
1110     const disableForEditKeys = ['service_type', 'service_id'];
1111     disableForEditKeys.forEach((key) => {
1112       this.serviceForm.get(key).disable();
1113     });
1114     switch (serviceType) {
1115       case 'ingress':
1116         this.serviceForm.get('backend_service').disable();
1117         break;
1118       case 'nvmeof':
1119         this.serviceForm.get('pool').disable();
1120         this.serviceForm.get('group').disable();
1121         break;
1122     }
1123   }
1124
1125   searchLabels = (text$: Observable<string>) => {
1126     return merge(
1127       text$.pipe(debounceTime(200), distinctUntilChanged()),
1128       this.labelFocus,
1129       this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
1130     ).pipe(
1131       map((value) =>
1132         this.labels
1133           .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
1134           .slice(0, 10)
1135       )
1136     );
1137   };
1138
1139   fileUpload(files: FileList, controlName: string) {
1140     const file: File = files[0];
1141     const reader = new FileReader();
1142     reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
1143       const control: AbstractControl = this.serviceForm.get(controlName);
1144       control.setValue(event.target.result);
1145       control.markAsDirty();
1146       control.markAsTouched();
1147       control.updateValueAndValidity();
1148     });
1149     reader.readAsText(file, 'utf8');
1150   }
1151
1152   prePopulateId() {
1153     const control: AbstractControl = this.serviceForm.get('service_id');
1154     const backendService = this.serviceForm.getValue('backend_service');
1155     // Set Id as read-only
1156     control.reset({ value: backendService, disabled: true });
1157   }
1158
1159   onSubmit() {
1160     const self = this;
1161     const values: object = this.serviceForm.getRawValue();
1162     const serviceType: string = values['service_type'];
1163     let taskUrl = `service/${URLVerbs.CREATE}`;
1164     if (this.editing) {
1165       taskUrl = `service/${URLVerbs.EDIT}`;
1166     }
1167     const serviceSpec: object = {
1168       service_type: serviceType,
1169       placement: {},
1170       unmanaged: values['unmanaged']
1171     };
1172     if (serviceType === 'rgw') {
1173       serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
1174       serviceSpec['rgw_zonegroup'] =
1175         values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
1176       serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
1177       if (values['qat']['compression'] && values['qat']['compression'] != QatOptions.none) {
1178         serviceSpec['qat'] = values['qat'];
1179       } else if (values['qat']['compression'] == QatOptions.none) {
1180         delete serviceSpec['qat'];
1181       }
1182     }
1183
1184     const serviceId: string = values['service_id'];
1185     let serviceName: string = serviceType;
1186     if (_.isString(serviceId) && !_.isEmpty(serviceId)) {
1187       serviceName = `${serviceType}.${serviceId}`;
1188       serviceSpec['service_id'] = serviceId;
1189     }
1190
1191     // These services has some fields to be
1192     // filled out even if unmanaged is true
1193     switch (serviceType) {
1194       case 'ingress':
1195         serviceSpec['backend_service'] = values['backend_service'];
1196         serviceSpec['service_id'] = values['backend_service'];
1197         if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
1198           serviceSpec['frontend_port'] = values['frontend_port'];
1199         }
1200         if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1201           serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1202         }
1203         if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1204           serviceSpec['monitor_port'] = values['monitor_port'];
1205         }
1206         break;
1207
1208       case 'nvmeof':
1209         serviceSpec['pool'] = values['pool'];
1210         serviceSpec['group'] = values['group'];
1211         serviceSpec['enable_auth'] = values['enable_mtls'];
1212         if (values['enable_mtls']) {
1213           serviceSpec['root_ca_cert'] = values['root_ca_cert'];
1214           serviceSpec['client_cert'] = values['client_cert'];
1215           serviceSpec['client_key'] = values['client_key'];
1216           serviceSpec['server_cert'] = values['server_cert'];
1217           serviceSpec['server_key'] = values['server_key'];
1218         }
1219         break;
1220       case 'iscsi':
1221         serviceSpec['pool'] = values['pool'];
1222         break;
1223
1224       case 'smb':
1225         serviceSpec['cluster_id'] = values['cluster_id']?.trim();
1226         serviceSpec['config_uri'] = values['config_uri']?.trim();
1227         for (const feature in values['features']) {
1228           if (values['features'][feature]) {
1229             (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
1230           }
1231         }
1232         serviceSpec['custom_dns'] = values['custom_dns'];
1233         serviceSpec['join_sources'] = values['join_sources']?.trim();
1234         serviceSpec['user_sources'] = values['user_sources']?.trim();
1235         serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
1236         break;
1237
1238       case 'snmp-gateway':
1239         serviceSpec['credentials'] = {};
1240         serviceSpec['snmp_version'] = values['snmp_version'];
1241         serviceSpec['snmp_destination'] = values['snmp_destination'];
1242         if (values['snmp_version'] === 'V3') {
1243           serviceSpec['engine_id'] = values['engine_id'];
1244           serviceSpec['auth_protocol'] = values['auth_protocol'];
1245           serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
1246           serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
1247           if (values['privacy_protocol'] !== null) {
1248             serviceSpec['privacy_protocol'] = values['privacy_protocol'];
1249             serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
1250           }
1251         } else {
1252           serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1253         }
1254         break;
1255     }
1256
1257     if (!values['unmanaged']) {
1258       switch (values['placement']) {
1259         case 'hosts':
1260           if (values['hosts'].length > 0) {
1261             serviceSpec['placement']['hosts'] = values['hosts'];
1262           }
1263           break;
1264         case 'label':
1265           serviceSpec['placement']['label'] = values['label'];
1266           break;
1267       }
1268       if (_.isNumber(values['count']) && values['count'] > 0) {
1269         serviceSpec['placement']['count'] = values['count'];
1270       }
1271       switch (serviceType) {
1272         case 'rgw':
1273           if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1274             serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1275           }
1276           serviceSpec['ssl'] = values['ssl'];
1277           if (values['ssl']) {
1278             serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1279           }
1280           break;
1281         case 'iscsi':
1282           if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1283             serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1284           }
1285           if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1286             serviceSpec['api_port'] = values['api_port'];
1287           }
1288           serviceSpec['api_user'] = values['api_user'];
1289           serviceSpec['api_password'] = values['api_password'];
1290           serviceSpec['api_secure'] = values['ssl'];
1291           if (values['ssl']) {
1292             serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1293             serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1294           }
1295           break;
1296         case 'ingress':
1297           serviceSpec['ssl'] = values['ssl'];
1298           if (values['ssl']) {
1299             serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1300             serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1301           }
1302           serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1303           break;
1304         case 'mgmt-gateway':
1305           serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1306           serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1307           serviceSpec['enable_auth'] = values['enable_auth'];
1308           serviceSpec['port'] = values['port'];
1309           if (serviceSpec['port'] === (443 || 80)) {
1310             // omit port default values due to issues with redirect_url on the backend
1311             delete serviceSpec['port'];
1312           }
1313           serviceSpec['ssl_protocols'] = [];
1314           if (values['ssl_protocols'] != this.DEFAULT_SSL_PROTOCOL_ITEM) {
1315             for (const key of Object.keys(values['ssl_protocols'])) {
1316               serviceSpec['ssl_protocols'].push(values['ssl_protocols'][key]['content']);
1317             }
1318           }
1319           serviceSpec['ssl_ciphers'] = values['ssl_ciphers']?.trim().split(':');
1320           break;
1321         case 'grafana':
1322           serviceSpec['port'] = values['grafana_port'];
1323           serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1324           break;
1325         case 'oauth2-proxy':
1326           serviceSpec['provider_display_name'] = values['provider_display_name']?.trim();
1327           serviceSpec['client_id'] = values['client_id']?.trim();
1328           serviceSpec['client_secret'] = values['client_secret']?.trim();
1329           serviceSpec['oidc_issuer_url'] = values['oidc_issuer_url']?.trim();
1330           serviceSpec['https_address'] = values['https_address']?.trim();
1331           serviceSpec['redirect_url'] = values['redirect_url']?.trim();
1332           serviceSpec['allowlist_domains'] = values['allowlist_domains']
1333             ?.split(',')
1334             .map((domain: string) => {
1335               return domain.trim();
1336             });
1337           if (values['ssl']) {
1338             serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1339             serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1340           }
1341           break;
1342       }
1343     }
1344     this.taskWrapperService
1345       .wrapTaskAroundCall({
1346         task: new FinishedTask(taskUrl, {
1347           service_name: serviceName
1348         }),
1349         call: this.editing
1350           ? this.cephServiceService.update(serviceSpec)
1351           : this.cephServiceService.create(serviceSpec)
1352       })
1353       .subscribe({
1354         error() {
1355           self.serviceForm.setErrors({ cdSubmitButton: true });
1356         },
1357         complete: () => {
1358           this.pageURL === 'services'
1359             ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1360             : this.activeModal.close();
1361         }
1362       });
1363   }
1364
1365   clearValidations() {
1366     const snmpVersion = this.serviceForm.getValue('snmp_version');
1367     const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1368     if (snmpVersion === 'V3') {
1369       this.serviceForm.get('snmp_community').clearValidators();
1370     } else {
1371       this.serviceForm.get('engine_id').clearValidators();
1372       this.serviceForm.get('auth_protocol').clearValidators();
1373       this.serviceForm.get('privacy_protocol').clearValidators();
1374       this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1375       this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1376     }
1377     if (privacyProtocol === null) {
1378       this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1379     }
1380   }
1381
1382   createMultisiteSetup() {
1383     this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1384       size: 'lg'
1385     });
1386     this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1387       this.setRgwFields();
1388     });
1389   }
1390 }