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';
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';
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';
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 } 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 import { environment } from '~/environments/environment';
45 selector: 'cd-service-form',
46 templateUrl: './service-form.component.html',
47 styleUrls: ['./service-form.component.scss']
49 export class ServiceFormComponent extends CdForm implements OnInit {
50 public sub = new Subscription();
52 readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
53 readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
54 readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
55 readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
56 readonly SMB_CONFIG_URI_PATTERN = /^(http:|https:|rados:|rados:mon-config-key:)/;
57 readonly OAUTH2_ISSUER_URL_PATTERN = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)(:[0-9]{1,5})?(\/.*)?$/;
58 readonly SSL_CIPHERS_PATTERN = /^[a-zA-Z0-9\-:]+$/;
59 readonly DEFAULT_SSL_PROTOCOL_ITEM = [{ content: 'TLSv1.3', selected: true }];
60 @ViewChild(NgbTypeahead, { static: false })
61 typeahead: NgbTypeahead;
63 @Input() hiddenServices: string[] = [];
65 @Input() editing = false;
67 @Input() serviceName: string;
69 @Input() serviceType: string;
71 serviceForm: CdFormGroup;
74 serviceTypes: string[] = [];
75 serviceIds: string[] = [];
78 labelClick = new Subject<string>();
79 labelFocus = new Subject<string>();
81 rbdPools: Array<Pool>;
82 services: Array<CephServiceSpec> = [];
84 serviceList: CephServiceSpec[];
85 multisiteInfo: object[] = [];
87 defaultZonegroupId = '';
89 realmList: RgwRealm[] = [];
90 zonegroupList: RgwZonegroup[] = [];
91 zoneList: RgwZone[] = [];
92 bsModalRef: NgbModalRef;
93 defaultZonegroup: RgwZonegroup;
94 showRealmCreationForm = false;
95 defaultsInfo: { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string };
97 zonegroupNames: string[];
99 smbFeaturesList = ['domain'];
102 sslProtocolsItems: Array<ListItem> = Object.values(SSL_PROTOCOLS).map((protocol) => ({
106 sslCiphersItems: Array<ListItem> = Object.values(SSL_CIPHERS).map((cipher) => ({
110 showMgmtGatewayMessage: boolean = false;
113 public actionLabels: ActionLabelsI18n,
114 private cephServiceService: CephServiceService,
115 private formBuilder: CdFormBuilder,
116 private hostService: HostService,
117 private poolService: PoolService,
118 private rbdService: RbdService,
119 private router: Router,
120 private taskWrapperService: TaskWrapperService,
121 public timerService: TimerService,
122 public timerServiceVariable: TimerServiceInterval,
123 public rgwRealmService: RgwRealmService,
124 public rgwZonegroupService: RgwZonegroupService,
125 public rgwZoneService: RgwZoneService,
126 public rgwMultisiteService: RgwMultisiteService,
127 private route: ActivatedRoute,
128 public activeModal: NgbActiveModal,
129 public modalService: ModalService
132 this.resource = $localize`service`;
135 messages: new SelectMessages({
136 empty: $localize`There are no hosts.`,
137 filter: $localize`Filter hosts`
144 this.serviceForm = this.formBuilder.group({
146 service_type: [null, [Validators.required]],
150 CdValidators.composeIf(
156 CdValidators.custom('mdsPattern', (value: string) => {
157 if (_.isEmpty(value)) {
160 return !this.MDS_SVC_ID_PATTERN.test(value);
164 CdValidators.requiredIf({
167 CdValidators.requiredIf({
168 service_type: 'iscsi'
170 CdValidators.requiredIf({
171 service_type: 'nvmeof'
173 CdValidators.requiredIf({
174 service_type: 'ingress'
176 CdValidators.requiredIf({
179 CdValidators.composeIf(
183 [Validators.required]
185 CdValidators.custom('uniqueName', (service_id: string) => {
186 return this.serviceIds && this.serviceIds.includes(service_id);
190 placement: ['hosts'],
194 CdValidators.requiredIf({
201 count: [null, [CdValidators.number(false)]],
208 CdValidators.requiredIf({
209 service_type: 'iscsi'
211 CdValidators.requiredIf({
212 service_type: 'nvmeof'
218 CdValidators.requiredIf({
219 service_type: 'nvmeof'
222 enable_mtls: [false],
226 CdValidators.composeIf(
228 service_type: 'nvmeof',
231 [Validators.required]
238 CdValidators.composeIf(
240 service_type: 'nvmeof',
243 [Validators.required]
250 CdValidators.composeIf(
252 service_type: 'nvmeof',
255 [Validators.required]
262 CdValidators.composeIf(
264 service_type: 'nvmeof',
267 [Validators.required]
274 CdValidators.composeIf(
276 service_type: 'nvmeof',
279 [Validators.required]
284 rgw_frontend_port: [null, [CdValidators.number(false)]],
286 zonegroup_name: [null],
289 trusted_ip_list: [null],
290 api_port: [null, [CdValidators.number(false)]],
294 CdValidators.requiredIf({
295 service_type: 'iscsi',
303 CdValidators.requiredIf({
304 service_type: 'iscsi',
313 CdValidators.requiredIf({
318 features: new CdFormGroup(
319 this.smbFeaturesList.reduce((acc: object, e) => {
320 acc[e] = new UntypedFormControl(false);
327 CdValidators.composeIf(
333 CdValidators.custom('configUriPattern', (value: string) => {
334 if (_.isEmpty(value)) {
337 return !this.SMB_CONFIG_URI_PATTERN.test(value);
344 join_sources: [null],
345 user_sources: [null],
346 include_ceph_users: [null],
351 CdValidators.requiredIf({
352 service_type: 'ingress'
359 CdValidators.requiredIf({
360 service_type: 'ingress'
367 CdValidators.number(false),
368 CdValidators.requiredIf({
369 service_type: 'ingress'
376 CdValidators.number(false),
377 CdValidators.requiredIf({
378 service_type: 'ingress'
382 virtual_interface_networks: [null],
383 ssl_protocols: [this.DEFAULT_SSL_PROTOCOL_ITEM],
387 CdValidators.custom('invalidPattern', (ciphers: string) => {
388 if (_.isEmpty(ciphers)) {
391 return !this.SSL_CIPHERS_PATTERN.test(ciphers);
395 // RGW, Ingress & iSCSI
400 CdValidators.composeIf(
406 [Validators.required, CdValidators.pemCert()]
408 CdValidators.composeIf(
410 service_type: 'iscsi',
414 [Validators.required, CdValidators.sslCert()]
416 CdValidators.composeIf(
418 service_type: 'ingress',
422 [Validators.required, CdValidators.pemCert()]
424 CdValidators.composeIf(
426 service_type: 'oauth2-proxy',
430 [Validators.required, CdValidators.sslCert()]
432 CdValidators.composeIf(
434 service_type: 'mgmt-gateway',
438 [CdValidators.sslCert()]
445 CdValidators.composeIf(
447 service_type: 'iscsi',
451 [Validators.required, CdValidators.sslPrivKey()]
453 CdValidators.composeIf(
455 service_type: 'oauth2-proxy',
459 [Validators.required, CdValidators.sslPrivKey()]
461 CdValidators.composeIf(
463 service_type: 'mgmt-gateway',
467 [CdValidators.sslPrivKey()]
473 port: [443, [CdValidators.number(false)]],
478 CdValidators.requiredIf({
479 service_type: 'snmp-gateway'
487 CdValidators.requiredIf({
488 service_type: 'snmp-gateway'
490 CdValidators.custom('snmpDestinationPattern', (value: string) => {
491 if (_.isEmpty(value)) {
494 return !this.SNMP_DESTINATION_PATTERN.test(value);
502 CdValidators.requiredIf({
503 service_type: 'snmp-gateway'
505 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
506 if (_.isEmpty(value)) {
509 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
516 CdValidators.requiredIf({
517 service_type: 'snmp-gateway'
521 privacy_protocol: [null],
525 CdValidators.requiredIf({
530 snmp_v3_auth_username: [
533 CdValidators.requiredIf({
534 service_type: 'snmp-gateway'
538 snmp_v3_auth_password: [
541 CdValidators.requiredIf({
542 service_type: 'snmp-gateway'
546 snmp_v3_priv_password: [
549 CdValidators.requiredIf({
550 privacy_protocol: { op: '!empty' }
554 grafana_port: [null, [CdValidators.number(false)]],
555 grafana_admin_password: [null],
557 provider_display_name: [
560 CdValidators.requiredIf({
561 service_type: 'oauth2-proxy'
568 CdValidators.requiredIf({
569 service_type: 'oauth2-proxy'
576 CdValidators.requiredIf({
577 service_type: 'oauth2-proxy'
584 CdValidators.requiredIf({
585 service_type: 'oauth2-proxy'
587 CdValidators.custom('validUrl', (url: string) => {
588 if (_.isEmpty(url)) {
591 return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
595 https_address: [null, [CdValidators.oauthAddressTest()]],
596 redirect_url: [null],
597 allowlist_domains: [null]
602 if (this.router.url.includes('services/(modal:create')) {
603 this.pageURL = 'services';
604 this.route.params.subscribe((params: { type: string }) => {
606 this.serviceType = params.type;
607 this.serviceForm.get('service_type').setValue(this.serviceType);
610 } else if (this.router.url.includes('services/(modal:edit')) {
612 this.pageURL = 'services';
613 this.route.params.subscribe((params: { type: string; name: string }) => {
614 this.serviceName = params.name;
615 this.serviceType = params.type;
621 this.action = this.actionLabels.CREATE;
624 this.cephServiceService
625 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
626 .observable.subscribe((services: CephServiceSpec[]) => {
627 this.serviceList = services;
628 this.services = services.filter((service: any) =>
629 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
633 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
634 // Remove service types:
635 // osd - This is deployed a different way.
636 // container - This should only be used in the CLI.
637 // nvmeof - This is only supported for IBM builds.
638 this.hiddenServices.push('osd', 'container', 'promtail');
639 if (environment.build !== 'ibm') this.hiddenServices.push('nvmeof');
641 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
643 this.hostService.getAllHosts().subscribe((resp: Host[]) => {
644 const options: SelectOption[] = [];
645 _.forEach(resp, (host: Host) => {
646 if (_.get(host, 'sources.orchestrator', false)) {
647 const option = new SelectOption(false, _.get(host, 'hostname'), '');
648 options.push(option);
651 this.hosts.options = [...options];
653 this.hostService.getLabels().subscribe((resp: string[]) => {
656 this.poolService.getList().subscribe((resp: Pool[]) => {
658 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
659 if (!this.editing && this.serviceType) {
660 this.onServiceTypeChange(this.serviceType);
665 this.action = this.actionLabels.EDIT;
666 this.disableForEditing(this.serviceType);
667 this.cephServiceService
668 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
669 .observable.subscribe((response: CephServiceSpec[]) => {
670 const formKeys = ['service_type', 'service_id', 'unmanaged'];
671 formKeys.forEach((keys) => {
672 this.serviceForm.get(keys).setValue(response[0][keys]);
674 if (!response[0]['unmanaged']) {
675 const placementKey = Object.keys(response[0]['placement'])[0];
676 let placementValue: string;
677 ['hosts', 'label'].indexOf(placementKey) >= 0
678 ? (placementValue = placementKey)
679 : (placementValue = 'hosts');
680 this.serviceForm.get('placement').setValue(placementValue);
681 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
682 if (response[0]?.placement[placementValue]) {
683 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
686 switch (this.serviceType) {
688 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
689 specKeys.forEach((key) => {
690 this.serviceForm.get(key).setValue(response[0].spec[key]);
692 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
693 if (response[0].spec?.api_secure) {
694 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
695 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
699 this.serviceForm.get('pool').setValue(response[0].spec.pool);
700 this.serviceForm.get('group').setValue(response[0].spec.group);
701 this.serviceForm.get('enable_mtls').setValue(response[0].spec?.enable_auth);
702 this.serviceForm.get('root_ca_cert').setValue(response[0].spec?.root_ca_cert);
703 this.serviceForm.get('client_cert').setValue(response[0].spec?.client_cert);
704 this.serviceForm.get('client_key').setValue(response[0].spec?.client_key);
705 this.serviceForm.get('server_cert').setValue(response[0].spec?.server_cert);
706 this.serviceForm.get('server_key').setValue(response[0].spec?.server_key);
710 .get('rgw_frontend_port')
711 .setValue(response[0].spec?.rgw_frontend_port);
713 response[0].spec?.rgw_realm,
714 response[0].spec?.rgw_zonegroup,
715 response[0].spec?.rgw_zone
717 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
718 if (response[0].spec?.ssl) {
721 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
725 const ingressSpecKeys = [
730 'virtual_interface_networks',
733 ingressSpecKeys.forEach((key) => {
734 this.serviceForm.get(key).setValue(response[0].spec[key]);
736 if (response[0].spec?.ssl) {
737 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
738 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
742 let hrefSplitted = window.location.href.split(':');
743 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
744 this.port = response[0].spec?.port;
746 if (response[0].spec?.ssl_protocols) {
747 let selectedValues: Array<ListItem> = [];
748 for (const value of response[0].spec.ssl_protocols) {
749 selectedValues.push({ content: value, selected: true });
751 this.serviceForm.get('ssl_protocols').setValue(selectedValues);
753 if (response[0].spec?.ssl_ciphers) {
756 .setValue(response[0].spec?.ssl_ciphers.join(':'));
758 if (response[0].spec?.ssl_cert) {
759 this.serviceForm.get('ssl_cert').setValue(response[0].spec.ssl_cert);
761 if (response[0].spec?.ssl_key) {
762 this.serviceForm.get('ssl_key').setValue(response[0].spec.ssl_key);
764 if (response[0].spec?.enable_auth) {
765 this.serviceForm.get('enable_auth').setValue(response[0].spec.enable_auth);
767 if (response[0].spec?.port) {
768 this.serviceForm.get('port').setValue(response[0].spec.port);
772 const smbSpecKeys = [
781 smbSpecKeys.forEach((key) => {
782 if (key === 'features') {
783 if (response[0].spec?.features) {
784 response[0].spec.features.forEach((feature) => {
785 this.serviceForm.get(`features.${feature}`).setValue(true);
789 this.serviceForm.get(key).setValue(response[0].spec[key]);
794 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
795 snmpCommonSpecKeys.forEach((key) => {
796 this.serviceForm.get(key).setValue(response[0].spec[key]);
798 if (this.serviceForm.getValue('snmp_version') === 'V3') {
799 const snmpV3SpecKeys = [
803 'snmp_v3_auth_username',
804 'snmp_v3_auth_password',
805 'snmp_v3_priv_password'
807 snmpV3SpecKeys.forEach((key) => {
810 key === 'snmp_v3_auth_username' ||
811 key === 'snmp_v3_auth_password' ||
812 key === 'snmp_v3_priv_password'
814 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
816 this.serviceForm.get(key).setValue(response[0].spec[key]);
822 .get('snmp_community')
823 .setValue(response[0].spec['credentials']['snmp_community']);
827 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
829 .get('grafana_admin_password')
830 .setValue(response[0].spec.initial_admin_password);
833 const oauth2SpecKeys = [
835 'provider_display_name',
842 oauth2SpecKeys.forEach((key) => {
843 this.serviceForm.get(key).setValue(response[0].spec[key]);
845 if (response[0].spec?.ssl) {
846 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
847 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
852 this.detectChanges();
855 detectChanges(): void {
856 const service_type = this.serviceForm.get('service_type');
858 service_type.valueChanges.subscribe((value) => {
859 if (value === 'mgmt-gateway') {
860 const port = this.serviceForm.get('port');
862 port.valueChanges.subscribe((_) => {
863 this.showMgmtGatewayMessage = true;
866 const ssl_protocols = this.serviceForm.get('ssl_protocols');
868 ssl_protocols.valueChanges.subscribe((_) => {
869 this.showMgmtGatewayMessage = true;
872 const ssl_ciphers = this.serviceForm.get('ssl_ciphers');
874 ssl_ciphers.valueChanges.subscribe((_) => {
875 this.showMgmtGatewayMessage = true;
883 getDefaultsEntitiesForRgw(
884 defaultRealmId: string,
885 defaultZonegroupId: string,
886 defaultZoneId: string
887 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
888 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
889 const defaultZonegroup = this.zonegroupList.find(
890 (x: { id: string }) => x.id === defaultZonegroupId
892 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
893 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
894 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
895 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
896 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
897 const defaultZonegroup = new RgwZonegroup();
898 defaultZonegroup.name = 'default';
899 this.zonegroupList.push(defaultZonegroup);
901 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
902 const defaultZone = new RgwZone();
903 defaultZone.name = 'default';
904 this.zoneList.push(defaultZone);
907 defaultRealmName: defaultRealmName,
908 defaultZonegroupName: defaultZonegroupName,
909 defaultZoneName: defaultZoneName
913 getDefaultPlacementCount(serviceType: string) {
915 * `defaults` from src/pybind/mgr/cephadm/module.py
917 switch (serviceType) {
919 this.serviceForm.get('count').setValue(5);
926 this.serviceForm.get('count').setValue(2);
929 case 'cephfs-mirror':
937 case 'elastic-serach':
938 case 'jaeger-collector':
943 this.serviceForm.get('count').setValue(1);
946 this.serviceForm.get('count').setValue(null);
950 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
951 const observables = [
952 this.rgwRealmService.getAllRealmsInfo(),
953 this.rgwZonegroupService.getAllZonegroupsInfo(),
954 this.rgwZoneService.getAllZonesInfo()
956 this.sub = forkJoin(observables).subscribe(
957 (multisiteInfo: [object, object, object]) => {
958 this.multisiteInfo = multisiteInfo;
960 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
961 ? this.multisiteInfo[0]['realms']
964 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
965 ? this.multisiteInfo[1]['zonegroups']
968 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
969 ? this.multisiteInfo[2]['zones']
971 this.realmNames = this.realmList.map((realm) => {
972 return realm['name'];
974 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
975 return zonegroup['name'];
977 this.zoneNames = this.zoneList.map((zone) => {
980 this.defaultRealmId = multisiteInfo[0]['default_realm'];
981 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
982 this.defaultZoneId = multisiteInfo[2]['default_zone'];
983 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
985 this.defaultZonegroupId,
989 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
991 .get('zonegroup_name')
992 .setValue(this.defaultsInfo['defaultZonegroupName']);
993 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
995 if (realm_name && !this.realmNames.includes(realm_name)) {
996 const realm = new RgwRealm();
997 realm.name = realm_name;
998 this.realmList.push(realm);
1000 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
1001 const zonegroup = new RgwZonegroup();
1002 zonegroup.name = zonegroup_name;
1003 this.zonegroupList.push(zonegroup);
1005 if (zone_name && !this.zoneNames.includes(zone_name)) {
1006 const zone = new RgwZone();
1007 zone.name = zone_name;
1008 this.zoneList.push(zone);
1010 if (zonegroup_name === undefined && zone_name === undefined) {
1011 zonegroup_name = 'default';
1012 zone_name = 'default';
1014 this.serviceForm.get('realm_name').setValue(realm_name);
1015 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
1016 this.serviceForm.get('zone_name').setValue(zone_name);
1018 if (this.realmList.length === 0) {
1019 this.showRealmCreationForm = true;
1021 this.showRealmCreationForm = false;
1025 const defaultZone = new RgwZone();
1026 defaultZone.name = 'default';
1027 const defaultZonegroup = new RgwZonegroup();
1028 defaultZonegroup.name = 'default';
1029 this.zoneList.push(defaultZone);
1030 this.zonegroupList.push(defaultZonegroup);
1035 setNvmeServiceId() {
1036 const pool = this.serviceForm.get('pool').value;
1037 const group = this.serviceForm.get('group').value;
1038 if (pool && group) {
1039 this.serviceForm.get('service_id').setValue(`${pool}.${group}`);
1041 this.serviceForm.get('service_id').setValue(pool);
1043 this.serviceForm.get('service_id').setValue(group);
1045 this.serviceForm.get('service_id').setValue(null);
1049 setNvmeDefaultPool() {
1051 this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')?.pool_name ||
1052 this.rbdPools?.[0].pool_name;
1053 this.serviceForm.get('pool').setValue(defaultPool);
1056 requiresServiceId(serviceType: string) {
1057 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
1060 setServiceId(serviceId: string): void {
1061 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
1062 if (requiresServiceId && serviceId === 'nvmeof') {
1063 this.setNvmeDefaultPool();
1064 this.setNvmeServiceId();
1065 } else if (requiresServiceId) {
1066 this.serviceForm.get('service_id').setValue(null);
1068 this.serviceForm.get('service_id').setValue(serviceId);
1072 onServiceTypeChange(selectedServiceType: string) {
1073 this.setServiceId(selectedServiceType);
1075 this.serviceIds = this.serviceList
1076 ?.filter((service) => service['service_type'] === selectedServiceType)
1077 .map((service) => service['service_id']);
1079 this.getDefaultPlacementCount(selectedServiceType);
1081 if (selectedServiceType === 'rgw') {
1082 this.setRgwFields();
1084 if (selectedServiceType === 'mgmt-gateway') {
1085 let hrefSplitted = window.location.href.split(':');
1086 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
1087 // mgmt-gateway lacks HA for now
1088 this.serviceForm.get('count').disable();
1090 this.serviceForm.get('count').enable();
1094 onPlacementChange(selected: string) {
1095 if (selected === 'label') {
1096 this.serviceForm.get('count').setValue(null);
1100 disableForEditing(serviceType: string) {
1101 const disableForEditKeys = ['service_type', 'service_id'];
1102 disableForEditKeys.forEach((key) => {
1103 this.serviceForm.get(key).disable();
1105 switch (serviceType) {
1107 this.serviceForm.get('backend_service').disable();
1110 this.serviceForm.get('pool').disable();
1111 this.serviceForm.get('group').disable();
1116 searchLabels = (text$: Observable<string>) => {
1118 text$.pipe(debounceTime(200), distinctUntilChanged()),
1120 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
1124 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
1130 fileUpload(files: FileList, controlName: string) {
1131 const file: File = files[0];
1132 const reader = new FileReader();
1133 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
1134 const control: AbstractControl = this.serviceForm.get(controlName);
1135 control.setValue(event.target.result);
1136 control.markAsDirty();
1137 control.markAsTouched();
1138 control.updateValueAndValidity();
1140 reader.readAsText(file, 'utf8');
1144 const control: AbstractControl = this.serviceForm.get('service_id');
1145 const backendService = this.serviceForm.getValue('backend_service');
1146 // Set Id as read-only
1147 control.reset({ value: backendService, disabled: true });
1152 const values: object = this.serviceForm.getRawValue();
1153 const serviceType: string = values['service_type'];
1154 let taskUrl = `service/${URLVerbs.CREATE}`;
1156 taskUrl = `service/${URLVerbs.EDIT}`;
1158 const serviceSpec: object = {
1159 service_type: serviceType,
1161 unmanaged: values['unmanaged']
1163 if (serviceType === 'rgw') {
1164 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
1165 serviceSpec['rgw_zonegroup'] =
1166 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
1167 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
1170 const serviceId: string = values['service_id'];
1171 let serviceName: string = serviceType;
1172 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
1173 serviceName = `${serviceType}.${serviceId}`;
1174 serviceSpec['service_id'] = serviceId;
1177 // These services has some fields to be
1178 // filled out even if unmanaged is true
1179 switch (serviceType) {
1181 serviceSpec['backend_service'] = values['backend_service'];
1182 serviceSpec['service_id'] = values['backend_service'];
1183 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
1184 serviceSpec['frontend_port'] = values['frontend_port'];
1186 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1187 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1189 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1190 serviceSpec['monitor_port'] = values['monitor_port'];
1195 serviceSpec['pool'] = values['pool'];
1196 serviceSpec['group'] = values['group'];
1197 serviceSpec['enable_auth'] = values['enable_mtls'];
1198 if (values['enable_mtls']) {
1199 serviceSpec['root_ca_cert'] = values['root_ca_cert'];
1200 serviceSpec['client_cert'] = values['client_cert'];
1201 serviceSpec['client_key'] = values['client_key'];
1202 serviceSpec['server_cert'] = values['server_cert'];
1203 serviceSpec['server_key'] = values['server_key'];
1207 serviceSpec['pool'] = values['pool'];
1211 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
1212 serviceSpec['config_uri'] = values['config_uri']?.trim();
1213 for (const feature in values['features']) {
1214 if (values['features'][feature]) {
1215 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
1218 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
1219 serviceSpec['join_sources'] = values['join_sources']?.trim();
1220 serviceSpec['user_sources'] = values['user_sources']?.trim();
1221 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
1224 case 'snmp-gateway':
1225 serviceSpec['credentials'] = {};
1226 serviceSpec['snmp_version'] = values['snmp_version'];
1227 serviceSpec['snmp_destination'] = values['snmp_destination'];
1228 if (values['snmp_version'] === 'V3') {
1229 serviceSpec['engine_id'] = values['engine_id'];
1230 serviceSpec['auth_protocol'] = values['auth_protocol'];
1231 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
1232 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
1233 if (values['privacy_protocol'] !== null) {
1234 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
1235 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
1238 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1243 if (!values['unmanaged']) {
1244 switch (values['placement']) {
1246 if (values['hosts'].length > 0) {
1247 serviceSpec['placement']['hosts'] = values['hosts'];
1251 serviceSpec['placement']['label'] = values['label'];
1254 if (_.isNumber(values['count']) && values['count'] > 0) {
1255 serviceSpec['placement']['count'] = values['count'];
1257 switch (serviceType) {
1259 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1260 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1262 serviceSpec['ssl'] = values['ssl'];
1263 if (values['ssl']) {
1264 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1268 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1269 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1271 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1272 serviceSpec['api_port'] = values['api_port'];
1274 serviceSpec['api_user'] = values['api_user'];
1275 serviceSpec['api_password'] = values['api_password'];
1276 serviceSpec['api_secure'] = values['ssl'];
1277 if (values['ssl']) {
1278 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1279 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1283 serviceSpec['ssl'] = values['ssl'];
1284 if (values['ssl']) {
1285 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1286 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1288 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1290 case 'mgmt-gateway':
1291 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1292 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1293 serviceSpec['enable_auth'] = values['enable_auth'];
1294 serviceSpec['port'] = values['port'];
1295 if (serviceSpec['port'] === (443 || 80)) {
1296 // omit port default values due to issues with redirect_url on the backend
1297 delete serviceSpec['port'];
1299 serviceSpec['ssl_protocols'] = [];
1300 if (values['ssl_protocols'] != this.DEFAULT_SSL_PROTOCOL_ITEM) {
1301 for (const key of Object.keys(values['ssl_protocols'])) {
1302 serviceSpec['ssl_protocols'].push(values['ssl_protocols'][key]['content']);
1305 serviceSpec['ssl_ciphers'] = values['ssl_ciphers']?.trim().split(':');
1308 serviceSpec['port'] = values['grafana_port'];
1309 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1311 case 'oauth2-proxy':
1312 serviceSpec['provider_display_name'] = values['provider_display_name']?.trim();
1313 serviceSpec['client_id'] = values['client_id']?.trim();
1314 serviceSpec['client_secret'] = values['client_secret']?.trim();
1315 serviceSpec['oidc_issuer_url'] = values['oidc_issuer_url']?.trim();
1316 serviceSpec['https_address'] = values['https_address']?.trim();
1317 serviceSpec['redirect_url'] = values['redirect_url']?.trim();
1318 serviceSpec['allowlist_domains'] = values['allowlist_domains']
1320 .map((domain: string) => {
1321 return domain.trim();
1323 if (values['ssl']) {
1324 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1325 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1330 this.taskWrapperService
1331 .wrapTaskAroundCall({
1332 task: new FinishedTask(taskUrl, {
1333 service_name: serviceName
1336 ? this.cephServiceService.update(serviceSpec)
1337 : this.cephServiceService.create(serviceSpec)
1341 self.serviceForm.setErrors({ cdSubmitButton: true });
1344 this.pageURL === 'services'
1345 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1346 : this.activeModal.close();
1351 clearValidations() {
1352 const snmpVersion = this.serviceForm.getValue('snmp_version');
1353 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1354 if (snmpVersion === 'V3') {
1355 this.serviceForm.get('snmp_community').clearValidators();
1357 this.serviceForm.get('engine_id').clearValidators();
1358 this.serviceForm.get('auth_protocol').clearValidators();
1359 this.serviceForm.get('privacy_protocol').clearValidators();
1360 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1361 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1363 if (privacyProtocol === null) {
1364 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1368 createMultisiteSetup() {
1369 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1372 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1373 this.setRgwFields();