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';
44 selector: 'cd-service-form',
45 templateUrl: './service-form.component.html',
46 styleUrls: ['./service-form.component.scss']
48 export class ServiceFormComponent extends CdForm implements OnInit {
49 public sub = new Subscription();
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;
62 @Input() hiddenServices: string[] = [];
64 @Input() editing = false;
66 @Input() serviceName: string;
68 @Input() serviceType: string;
70 serviceForm: CdFormGroup;
73 serviceTypes: string[] = [];
74 serviceIds: string[] = [];
77 labelClick = new Subject<string>();
78 labelFocus = new Subject<string>();
80 rbdPools: Array<Pool>;
81 services: Array<CephServiceSpec> = [];
83 serviceList: CephServiceSpec[];
84 multisiteInfo: object[] = [];
86 defaultZonegroupId = '';
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 };
96 zonegroupNames: string[];
98 smbFeaturesList = ['domain'];
101 sslProtocolsItems: Array<ListItem> = Object.values(SSL_PROTOCOLS).map((protocol) => ({
105 sslCiphersItems: Array<ListItem> = Object.values(SSL_CIPHERS).map((cipher) => ({
109 showMgmtGatewayMessage: boolean = false;
112 public actionLabels: ActionLabelsI18n,
113 private cephServiceService: CephServiceService,
114 private formBuilder: CdFormBuilder,
115 private hostService: HostService,
116 private poolService: PoolService,
117 private rbdService: RbdService,
118 private router: Router,
119 private taskWrapperService: TaskWrapperService,
120 public timerService: TimerService,
121 public timerServiceVariable: TimerServiceInterval,
122 public rgwRealmService: RgwRealmService,
123 public rgwZonegroupService: RgwZonegroupService,
124 public rgwZoneService: RgwZoneService,
125 public rgwMultisiteService: RgwMultisiteService,
126 private route: ActivatedRoute,
127 public activeModal: NgbActiveModal,
128 public modalService: ModalService
131 this.resource = $localize`service`;
134 messages: new SelectMessages({
135 empty: $localize`There are no hosts.`,
136 filter: $localize`Filter hosts`
143 this.serviceForm = this.formBuilder.group({
145 service_type: [null, [Validators.required]],
149 CdValidators.composeIf(
155 CdValidators.custom('mdsPattern', (value: string) => {
156 if (_.isEmpty(value)) {
159 return !this.MDS_SVC_ID_PATTERN.test(value);
163 CdValidators.requiredIf({
166 CdValidators.requiredIf({
167 service_type: 'iscsi'
169 CdValidators.requiredIf({
170 service_type: 'nvmeof'
172 CdValidators.requiredIf({
173 service_type: 'ingress'
175 CdValidators.requiredIf({
178 CdValidators.composeIf(
182 [Validators.required]
184 CdValidators.custom('uniqueName', (service_id: string) => {
185 return this.serviceIds && this.serviceIds.includes(service_id);
189 placement: ['hosts'],
193 CdValidators.requiredIf({
200 count: [null, [CdValidators.number(false)]],
207 CdValidators.requiredIf({
208 service_type: 'iscsi'
210 CdValidators.requiredIf({
211 service_type: 'nvmeof'
217 CdValidators.requiredIf({
218 service_type: 'nvmeof'
221 enable_mtls: [false],
225 CdValidators.composeIf(
227 service_type: 'nvmeof',
230 [Validators.required]
237 CdValidators.composeIf(
239 service_type: 'nvmeof',
242 [Validators.required]
249 CdValidators.composeIf(
251 service_type: 'nvmeof',
254 [Validators.required]
261 CdValidators.composeIf(
263 service_type: 'nvmeof',
266 [Validators.required]
273 CdValidators.composeIf(
275 service_type: 'nvmeof',
278 [Validators.required]
283 rgw_frontend_port: [null, [CdValidators.number(false)]],
285 zonegroup_name: [null],
288 trusted_ip_list: [null],
289 api_port: [null, [CdValidators.number(false)]],
293 CdValidators.requiredIf({
294 service_type: 'iscsi',
302 CdValidators.requiredIf({
303 service_type: 'iscsi',
312 CdValidators.requiredIf({
317 features: new CdFormGroup(
318 this.smbFeaturesList.reduce((acc: object, e) => {
319 acc[e] = new UntypedFormControl(false);
326 CdValidators.composeIf(
332 CdValidators.custom('configUriPattern', (value: string) => {
333 if (_.isEmpty(value)) {
336 return !this.SMB_CONFIG_URI_PATTERN.test(value);
343 join_sources: [null],
344 user_sources: [null],
345 include_ceph_users: [null],
350 CdValidators.requiredIf({
351 service_type: 'ingress'
358 CdValidators.requiredIf({
359 service_type: 'ingress'
366 CdValidators.number(false),
367 CdValidators.requiredIf({
368 service_type: 'ingress'
375 CdValidators.number(false),
376 CdValidators.requiredIf({
377 service_type: 'ingress'
381 virtual_interface_networks: [null],
382 ssl_protocols: [this.DEFAULT_SSL_PROTOCOL_ITEM],
386 CdValidators.custom('invalidPattern', (ciphers: string) => {
387 if (_.isEmpty(ciphers)) {
390 return !this.SSL_CIPHERS_PATTERN.test(ciphers);
394 // RGW, Ingress & iSCSI
399 CdValidators.composeIf(
405 [Validators.required, CdValidators.pemCert()]
407 CdValidators.composeIf(
409 service_type: 'iscsi',
413 [Validators.required, CdValidators.sslCert()]
415 CdValidators.composeIf(
417 service_type: 'ingress',
421 [Validators.required, CdValidators.pemCert()]
423 CdValidators.composeIf(
425 service_type: 'oauth2-proxy',
429 [Validators.required, CdValidators.sslCert()]
431 CdValidators.composeIf(
433 service_type: 'mgmt-gateway',
437 [CdValidators.sslCert()]
444 CdValidators.composeIf(
446 service_type: 'iscsi',
450 [Validators.required, CdValidators.sslPrivKey()]
452 CdValidators.composeIf(
454 service_type: 'oauth2-proxy',
458 [Validators.required, CdValidators.sslPrivKey()]
460 CdValidators.composeIf(
462 service_type: 'mgmt-gateway',
466 [CdValidators.sslPrivKey()]
472 port: [443, [CdValidators.number(false)]],
477 CdValidators.requiredIf({
478 service_type: 'snmp-gateway'
486 CdValidators.requiredIf({
487 service_type: 'snmp-gateway'
489 CdValidators.custom('snmpDestinationPattern', (value: string) => {
490 if (_.isEmpty(value)) {
493 return !this.SNMP_DESTINATION_PATTERN.test(value);
501 CdValidators.requiredIf({
502 service_type: 'snmp-gateway'
504 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
505 if (_.isEmpty(value)) {
508 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
515 CdValidators.requiredIf({
516 service_type: 'snmp-gateway'
520 privacy_protocol: [null],
524 CdValidators.requiredIf({
529 snmp_v3_auth_username: [
532 CdValidators.requiredIf({
533 service_type: 'snmp-gateway'
537 snmp_v3_auth_password: [
540 CdValidators.requiredIf({
541 service_type: 'snmp-gateway'
545 snmp_v3_priv_password: [
548 CdValidators.requiredIf({
549 privacy_protocol: { op: '!empty' }
553 grafana_port: [null, [CdValidators.number(false)]],
554 grafana_admin_password: [null],
556 provider_display_name: [
559 CdValidators.requiredIf({
560 service_type: 'oauth2-proxy'
567 CdValidators.requiredIf({
568 service_type: 'oauth2-proxy'
575 CdValidators.requiredIf({
576 service_type: 'oauth2-proxy'
583 CdValidators.requiredIf({
584 service_type: 'oauth2-proxy'
586 CdValidators.custom('validUrl', (url: string) => {
587 if (_.isEmpty(url)) {
590 return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
594 https_address: [null, [CdValidators.oauthAddressTest()]],
595 redirect_url: [null],
596 allowlist_domains: [null]
601 if (this.router.url.includes('services/(modal:create')) {
602 this.pageURL = 'services';
603 this.route.params.subscribe((params: { type: string }) => {
605 this.serviceType = params.type;
606 this.serviceForm.get('service_type').setValue(this.serviceType);
609 } else if (this.router.url.includes('services/(modal:edit')) {
611 this.pageURL = 'services';
612 this.route.params.subscribe((params: { type: string; name: string }) => {
613 this.serviceName = params.name;
614 this.serviceType = params.type;
620 this.action = this.actionLabels.CREATE;
623 this.cephServiceService
624 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
625 .observable.subscribe((services: CephServiceSpec[]) => {
626 this.serviceList = services;
627 this.services = services.filter((service: any) =>
628 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
632 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
633 // Remove service types:
634 // osd - This is deployed a different way.
635 // container - This should only be used in the CLI.
636 // promtail - This is deprecated and replaced by alloy.
637 this.hiddenServices.push('osd', 'container', 'promtail');
639 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
641 this.hostService.getAllHosts().subscribe((resp: Host[]) => {
642 const options: SelectOption[] = [];
643 _.forEach(resp, (host: Host) => {
644 if (_.get(host, 'sources.orchestrator', false)) {
645 const option = new SelectOption(false, _.get(host, 'hostname'), '');
646 options.push(option);
649 this.hosts.options = [...options];
651 this.hostService.getLabels().subscribe((resp: string[]) => {
654 this.poolService.getList().subscribe((resp: Pool[]) => {
656 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
657 if (!this.editing && this.serviceType) {
658 this.onServiceTypeChange(this.serviceType);
663 this.action = this.actionLabels.EDIT;
664 this.disableForEditing(this.serviceType);
665 this.cephServiceService
666 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
667 .observable.subscribe((response: CephServiceSpec[]) => {
668 const formKeys = ['service_type', 'service_id', 'unmanaged'];
669 formKeys.forEach((keys) => {
670 this.serviceForm.get(keys).setValue(response[0][keys]);
672 if (!response[0]['unmanaged']) {
673 const placementKey = Object.keys(response[0]['placement'])[0];
674 let placementValue: string;
675 ['hosts', 'label'].indexOf(placementKey) >= 0
676 ? (placementValue = placementKey)
677 : (placementValue = 'hosts');
678 this.serviceForm.get('placement').setValue(placementValue);
679 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
680 if (response[0]?.placement[placementValue]) {
681 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
684 switch (this.serviceType) {
686 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
687 specKeys.forEach((key) => {
688 this.serviceForm.get(key).setValue(response[0].spec[key]);
690 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
691 if (response[0].spec?.api_secure) {
692 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
693 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
697 this.serviceForm.get('pool').setValue(response[0].spec.pool);
698 this.serviceForm.get('group').setValue(response[0].spec.group);
699 this.serviceForm.get('enable_mtls').setValue(response[0].spec?.enable_auth);
700 this.serviceForm.get('root_ca_cert').setValue(response[0].spec?.root_ca_cert);
701 this.serviceForm.get('client_cert').setValue(response[0].spec?.client_cert);
702 this.serviceForm.get('client_key').setValue(response[0].spec?.client_key);
703 this.serviceForm.get('server_cert').setValue(response[0].spec?.server_cert);
704 this.serviceForm.get('server_key').setValue(response[0].spec?.server_key);
708 .get('rgw_frontend_port')
709 .setValue(response[0].spec?.rgw_frontend_port);
711 response[0].spec?.rgw_realm,
712 response[0].spec?.rgw_zonegroup,
713 response[0].spec?.rgw_zone
715 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
716 if (response[0].spec?.ssl) {
719 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
723 const ingressSpecKeys = [
728 'virtual_interface_networks',
731 ingressSpecKeys.forEach((key) => {
732 this.serviceForm.get(key).setValue(response[0].spec[key]);
734 if (response[0].spec?.ssl) {
735 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
736 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
740 let hrefSplitted = window.location.href.split(':');
741 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
742 this.port = response[0].spec?.port;
744 if (response[0].spec?.ssl_protocols) {
745 let selectedValues: Array<ListItem> = [];
746 for (const value of response[0].spec.ssl_protocols) {
747 selectedValues.push({ content: value, selected: true });
749 this.serviceForm.get('ssl_protocols').setValue(selectedValues);
751 if (response[0].spec?.ssl_ciphers) {
754 .setValue(response[0].spec?.ssl_ciphers.join(':'));
756 if (response[0].spec?.ssl_cert) {
757 this.serviceForm.get('ssl_cert').setValue(response[0].spec.ssl_cert);
759 if (response[0].spec?.ssl_key) {
760 this.serviceForm.get('ssl_key').setValue(response[0].spec.ssl_key);
762 if (response[0].spec?.enable_auth) {
763 this.serviceForm.get('enable_auth').setValue(response[0].spec.enable_auth);
765 if (response[0].spec?.port) {
766 this.serviceForm.get('port').setValue(response[0].spec.port);
770 const smbSpecKeys = [
779 smbSpecKeys.forEach((key) => {
780 if (key === 'features') {
781 if (response[0].spec?.features) {
782 response[0].spec.features.forEach((feature) => {
783 this.serviceForm.get(`features.${feature}`).setValue(true);
787 this.serviceForm.get(key).setValue(response[0].spec[key]);
792 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
793 snmpCommonSpecKeys.forEach((key) => {
794 this.serviceForm.get(key).setValue(response[0].spec[key]);
796 if (this.serviceForm.getValue('snmp_version') === 'V3') {
797 const snmpV3SpecKeys = [
801 'snmp_v3_auth_username',
802 'snmp_v3_auth_password',
803 'snmp_v3_priv_password'
805 snmpV3SpecKeys.forEach((key) => {
808 key === 'snmp_v3_auth_username' ||
809 key === 'snmp_v3_auth_password' ||
810 key === 'snmp_v3_priv_password'
812 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
814 this.serviceForm.get(key).setValue(response[0].spec[key]);
820 .get('snmp_community')
821 .setValue(response[0].spec['credentials']['snmp_community']);
825 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
827 .get('grafana_admin_password')
828 .setValue(response[0].spec.initial_admin_password);
831 const oauth2SpecKeys = [
833 'provider_display_name',
840 oauth2SpecKeys.forEach((key) => {
841 this.serviceForm.get(key).setValue(response[0].spec[key]);
843 if (response[0].spec?.ssl) {
844 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
845 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
850 this.detectChanges();
853 detectChanges(): void {
854 const service_type = this.serviceForm.get('service_type');
856 service_type.valueChanges.subscribe((value) => {
857 if (value === 'mgmt-gateway') {
858 const port = this.serviceForm.get('port');
860 port.valueChanges.subscribe((_) => {
861 this.showMgmtGatewayMessage = true;
864 const ssl_protocols = this.serviceForm.get('ssl_protocols');
866 ssl_protocols.valueChanges.subscribe((_) => {
867 this.showMgmtGatewayMessage = true;
870 const ssl_ciphers = this.serviceForm.get('ssl_ciphers');
872 ssl_ciphers.valueChanges.subscribe((_) => {
873 this.showMgmtGatewayMessage = true;
881 getDefaultsEntitiesForRgw(
882 defaultRealmId: string,
883 defaultZonegroupId: string,
884 defaultZoneId: string
885 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
886 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
887 const defaultZonegroup = this.zonegroupList.find(
888 (x: { id: string }) => x.id === defaultZonegroupId
890 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
891 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
892 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
893 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
894 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
895 const defaultZonegroup = new RgwZonegroup();
896 defaultZonegroup.name = 'default';
897 this.zonegroupList.push(defaultZonegroup);
899 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
900 const defaultZone = new RgwZone();
901 defaultZone.name = 'default';
902 this.zoneList.push(defaultZone);
905 defaultRealmName: defaultRealmName,
906 defaultZonegroupName: defaultZonegroupName,
907 defaultZoneName: defaultZoneName
911 getDefaultPlacementCount(serviceType: string) {
913 * `defaults` from src/pybind/mgr/cephadm/module.py
915 switch (serviceType) {
917 this.serviceForm.get('count').setValue(5);
924 this.serviceForm.get('count').setValue(2);
927 case 'cephfs-mirror':
935 case 'elastic-serach':
936 case 'jaeger-collector':
941 this.serviceForm.get('count').setValue(1);
944 this.serviceForm.get('count').setValue(null);
948 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
949 const observables = [
950 this.rgwRealmService.getAllRealmsInfo(),
951 this.rgwZonegroupService.getAllZonegroupsInfo(),
952 this.rgwZoneService.getAllZonesInfo()
954 this.sub = forkJoin(observables).subscribe(
955 (multisiteInfo: [object, object, object]) => {
956 this.multisiteInfo = multisiteInfo;
958 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
959 ? this.multisiteInfo[0]['realms']
962 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
963 ? this.multisiteInfo[1]['zonegroups']
966 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
967 ? this.multisiteInfo[2]['zones']
969 this.realmNames = this.realmList.map((realm) => {
970 return realm['name'];
972 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
973 return zonegroup['name'];
975 this.zoneNames = this.zoneList.map((zone) => {
978 this.defaultRealmId = multisiteInfo[0]['default_realm'];
979 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
980 this.defaultZoneId = multisiteInfo[2]['default_zone'];
981 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
983 this.defaultZonegroupId,
987 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
989 .get('zonegroup_name')
990 .setValue(this.defaultsInfo['defaultZonegroupName']);
991 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
993 if (realm_name && !this.realmNames.includes(realm_name)) {
994 const realm = new RgwRealm();
995 realm.name = realm_name;
996 this.realmList.push(realm);
998 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
999 const zonegroup = new RgwZonegroup();
1000 zonegroup.name = zonegroup_name;
1001 this.zonegroupList.push(zonegroup);
1003 if (zone_name && !this.zoneNames.includes(zone_name)) {
1004 const zone = new RgwZone();
1005 zone.name = zone_name;
1006 this.zoneList.push(zone);
1008 if (zonegroup_name === undefined && zone_name === undefined) {
1009 zonegroup_name = 'default';
1010 zone_name = 'default';
1012 this.serviceForm.get('realm_name').setValue(realm_name);
1013 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
1014 this.serviceForm.get('zone_name').setValue(zone_name);
1016 if (this.realmList.length === 0) {
1017 this.showRealmCreationForm = true;
1019 this.showRealmCreationForm = false;
1023 const defaultZone = new RgwZone();
1024 defaultZone.name = 'default';
1025 const defaultZonegroup = new RgwZonegroup();
1026 defaultZonegroup.name = 'default';
1027 this.zoneList.push(defaultZone);
1028 this.zonegroupList.push(defaultZonegroup);
1033 setNvmeServiceId() {
1034 const pool = this.serviceForm.get('pool').value;
1035 const group = this.serviceForm.get('group').value;
1036 if (pool && group) {
1037 this.serviceForm.get('service_id').setValue(`${pool}.${group}`);
1039 this.serviceForm.get('service_id').setValue(pool);
1041 this.serviceForm.get('service_id').setValue(group);
1043 this.serviceForm.get('service_id').setValue(null);
1047 setNvmeDefaultPool() {
1049 this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')?.pool_name ||
1050 this.rbdPools?.[0].pool_name;
1051 this.serviceForm.get('pool').setValue(defaultPool);
1054 requiresServiceId(serviceType: string) {
1055 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
1058 setServiceId(serviceId: string): void {
1059 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
1060 if (requiresServiceId && serviceId === 'nvmeof') {
1061 this.setNvmeDefaultPool();
1062 this.setNvmeServiceId();
1063 } else if (requiresServiceId) {
1064 this.serviceForm.get('service_id').setValue(null);
1066 this.serviceForm.get('service_id').setValue(serviceId);
1070 onServiceTypeChange(selectedServiceType: string) {
1071 this.setServiceId(selectedServiceType);
1073 this.serviceIds = this.serviceList
1074 ?.filter((service) => service['service_type'] === selectedServiceType)
1075 .map((service) => service['service_id']);
1077 this.getDefaultPlacementCount(selectedServiceType);
1079 if (selectedServiceType === 'rgw') {
1080 this.setRgwFields();
1082 if (selectedServiceType === 'mgmt-gateway') {
1083 let hrefSplitted = window.location.href.split(':');
1084 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
1085 // mgmt-gateway lacks HA for now
1086 this.serviceForm.get('count').disable();
1088 this.serviceForm.get('count').enable();
1092 onPlacementChange(selected: string) {
1093 if (selected === 'label') {
1094 this.serviceForm.get('count').setValue(null);
1098 disableForEditing(serviceType: string) {
1099 const disableForEditKeys = ['service_type', 'service_id'];
1100 disableForEditKeys.forEach((key) => {
1101 this.serviceForm.get(key).disable();
1103 switch (serviceType) {
1105 this.serviceForm.get('backend_service').disable();
1108 this.serviceForm.get('pool').disable();
1109 this.serviceForm.get('group').disable();
1114 searchLabels = (text$: Observable<string>) => {
1116 text$.pipe(debounceTime(200), distinctUntilChanged()),
1118 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
1122 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
1128 fileUpload(files: FileList, controlName: string) {
1129 const file: File = files[0];
1130 const reader = new FileReader();
1131 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
1132 const control: AbstractControl = this.serviceForm.get(controlName);
1133 control.setValue(event.target.result);
1134 control.markAsDirty();
1135 control.markAsTouched();
1136 control.updateValueAndValidity();
1138 reader.readAsText(file, 'utf8');
1142 const control: AbstractControl = this.serviceForm.get('service_id');
1143 const backendService = this.serviceForm.getValue('backend_service');
1144 // Set Id as read-only
1145 control.reset({ value: backendService, disabled: true });
1150 const values: object = this.serviceForm.getRawValue();
1151 const serviceType: string = values['service_type'];
1152 let taskUrl = `service/${URLVerbs.CREATE}`;
1154 taskUrl = `service/${URLVerbs.EDIT}`;
1156 const serviceSpec: object = {
1157 service_type: serviceType,
1159 unmanaged: values['unmanaged']
1161 if (serviceType === 'rgw') {
1162 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
1163 serviceSpec['rgw_zonegroup'] =
1164 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
1165 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
1168 const serviceId: string = values['service_id'];
1169 let serviceName: string = serviceType;
1170 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
1171 serviceName = `${serviceType}.${serviceId}`;
1172 serviceSpec['service_id'] = serviceId;
1175 // These services has some fields to be
1176 // filled out even if unmanaged is true
1177 switch (serviceType) {
1179 serviceSpec['backend_service'] = values['backend_service'];
1180 serviceSpec['service_id'] = values['backend_service'];
1181 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
1182 serviceSpec['frontend_port'] = values['frontend_port'];
1184 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1185 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1187 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1188 serviceSpec['monitor_port'] = values['monitor_port'];
1193 serviceSpec['pool'] = values['pool'];
1194 serviceSpec['group'] = values['group'];
1195 serviceSpec['enable_auth'] = values['enable_mtls'];
1196 if (values['enable_mtls']) {
1197 serviceSpec['root_ca_cert'] = values['root_ca_cert'];
1198 serviceSpec['client_cert'] = values['client_cert'];
1199 serviceSpec['client_key'] = values['client_key'];
1200 serviceSpec['server_cert'] = values['server_cert'];
1201 serviceSpec['server_key'] = values['server_key'];
1205 serviceSpec['pool'] = values['pool'];
1209 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
1210 serviceSpec['config_uri'] = values['config_uri']?.trim();
1211 for (const feature in values['features']) {
1212 if (values['features'][feature]) {
1213 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
1216 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
1217 serviceSpec['join_sources'] = values['join_sources']?.trim();
1218 serviceSpec['user_sources'] = values['user_sources']?.trim();
1219 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
1222 case 'snmp-gateway':
1223 serviceSpec['credentials'] = {};
1224 serviceSpec['snmp_version'] = values['snmp_version'];
1225 serviceSpec['snmp_destination'] = values['snmp_destination'];
1226 if (values['snmp_version'] === 'V3') {
1227 serviceSpec['engine_id'] = values['engine_id'];
1228 serviceSpec['auth_protocol'] = values['auth_protocol'];
1229 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
1230 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
1231 if (values['privacy_protocol'] !== null) {
1232 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
1233 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
1236 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1241 if (!values['unmanaged']) {
1242 switch (values['placement']) {
1244 if (values['hosts'].length > 0) {
1245 serviceSpec['placement']['hosts'] = values['hosts'];
1249 serviceSpec['placement']['label'] = values['label'];
1252 if (_.isNumber(values['count']) && values['count'] > 0) {
1253 serviceSpec['placement']['count'] = values['count'];
1255 switch (serviceType) {
1257 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1258 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1260 serviceSpec['ssl'] = values['ssl'];
1261 if (values['ssl']) {
1262 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1266 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1267 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1269 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1270 serviceSpec['api_port'] = values['api_port'];
1272 serviceSpec['api_user'] = values['api_user'];
1273 serviceSpec['api_password'] = values['api_password'];
1274 serviceSpec['api_secure'] = values['ssl'];
1275 if (values['ssl']) {
1276 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1277 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1281 serviceSpec['ssl'] = values['ssl'];
1282 if (values['ssl']) {
1283 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1284 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1286 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1288 case 'mgmt-gateway':
1289 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1290 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1291 serviceSpec['enable_auth'] = values['enable_auth'];
1292 serviceSpec['port'] = values['port'];
1293 if (serviceSpec['port'] === (443 || 80)) {
1294 // omit port default values due to issues with redirect_url on the backend
1295 delete serviceSpec['port'];
1297 serviceSpec['ssl_protocols'] = [];
1298 if (values['ssl_protocols'] != this.DEFAULT_SSL_PROTOCOL_ITEM) {
1299 for (const key of Object.keys(values['ssl_protocols'])) {
1300 serviceSpec['ssl_protocols'].push(values['ssl_protocols'][key]['content']);
1303 serviceSpec['ssl_ciphers'] = values['ssl_ciphers']?.trim().split(':');
1306 serviceSpec['port'] = values['grafana_port'];
1307 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1309 case 'oauth2-proxy':
1310 serviceSpec['provider_display_name'] = values['provider_display_name']?.trim();
1311 serviceSpec['client_id'] = values['client_id']?.trim();
1312 serviceSpec['client_secret'] = values['client_secret']?.trim();
1313 serviceSpec['oidc_issuer_url'] = values['oidc_issuer_url']?.trim();
1314 serviceSpec['https_address'] = values['https_address']?.trim();
1315 serviceSpec['redirect_url'] = values['redirect_url']?.trim();
1316 serviceSpec['allowlist_domains'] = values['allowlist_domains']
1318 .map((domain: string) => {
1319 return domain.trim();
1321 if (values['ssl']) {
1322 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1323 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1328 this.taskWrapperService
1329 .wrapTaskAroundCall({
1330 task: new FinishedTask(taskUrl, {
1331 service_name: serviceName
1334 ? this.cephServiceService.update(serviceSpec)
1335 : this.cephServiceService.create(serviceSpec)
1339 self.serviceForm.setErrors({ cdSubmitButton: true });
1342 this.pageURL === 'services'
1343 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1344 : this.activeModal.close();
1349 clearValidations() {
1350 const snmpVersion = this.serviceForm.getValue('snmp_version');
1351 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1352 if (snmpVersion === 'V3') {
1353 this.serviceForm.get('snmp_community').clearValidators();
1355 this.serviceForm.get('engine_id').clearValidators();
1356 this.serviceForm.get('auth_protocol').clearValidators();
1357 this.serviceForm.get('privacy_protocol').clearValidators();
1358 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1359 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1361 if (privacyProtocol === null) {
1362 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1366 createMultisiteSetup() {
1367 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1370 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1371 this.setRgwFields();