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, 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';
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;
110 qatCompressionOptions = [
111 { value: QatOptions.hw, label: 'Hardware' },
112 { value: QatOptions.sw, label: 'Software' },
113 { value: QatOptions.none, label: 'None' }
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
136 this.resource = $localize`service`;
139 messages: new SelectMessages({
140 empty: $localize`There are no hosts.`,
141 filter: $localize`Filter hosts`
148 this.serviceForm = this.formBuilder.group({
150 service_type: [null, [Validators.required]],
154 CdValidators.composeIf(
160 CdValidators.custom('mdsPattern', (value: string) => {
161 if (_.isEmpty(value)) {
164 return !this.MDS_SVC_ID_PATTERN.test(value);
168 CdValidators.requiredIf({
171 CdValidators.requiredIf({
172 service_type: 'iscsi'
174 CdValidators.requiredIf({
175 service_type: 'nvmeof'
177 CdValidators.requiredIf({
178 service_type: 'ingress'
180 CdValidators.requiredIf({
183 CdValidators.composeIf(
187 [Validators.required]
189 CdValidators.custom('uniqueName', (service_id: string) => {
190 return this.serviceIds && this.serviceIds.includes(service_id);
194 placement: ['hosts'],
198 CdValidators.requiredIf({
205 count: [null, [CdValidators.number(false)]],
212 CdValidators.requiredIf({
213 service_type: 'iscsi'
215 CdValidators.requiredIf({
216 service_type: 'nvmeof'
222 CdValidators.requiredIf({
223 service_type: 'nvmeof'
226 enable_mtls: [false],
230 CdValidators.composeIf(
232 service_type: 'nvmeof',
235 [Validators.required]
242 CdValidators.composeIf(
244 service_type: 'nvmeof',
247 [Validators.required]
254 CdValidators.composeIf(
256 service_type: 'nvmeof',
259 [Validators.required]
266 CdValidators.composeIf(
268 service_type: 'nvmeof',
271 [Validators.required]
278 CdValidators.composeIf(
280 service_type: 'nvmeof',
283 [Validators.required]
288 rgw_frontend_port: [null, [CdValidators.number(false)]],
290 zonegroup_name: [null],
292 qat: new CdFormGroup({
293 compression: new UntypedFormControl(QatOptions.none)
296 trusted_ip_list: [null],
297 api_port: [null, [CdValidators.number(false)]],
301 CdValidators.requiredIf({
302 service_type: 'iscsi',
310 CdValidators.requiredIf({
311 service_type: 'iscsi',
320 CdValidators.requiredIf({
325 features: new CdFormGroup(
326 this.smbFeaturesList.reduce((acc: object, e) => {
327 acc[e] = new UntypedFormControl(false);
334 CdValidators.composeIf(
340 CdValidators.custom('configUriPattern', (value: string) => {
341 if (_.isEmpty(value)) {
344 return !this.SMB_CONFIG_URI_PATTERN.test(value);
351 join_sources: [null],
352 user_sources: [null],
353 include_ceph_users: [null],
358 CdValidators.requiredIf({
359 service_type: 'ingress'
366 CdValidators.requiredIf({
367 service_type: 'ingress'
374 CdValidators.number(false),
375 CdValidators.requiredIf({
376 service_type: 'ingress'
383 CdValidators.number(false),
384 CdValidators.requiredIf({
385 service_type: 'ingress'
389 virtual_interface_networks: [null],
390 ssl_protocols: [this.DEFAULT_SSL_PROTOCOL_ITEM],
394 CdValidators.custom('invalidPattern', (ciphers: string) => {
395 if (_.isEmpty(ciphers)) {
398 return !this.SSL_CIPHERS_PATTERN.test(ciphers);
402 // RGW, Ingress & iSCSI
407 CdValidators.composeIf(
413 [Validators.required, CdValidators.pemCert()]
415 CdValidators.composeIf(
417 service_type: 'iscsi',
421 [Validators.required, CdValidators.sslCert()]
423 CdValidators.composeIf(
425 service_type: 'ingress',
429 [Validators.required, CdValidators.pemCert()]
431 CdValidators.composeIf(
433 service_type: 'oauth2-proxy',
437 [Validators.required, CdValidators.sslCert()]
439 CdValidators.composeIf(
441 service_type: 'mgmt-gateway',
445 [CdValidators.sslCert()]
452 CdValidators.composeIf(
454 service_type: 'iscsi',
458 [Validators.required, CdValidators.sslPrivKey()]
460 CdValidators.composeIf(
462 service_type: 'oauth2-proxy',
466 [Validators.required, CdValidators.sslPrivKey()]
468 CdValidators.composeIf(
470 service_type: 'mgmt-gateway',
474 [CdValidators.sslPrivKey()]
480 port: [443, [CdValidators.number(false)]],
485 CdValidators.requiredIf({
486 service_type: 'snmp-gateway'
494 CdValidators.requiredIf({
495 service_type: 'snmp-gateway'
497 CdValidators.custom('snmpDestinationPattern', (value: string) => {
498 if (_.isEmpty(value)) {
501 return !this.SNMP_DESTINATION_PATTERN.test(value);
509 CdValidators.requiredIf({
510 service_type: 'snmp-gateway'
512 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
513 if (_.isEmpty(value)) {
516 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
523 CdValidators.requiredIf({
524 service_type: 'snmp-gateway'
528 privacy_protocol: [null],
532 CdValidators.requiredIf({
537 snmp_v3_auth_username: [
540 CdValidators.requiredIf({
541 service_type: 'snmp-gateway'
545 snmp_v3_auth_password: [
548 CdValidators.requiredIf({
549 service_type: 'snmp-gateway'
553 snmp_v3_priv_password: [
556 CdValidators.requiredIf({
557 privacy_protocol: { op: '!empty' }
561 grafana_port: [null, [CdValidators.number(false)]],
562 grafana_admin_password: [null],
564 provider_display_name: [
567 CdValidators.requiredIf({
568 service_type: 'oauth2-proxy'
575 CdValidators.requiredIf({
576 service_type: 'oauth2-proxy'
583 CdValidators.requiredIf({
584 service_type: 'oauth2-proxy'
591 CdValidators.requiredIf({
592 service_type: 'oauth2-proxy'
594 CdValidators.custom('validUrl', (url: string) => {
595 if (_.isEmpty(url)) {
598 return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
602 https_address: [null, [CdValidators.oauthAddressTest()]],
603 redirect_url: [null],
604 allowlist_domains: [null]
609 if (this.router.url.includes('services/(modal:create')) {
610 this.pageURL = 'services';
611 this.route.params.subscribe((params: { type: string }) => {
613 this.serviceType = params.type;
614 this.serviceForm.get('service_type').setValue(this.serviceType);
617 } else if (this.router.url.includes('services/(modal:edit')) {
619 this.pageURL = 'services';
620 this.route.params.subscribe((params: { type: string; name: string }) => {
621 this.serviceName = params.name;
622 this.serviceType = params.type;
628 this.action = this.actionLabels.CREATE;
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)
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');
646 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
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);
656 this.hosts.options = [...options];
658 this.hostService.getLabels().subscribe((resp: string[]) => {
661 this.poolService.getList().subscribe((resp: Pool[]) => {
663 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
664 if (!this.editing && this.serviceType) {
665 this.onServiceTypeChange(this.serviceType);
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]);
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]);
691 switch (this.serviceType) {
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]);
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);
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);
715 .get('rgw_frontend_port')
716 .setValue(response[0].spec?.rgw_frontend_port);
718 response[0].spec?.rgw_realm,
719 response[0].spec?.rgw_zonegroup,
720 response[0].spec?.rgw_zone,
721 response[0].spec?.qat
723 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
724 if (response[0].spec?.ssl) {
727 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
731 const ingressSpecKeys = [
736 'virtual_interface_networks',
739 ingressSpecKeys.forEach((key) => {
740 this.serviceForm.get(key).setValue(response[0].spec[key]);
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);
748 let hrefSplitted = window.location.href.split(':');
749 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
750 this.port = response[0].spec?.port;
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 });
757 this.serviceForm.get('ssl_protocols').setValue(selectedValues);
759 if (response[0].spec?.ssl_ciphers) {
762 .setValue(response[0].spec?.ssl_ciphers.join(':'));
764 if (response[0].spec?.ssl_cert) {
765 this.serviceForm.get('ssl_cert').setValue(response[0].spec.ssl_cert);
767 if (response[0].spec?.ssl_key) {
768 this.serviceForm.get('ssl_key').setValue(response[0].spec.ssl_key);
770 if (response[0].spec?.enable_auth) {
771 this.serviceForm.get('enable_auth').setValue(response[0].spec.enable_auth);
773 if (response[0].spec?.port) {
774 this.serviceForm.get('port').setValue(response[0].spec.port);
778 const smbSpecKeys = [
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);
795 this.serviceForm.get(key).setValue(response[0].spec[key]);
800 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
801 snmpCommonSpecKeys.forEach((key) => {
802 this.serviceForm.get(key).setValue(response[0].spec[key]);
804 if (this.serviceForm.getValue('snmp_version') === 'V3') {
805 const snmpV3SpecKeys = [
809 'snmp_v3_auth_username',
810 'snmp_v3_auth_password',
811 'snmp_v3_priv_password'
813 snmpV3SpecKeys.forEach((key) => {
816 key === 'snmp_v3_auth_username' ||
817 key === 'snmp_v3_auth_password' ||
818 key === 'snmp_v3_priv_password'
820 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
822 this.serviceForm.get(key).setValue(response[0].spec[key]);
828 .get('snmp_community')
829 .setValue(response[0].spec['credentials']['snmp_community']);
833 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
835 .get('grafana_admin_password')
836 .setValue(response[0].spec.initial_admin_password);
839 const oauth2SpecKeys = [
841 'provider_display_name',
848 oauth2SpecKeys.forEach((key) => {
849 this.serviceForm.get(key).setValue(response[0].spec[key]);
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);
858 this.detectChanges();
861 detectChanges(): void {
862 const service_type = this.serviceForm.get('service_type');
864 service_type.valueChanges.subscribe((value) => {
865 if (value === 'mgmt-gateway') {
866 const port = this.serviceForm.get('port');
868 port.valueChanges.subscribe((_) => {
869 this.showMgmtGatewayMessage = true;
872 const ssl_protocols = this.serviceForm.get('ssl_protocols');
874 ssl_protocols.valueChanges.subscribe((_) => {
875 this.showMgmtGatewayMessage = true;
878 const ssl_ciphers = this.serviceForm.get('ssl_ciphers');
880 ssl_ciphers.valueChanges.subscribe((_) => {
881 this.showMgmtGatewayMessage = true;
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
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);
907 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
908 const defaultZone = new RgwZone();
909 defaultZone.name = 'default';
910 this.zoneList.push(defaultZone);
913 defaultRealmName: defaultRealmName,
914 defaultZonegroupName: defaultZonegroupName,
915 defaultZoneName: defaultZoneName
919 getDefaultPlacementCount(serviceType: string) {
921 * `defaults` from src/pybind/mgr/cephadm/module.py
923 switch (serviceType) {
925 this.serviceForm.get('count').setValue(5);
932 this.serviceForm.get('count').setValue(2);
935 case 'cephfs-mirror':
943 case 'elastic-serach':
944 case 'jaeger-collector':
949 this.serviceForm.get('count').setValue(1);
952 this.serviceForm.get('count').setValue(null);
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()
962 this.sub = forkJoin(observables).subscribe(
963 (multisiteInfo: [object, object, object]) => {
964 this.multisiteInfo = multisiteInfo;
966 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
967 ? this.multisiteInfo[0]['realms']
970 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
971 ? this.multisiteInfo[1]['zonegroups']
974 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
975 ? this.multisiteInfo[2]['zones']
977 this.realmNames = this.realmList.map((realm) => {
978 return realm['name'];
980 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
981 return zonegroup['name'];
983 this.zoneNames = this.zoneList.map((zone) => {
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(
991 this.defaultZonegroupId,
995 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
997 .get('zonegroup_name')
998 .setValue(this.defaultsInfo['defaultZonegroupName']);
999 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
1001 if (realm_name && !this.realmNames.includes(realm_name)) {
1002 const realm = new RgwRealm();
1003 realm.name = realm_name;
1004 this.realmList.push(realm);
1006 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
1007 const zonegroup = new RgwZonegroup();
1008 zonegroup.name = zonegroup_name;
1009 this.zonegroupList.push(zonegroup);
1011 if (zone_name && !this.zoneNames.includes(zone_name)) {
1012 const zone = new RgwZone();
1013 zone.name = zone_name;
1014 this.zoneList.push(zone);
1016 if (zonegroup_name === undefined && zone_name === undefined) {
1017 zonegroup_name = 'default';
1018 zone_name = 'default';
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);
1025 this.serviceForm.get(`qat.compression`)?.setValue(qat['compression']);
1027 if (this.realmList.length === 0) {
1028 this.showRealmCreationForm = true;
1030 this.showRealmCreationForm = false;
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);
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}`);
1050 this.serviceForm.get('service_id').setValue(pool);
1052 this.serviceForm.get('service_id').setValue(group);
1054 this.serviceForm.get('service_id').setValue(null);
1058 setNvmeDefaultPool() {
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);
1065 requiresServiceId(serviceType: string) {
1066 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
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);
1077 this.serviceForm.get('service_id').setValue(serviceId);
1081 onServiceTypeChange(selectedServiceType: string) {
1082 this.setServiceId(selectedServiceType);
1084 this.serviceIds = this.serviceList
1085 ?.filter((service) => service['service_type'] === selectedServiceType)
1086 .map((service) => service['service_id']);
1088 this.getDefaultPlacementCount(selectedServiceType);
1090 if (selectedServiceType === 'rgw') {
1091 this.setRgwFields();
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();
1099 this.serviceForm.get('count').enable();
1103 onPlacementChange(selected: string) {
1104 if (selected === 'label') {
1105 this.serviceForm.get('count').setValue(null);
1109 disableForEditing(serviceType: string) {
1110 const disableForEditKeys = ['service_type', 'service_id'];
1111 disableForEditKeys.forEach((key) => {
1112 this.serviceForm.get(key).disable();
1114 switch (serviceType) {
1116 this.serviceForm.get('backend_service').disable();
1119 this.serviceForm.get('pool').disable();
1120 this.serviceForm.get('group').disable();
1125 searchLabels = (text$: Observable<string>) => {
1127 text$.pipe(debounceTime(200), distinctUntilChanged()),
1129 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
1133 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
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();
1149 reader.readAsText(file, 'utf8');
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 });
1161 const values: object = this.serviceForm.getRawValue();
1162 const serviceType: string = values['service_type'];
1163 let taskUrl = `service/${URLVerbs.CREATE}`;
1165 taskUrl = `service/${URLVerbs.EDIT}`;
1167 const serviceSpec: object = {
1168 service_type: serviceType,
1170 unmanaged: values['unmanaged']
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'];
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;
1191 // These services has some fields to be
1192 // filled out even if unmanaged is true
1193 switch (serviceType) {
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'];
1200 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1201 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1203 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1204 serviceSpec['monitor_port'] = values['monitor_port'];
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'];
1221 serviceSpec['pool'] = values['pool'];
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);
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();
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'];
1252 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1257 if (!values['unmanaged']) {
1258 switch (values['placement']) {
1260 if (values['hosts'].length > 0) {
1261 serviceSpec['placement']['hosts'] = values['hosts'];
1265 serviceSpec['placement']['label'] = values['label'];
1268 if (_.isNumber(values['count']) && values['count'] > 0) {
1269 serviceSpec['placement']['count'] = values['count'];
1271 switch (serviceType) {
1273 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1274 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1276 serviceSpec['ssl'] = values['ssl'];
1277 if (values['ssl']) {
1278 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1282 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1283 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1285 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1286 serviceSpec['api_port'] = values['api_port'];
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();
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();
1302 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
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'];
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']);
1319 serviceSpec['ssl_ciphers'] = values['ssl_ciphers']?.trim().split(':');
1322 serviceSpec['port'] = values['grafana_port'];
1323 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
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']
1334 .map((domain: string) => {
1335 return domain.trim();
1337 if (values['ssl']) {
1338 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1339 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1344 this.taskWrapperService
1345 .wrapTaskAroundCall({
1346 task: new FinishedTask(taskUrl, {
1347 service_name: serviceName
1350 ? this.cephServiceService.update(serviceSpec)
1351 : this.cephServiceService.create(serviceSpec)
1355 self.serviceForm.setErrors({ cdSubmitButton: true });
1358 this.pageURL === 'services'
1359 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1360 : this.activeModal.close();
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();
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();
1377 if (privacyProtocol === null) {
1378 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1382 createMultisiteSetup() {
1383 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1386 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1387 this.setRgwFields();