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 { CephServiceSpec } from '~/app/shared/models/service.interface';
38 import { ModalService } from '~/app/shared/services/modal.service';
39 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
40 import { TimerService } from '~/app/shared/services/timer.service';
43 selector: 'cd-service-form',
44 templateUrl: './service-form.component.html',
45 styleUrls: ['./service-form.component.scss']
47 export class ServiceFormComponent extends CdForm implements OnInit {
48 public sub = new Subscription();
50 readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
51 readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
52 readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
53 readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
54 readonly SMB_CONFIG_URI_PATTERN = /^(http:|https:|rados:|rados:mon-config-key:)/;
55 readonly OAUTH2_ISSUER_URL_PATTERN = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)(:[0-9]{1,5})?(\/.*)?$/;
56 readonly SSL_CIPHERS_PATTERN = /^[a-zA-Z0-9\-:]+$/;
57 readonly DEFAULT_SSL_PROTOCOL_ITEM = [{ content: 'TLSv1.3', selected: true }];
58 @ViewChild(NgbTypeahead, { static: false })
59 typeahead: NgbTypeahead;
61 @Input() hiddenServices: string[] = [];
63 @Input() editing = false;
65 @Input() serviceName: string;
67 @Input() serviceType: string;
69 serviceForm: CdFormGroup;
72 serviceTypes: string[] = [];
73 serviceIds: string[] = [];
76 labelClick = new Subject<string>();
77 labelFocus = new Subject<string>();
79 rbdPools: Array<Pool>;
80 services: Array<CephServiceSpec> = [];
82 serviceList: CephServiceSpec[];
83 multisiteInfo: object[] = [];
85 defaultZonegroupId = '';
87 realmList: RgwRealm[] = [];
88 zonegroupList: RgwZonegroup[] = [];
89 zoneList: RgwZone[] = [];
90 bsModalRef: NgbModalRef;
91 defaultZonegroup: RgwZonegroup;
92 showRealmCreationForm = false;
93 defaultsInfo: { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string };
95 zonegroupNames: string[];
97 smbFeaturesList = ['domain'];
100 sslProtocolsItems: Array<ListItem> = Object.values(SSL_PROTOCOLS).map((protocol) => ({
104 sslCiphersItems: Array<ListItem> = Object.values(SSL_CIPHERS).map((cipher) => ({
108 showMgmtGatewayMessage: boolean = false;
111 public actionLabels: ActionLabelsI18n,
112 private cephServiceService: CephServiceService,
113 private formBuilder: CdFormBuilder,
114 private hostService: HostService,
115 private poolService: PoolService,
116 private rbdService: RbdService,
117 private router: Router,
118 private taskWrapperService: TaskWrapperService,
119 public timerService: TimerService,
120 public timerServiceVariable: TimerServiceInterval,
121 public rgwRealmService: RgwRealmService,
122 public rgwZonegroupService: RgwZonegroupService,
123 public rgwZoneService: RgwZoneService,
124 public rgwMultisiteService: RgwMultisiteService,
125 private route: ActivatedRoute,
126 public activeModal: NgbActiveModal,
127 public modalService: ModalService
130 this.resource = $localize`service`;
133 messages: new SelectMessages({
134 empty: $localize`There are no hosts.`,
135 filter: $localize`Filter hosts`
142 this.serviceForm = this.formBuilder.group({
144 service_type: [null, [Validators.required]],
148 CdValidators.composeIf(
154 CdValidators.custom('mdsPattern', (value: string) => {
155 if (_.isEmpty(value)) {
158 return !this.MDS_SVC_ID_PATTERN.test(value);
162 CdValidators.requiredIf({
165 CdValidators.requiredIf({
166 service_type: 'iscsi'
168 CdValidators.requiredIf({
169 service_type: 'nvmeof'
171 CdValidators.requiredIf({
172 service_type: 'ingress'
174 CdValidators.requiredIf({
177 CdValidators.composeIf(
181 [Validators.required]
183 CdValidators.custom('uniqueName', (service_id: string) => {
184 return this.serviceIds && this.serviceIds.includes(service_id);
188 placement: ['hosts'],
192 CdValidators.requiredIf({
199 count: [null, [CdValidators.number(false)]],
206 CdValidators.requiredIf({
207 service_type: 'iscsi'
209 CdValidators.requiredIf({
210 service_type: 'nvmeof'
216 CdValidators.requiredIf({
217 service_type: 'nvmeof'
220 enable_mtls: [false],
224 CdValidators.composeIf(
226 service_type: 'nvmeof',
229 [Validators.required]
236 CdValidators.composeIf(
238 service_type: 'nvmeof',
241 [Validators.required]
248 CdValidators.composeIf(
250 service_type: 'nvmeof',
253 [Validators.required]
260 CdValidators.composeIf(
262 service_type: 'nvmeof',
265 [Validators.required]
272 CdValidators.composeIf(
274 service_type: 'nvmeof',
277 [Validators.required]
282 rgw_frontend_port: [null, [CdValidators.number(false)]],
284 zonegroup_name: [null],
287 trusted_ip_list: [null],
288 api_port: [null, [CdValidators.number(false)]],
292 CdValidators.requiredIf({
293 service_type: 'iscsi',
301 CdValidators.requiredIf({
302 service_type: 'iscsi',
311 CdValidators.requiredIf({
316 features: new CdFormGroup(
317 this.smbFeaturesList.reduce((acc: object, e) => {
318 acc[e] = new UntypedFormControl(false);
325 CdValidators.composeIf(
331 CdValidators.custom('configUriPattern', (value: string) => {
332 if (_.isEmpty(value)) {
335 return !this.SMB_CONFIG_URI_PATTERN.test(value);
342 join_sources: [null],
343 user_sources: [null],
344 include_ceph_users: [null],
349 CdValidators.requiredIf({
350 service_type: 'ingress'
357 CdValidators.requiredIf({
358 service_type: 'ingress'
365 CdValidators.number(false),
366 CdValidators.requiredIf({
367 service_type: 'ingress'
374 CdValidators.number(false),
375 CdValidators.requiredIf({
376 service_type: 'ingress'
380 virtual_interface_networks: [null],
381 ssl_protocols: [this.DEFAULT_SSL_PROTOCOL_ITEM],
385 CdValidators.custom('invalidPattern', (ciphers: string) => {
386 if (_.isEmpty(ciphers)) {
389 return !this.SSL_CIPHERS_PATTERN.test(ciphers);
393 // RGW, Ingress & iSCSI
398 CdValidators.composeIf(
404 [Validators.required, CdValidators.pemCert()]
406 CdValidators.composeIf(
408 service_type: 'iscsi',
412 [Validators.required, CdValidators.sslCert()]
414 CdValidators.composeIf(
416 service_type: 'ingress',
420 [Validators.required, CdValidators.pemCert()]
422 CdValidators.composeIf(
424 service_type: 'oauth2-proxy',
428 [Validators.required, CdValidators.sslCert()]
430 CdValidators.composeIf(
432 service_type: 'mgmt-gateway',
436 [CdValidators.sslCert()]
443 CdValidators.composeIf(
445 service_type: 'iscsi',
449 [Validators.required, CdValidators.sslPrivKey()]
451 CdValidators.composeIf(
453 service_type: 'oauth2-proxy',
457 [Validators.required, CdValidators.sslPrivKey()]
459 CdValidators.composeIf(
461 service_type: 'mgmt-gateway',
465 [CdValidators.sslPrivKey()]
471 port: [443, [CdValidators.number(false)]],
476 CdValidators.requiredIf({
477 service_type: 'snmp-gateway'
485 CdValidators.requiredIf({
486 service_type: 'snmp-gateway'
488 CdValidators.custom('snmpDestinationPattern', (value: string) => {
489 if (_.isEmpty(value)) {
492 return !this.SNMP_DESTINATION_PATTERN.test(value);
500 CdValidators.requiredIf({
501 service_type: 'snmp-gateway'
503 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
504 if (_.isEmpty(value)) {
507 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
514 CdValidators.requiredIf({
515 service_type: 'snmp-gateway'
519 privacy_protocol: [null],
523 CdValidators.requiredIf({
528 snmp_v3_auth_username: [
531 CdValidators.requiredIf({
532 service_type: 'snmp-gateway'
536 snmp_v3_auth_password: [
539 CdValidators.requiredIf({
540 service_type: 'snmp-gateway'
544 snmp_v3_priv_password: [
547 CdValidators.requiredIf({
548 privacy_protocol: { op: '!empty' }
552 grafana_port: [null, [CdValidators.number(false)]],
553 grafana_admin_password: [null],
555 provider_display_name: [
558 CdValidators.requiredIf({
559 service_type: 'oauth2-proxy'
566 CdValidators.requiredIf({
567 service_type: 'oauth2-proxy'
574 CdValidators.requiredIf({
575 service_type: 'oauth2-proxy'
582 CdValidators.requiredIf({
583 service_type: 'oauth2-proxy'
585 CdValidators.custom('validUrl', (url: string) => {
586 if (_.isEmpty(url)) {
589 return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
593 https_address: [null, [CdValidators.oauthAddressTest()]],
594 redirect_url: [null],
595 allowlist_domains: [null]
600 if (this.router.url.includes('services/(modal:create')) {
601 this.pageURL = 'services';
602 this.route.params.subscribe((params: { type: string }) => {
604 this.serviceType = params.type;
605 this.serviceForm.get('service_type').setValue(this.serviceType);
608 } else if (this.router.url.includes('services/(modal:edit')) {
610 this.pageURL = 'services';
611 this.route.params.subscribe((params: { type: string; name: string }) => {
612 this.serviceName = params.name;
613 this.serviceType = params.type;
619 this.action = this.actionLabels.CREATE;
622 this.cephServiceService
623 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
624 .observable.subscribe((services: CephServiceSpec[]) => {
625 this.serviceList = services;
626 this.services = services.filter((service: any) =>
627 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
631 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
632 // Remove service types:
633 // osd - This is deployed a different way.
634 // container - This should only be used in the CLI.
635 this.hiddenServices.push('osd', 'container');
637 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
639 this.hostService.getAllHosts().subscribe((resp: object[]) => {
640 const options: SelectOption[] = [];
641 _.forEach(resp, (host: object) => {
642 if (_.get(host, 'sources.orchestrator', false)) {
643 const option = new SelectOption(false, _.get(host, 'hostname'), '');
644 options.push(option);
647 this.hosts.options = [...options];
649 this.hostService.getLabels().subscribe((resp: string[]) => {
652 this.poolService.getList().subscribe((resp: Pool[]) => {
654 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
655 if (!this.editing && this.serviceType) {
656 this.onServiceTypeChange(this.serviceType);
661 this.action = this.actionLabels.EDIT;
662 this.disableForEditing(this.serviceType);
663 this.cephServiceService
664 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
665 .observable.subscribe((response: CephServiceSpec[]) => {
666 const formKeys = ['service_type', 'service_id', 'unmanaged'];
667 formKeys.forEach((keys) => {
668 this.serviceForm.get(keys).setValue(response[0][keys]);
670 if (!response[0]['unmanaged']) {
671 const placementKey = Object.keys(response[0]['placement'])[0];
672 let placementValue: string;
673 ['hosts', 'label'].indexOf(placementKey) >= 0
674 ? (placementValue = placementKey)
675 : (placementValue = 'hosts');
676 this.serviceForm.get('placement').setValue(placementValue);
677 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
678 if (response[0]?.placement[placementValue]) {
679 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
682 switch (this.serviceType) {
684 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
685 specKeys.forEach((key) => {
686 this.serviceForm.get(key).setValue(response[0].spec[key]);
688 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
689 if (response[0].spec?.api_secure) {
690 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
691 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
695 this.serviceForm.get('pool').setValue(response[0].spec.pool);
696 this.serviceForm.get('group').setValue(response[0].spec.group);
697 this.serviceForm.get('enable_mtls').setValue(response[0].spec?.enable_auth);
698 this.serviceForm.get('root_ca_cert').setValue(response[0].spec?.root_ca_cert);
699 this.serviceForm.get('client_cert').setValue(response[0].spec?.client_cert);
700 this.serviceForm.get('client_key').setValue(response[0].spec?.client_key);
701 this.serviceForm.get('server_cert').setValue(response[0].spec?.server_cert);
702 this.serviceForm.get('server_key').setValue(response[0].spec?.server_key);
706 .get('rgw_frontend_port')
707 .setValue(response[0].spec?.rgw_frontend_port);
709 response[0].spec?.rgw_realm,
710 response[0].spec?.rgw_zonegroup,
711 response[0].spec?.rgw_zone
713 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
714 if (response[0].spec?.ssl) {
717 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
721 const ingressSpecKeys = [
726 'virtual_interface_networks',
729 ingressSpecKeys.forEach((key) => {
730 this.serviceForm.get(key).setValue(response[0].spec[key]);
732 if (response[0].spec?.ssl) {
733 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
734 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
738 let hrefSplitted = window.location.href.split(':');
739 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
740 this.port = response[0].spec?.port;
742 if (response[0].spec?.ssl_protocols) {
743 let selectedValues: Array<ListItem> = [];
744 for (const value of response[0].spec.ssl_protocols) {
745 selectedValues.push({ content: value, selected: true });
747 this.serviceForm.get('ssl_protocols').setValue(selectedValues);
749 if (response[0].spec?.ssl_ciphers) {
752 .setValue(response[0].spec?.ssl_ciphers.join(':'));
754 if (response[0].spec?.ssl_cert) {
755 this.serviceForm.get('ssl_cert').setValue(response[0].spec.ssl_cert);
757 if (response[0].spec?.ssl_key) {
758 this.serviceForm.get('ssl_key').setValue(response[0].spec.ssl_key);
760 if (response[0].spec?.enable_auth) {
761 this.serviceForm.get('enable_auth').setValue(response[0].spec.enable_auth);
763 if (response[0].spec?.port) {
764 this.serviceForm.get('port').setValue(response[0].spec.port);
768 const smbSpecKeys = [
777 smbSpecKeys.forEach((key) => {
778 if (key === 'features') {
779 if (response[0].spec?.features) {
780 response[0].spec.features.forEach((feature) => {
781 this.serviceForm.get(`features.${feature}`).setValue(true);
785 this.serviceForm.get(key).setValue(response[0].spec[key]);
790 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
791 snmpCommonSpecKeys.forEach((key) => {
792 this.serviceForm.get(key).setValue(response[0].spec[key]);
794 if (this.serviceForm.getValue('snmp_version') === 'V3') {
795 const snmpV3SpecKeys = [
799 'snmp_v3_auth_username',
800 'snmp_v3_auth_password',
801 'snmp_v3_priv_password'
803 snmpV3SpecKeys.forEach((key) => {
806 key === 'snmp_v3_auth_username' ||
807 key === 'snmp_v3_auth_password' ||
808 key === 'snmp_v3_priv_password'
810 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
812 this.serviceForm.get(key).setValue(response[0].spec[key]);
818 .get('snmp_community')
819 .setValue(response[0].spec['credentials']['snmp_community']);
823 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
825 .get('grafana_admin_password')
826 .setValue(response[0].spec.initial_admin_password);
829 const oauth2SpecKeys = [
831 'provider_display_name',
838 oauth2SpecKeys.forEach((key) => {
839 this.serviceForm.get(key).setValue(response[0].spec[key]);
841 if (response[0].spec?.ssl) {
842 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
843 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
848 this.detectChanges();
851 detectChanges(): void {
852 const service_type = this.serviceForm.get('service_type');
854 service_type.valueChanges.subscribe((value) => {
855 if (value === 'mgmt-gateway') {
856 const port = this.serviceForm.get('port');
858 port.valueChanges.subscribe((_) => {
859 this.showMgmtGatewayMessage = true;
862 const ssl_protocols = this.serviceForm.get('ssl_protocols');
864 ssl_protocols.valueChanges.subscribe((_) => {
865 this.showMgmtGatewayMessage = true;
868 const ssl_ciphers = this.serviceForm.get('ssl_ciphers');
870 ssl_ciphers.valueChanges.subscribe((_) => {
871 this.showMgmtGatewayMessage = true;
879 getDefaultsEntitiesForRgw(
880 defaultRealmId: string,
881 defaultZonegroupId: string,
882 defaultZoneId: string
883 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
884 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
885 const defaultZonegroup = this.zonegroupList.find(
886 (x: { id: string }) => x.id === defaultZonegroupId
888 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
889 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
890 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
891 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
892 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
893 const defaultZonegroup = new RgwZonegroup();
894 defaultZonegroup.name = 'default';
895 this.zonegroupList.push(defaultZonegroup);
897 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
898 const defaultZone = new RgwZone();
899 defaultZone.name = 'default';
900 this.zoneList.push(defaultZone);
903 defaultRealmName: defaultRealmName,
904 defaultZonegroupName: defaultZonegroupName,
905 defaultZoneName: defaultZoneName
909 getDefaultPlacementCount(serviceType: string) {
911 * `defaults` from src/pybind/mgr/cephadm/module.py
913 switch (serviceType) {
915 this.serviceForm.get('count').setValue(5);
922 this.serviceForm.get('count').setValue(2);
925 case 'cephfs-mirror':
933 case 'elastic-serach':
934 case 'jaeger-collector':
939 this.serviceForm.get('count').setValue(1);
942 this.serviceForm.get('count').setValue(null);
946 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
947 const observables = [
948 this.rgwRealmService.getAllRealmsInfo(),
949 this.rgwZonegroupService.getAllZonegroupsInfo(),
950 this.rgwZoneService.getAllZonesInfo()
952 this.sub = forkJoin(observables).subscribe(
953 (multisiteInfo: [object, object, object]) => {
954 this.multisiteInfo = multisiteInfo;
956 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
957 ? this.multisiteInfo[0]['realms']
960 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
961 ? this.multisiteInfo[1]['zonegroups']
964 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
965 ? this.multisiteInfo[2]['zones']
967 this.realmNames = this.realmList.map((realm) => {
968 return realm['name'];
970 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
971 return zonegroup['name'];
973 this.zoneNames = this.zoneList.map((zone) => {
976 this.defaultRealmId = multisiteInfo[0]['default_realm'];
977 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
978 this.defaultZoneId = multisiteInfo[2]['default_zone'];
979 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
981 this.defaultZonegroupId,
985 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
987 .get('zonegroup_name')
988 .setValue(this.defaultsInfo['defaultZonegroupName']);
989 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
991 if (realm_name && !this.realmNames.includes(realm_name)) {
992 const realm = new RgwRealm();
993 realm.name = realm_name;
994 this.realmList.push(realm);
996 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
997 const zonegroup = new RgwZonegroup();
998 zonegroup.name = zonegroup_name;
999 this.zonegroupList.push(zonegroup);
1001 if (zone_name && !this.zoneNames.includes(zone_name)) {
1002 const zone = new RgwZone();
1003 zone.name = zone_name;
1004 this.zoneList.push(zone);
1006 if (zonegroup_name === undefined && zone_name === undefined) {
1007 zonegroup_name = 'default';
1008 zone_name = 'default';
1010 this.serviceForm.get('realm_name').setValue(realm_name);
1011 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
1012 this.serviceForm.get('zone_name').setValue(zone_name);
1014 if (this.realmList.length === 0) {
1015 this.showRealmCreationForm = true;
1017 this.showRealmCreationForm = false;
1021 const defaultZone = new RgwZone();
1022 defaultZone.name = 'default';
1023 const defaultZonegroup = new RgwZonegroup();
1024 defaultZonegroup.name = 'default';
1025 this.zoneList.push(defaultZone);
1026 this.zonegroupList.push(defaultZonegroup);
1031 setNvmeServiceId() {
1032 const pool = this.serviceForm.get('pool').value;
1033 const group = this.serviceForm.get('group').value;
1034 if (pool && group) {
1035 this.serviceForm.get('service_id').setValue(`${pool}.${group}`);
1037 this.serviceForm.get('service_id').setValue(pool);
1039 this.serviceForm.get('service_id').setValue(group);
1041 this.serviceForm.get('service_id').setValue(null);
1045 setNvmeDefaultPool() {
1047 this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')?.pool_name ||
1048 this.rbdPools?.[0].pool_name;
1049 this.serviceForm.get('pool').setValue(defaultPool);
1052 requiresServiceId(serviceType: string) {
1053 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
1056 setServiceId(serviceId: string): void {
1057 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
1058 if (requiresServiceId && serviceId === 'nvmeof') {
1059 this.setNvmeDefaultPool();
1060 this.setNvmeServiceId();
1061 } else if (requiresServiceId) {
1062 this.serviceForm.get('service_id').setValue(null);
1064 this.serviceForm.get('service_id').setValue(serviceId);
1068 onServiceTypeChange(selectedServiceType: string) {
1069 this.setServiceId(selectedServiceType);
1071 this.serviceIds = this.serviceList
1072 ?.filter((service) => service['service_type'] === selectedServiceType)
1073 .map((service) => service['service_id']);
1075 this.getDefaultPlacementCount(selectedServiceType);
1077 if (selectedServiceType === 'rgw') {
1078 this.setRgwFields();
1080 if (selectedServiceType === 'mgmt-gateway') {
1081 let hrefSplitted = window.location.href.split(':');
1082 this.currentURL = hrefSplitted[0] + hrefSplitted[1];
1083 // mgmt-gateway lacks HA for now
1084 this.serviceForm.get('count').disable();
1086 this.serviceForm.get('count').enable();
1090 onPlacementChange(selected: string) {
1091 if (selected === 'label') {
1092 this.serviceForm.get('count').setValue(null);
1096 disableForEditing(serviceType: string) {
1097 const disableForEditKeys = ['service_type', 'service_id'];
1098 disableForEditKeys.forEach((key) => {
1099 this.serviceForm.get(key).disable();
1101 switch (serviceType) {
1103 this.serviceForm.get('backend_service').disable();
1106 this.serviceForm.get('pool').disable();
1107 this.serviceForm.get('group').disable();
1112 searchLabels = (text$: Observable<string>) => {
1114 text$.pipe(debounceTime(200), distinctUntilChanged()),
1116 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
1120 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
1126 fileUpload(files: FileList, controlName: string) {
1127 const file: File = files[0];
1128 const reader = new FileReader();
1129 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
1130 const control: AbstractControl = this.serviceForm.get(controlName);
1131 control.setValue(event.target.result);
1132 control.markAsDirty();
1133 control.markAsTouched();
1134 control.updateValueAndValidity();
1136 reader.readAsText(file, 'utf8');
1140 const control: AbstractControl = this.serviceForm.get('service_id');
1141 const backendService = this.serviceForm.getValue('backend_service');
1142 // Set Id as read-only
1143 control.reset({ value: backendService, disabled: true });
1148 const values: object = this.serviceForm.getRawValue();
1149 const serviceType: string = values['service_type'];
1150 let taskUrl = `service/${URLVerbs.CREATE}`;
1152 taskUrl = `service/${URLVerbs.EDIT}`;
1154 const serviceSpec: object = {
1155 service_type: serviceType,
1157 unmanaged: values['unmanaged']
1159 if (serviceType === 'rgw') {
1160 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
1161 serviceSpec['rgw_zonegroup'] =
1162 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
1163 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
1166 const serviceId: string = values['service_id'];
1167 let serviceName: string = serviceType;
1168 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
1169 serviceName = `${serviceType}.${serviceId}`;
1170 serviceSpec['service_id'] = serviceId;
1173 // These services has some fields to be
1174 // filled out even if unmanaged is true
1175 switch (serviceType) {
1177 serviceSpec['backend_service'] = values['backend_service'];
1178 serviceSpec['service_id'] = values['backend_service'];
1179 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
1180 serviceSpec['frontend_port'] = values['frontend_port'];
1182 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1183 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1185 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1186 serviceSpec['monitor_port'] = values['monitor_port'];
1191 serviceSpec['pool'] = values['pool'];
1192 serviceSpec['group'] = values['group'];
1193 serviceSpec['enable_auth'] = values['enable_mtls'];
1194 if (values['enable_mtls']) {
1195 serviceSpec['root_ca_cert'] = values['root_ca_cert'];
1196 serviceSpec['client_cert'] = values['client_cert'];
1197 serviceSpec['client_key'] = values['client_key'];
1198 serviceSpec['server_cert'] = values['server_cert'];
1199 serviceSpec['server_key'] = values['server_key'];
1203 serviceSpec['pool'] = values['pool'];
1207 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
1208 serviceSpec['config_uri'] = values['config_uri']?.trim();
1209 for (const feature in values['features']) {
1210 if (values['features'][feature]) {
1211 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
1214 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
1215 serviceSpec['join_sources'] = values['join_sources']?.trim();
1216 serviceSpec['user_sources'] = values['user_sources']?.trim();
1217 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
1220 case 'snmp-gateway':
1221 serviceSpec['credentials'] = {};
1222 serviceSpec['snmp_version'] = values['snmp_version'];
1223 serviceSpec['snmp_destination'] = values['snmp_destination'];
1224 if (values['snmp_version'] === 'V3') {
1225 serviceSpec['engine_id'] = values['engine_id'];
1226 serviceSpec['auth_protocol'] = values['auth_protocol'];
1227 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
1228 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
1229 if (values['privacy_protocol'] !== null) {
1230 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
1231 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
1234 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1239 if (!values['unmanaged']) {
1240 switch (values['placement']) {
1242 if (values['hosts'].length > 0) {
1243 serviceSpec['placement']['hosts'] = values['hosts'];
1247 serviceSpec['placement']['label'] = values['label'];
1250 if (_.isNumber(values['count']) && values['count'] > 0) {
1251 serviceSpec['placement']['count'] = values['count'];
1253 switch (serviceType) {
1255 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1256 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1258 serviceSpec['ssl'] = values['ssl'];
1259 if (values['ssl']) {
1260 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1264 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1265 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1267 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1268 serviceSpec['api_port'] = values['api_port'];
1270 serviceSpec['api_user'] = values['api_user'];
1271 serviceSpec['api_password'] = values['api_password'];
1272 serviceSpec['api_secure'] = values['ssl'];
1273 if (values['ssl']) {
1274 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1275 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1279 serviceSpec['ssl'] = values['ssl'];
1280 if (values['ssl']) {
1281 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1282 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1284 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1286 case 'mgmt-gateway':
1287 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1288 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1289 serviceSpec['enable_auth'] = values['enable_auth'];
1290 serviceSpec['port'] = values['port'];
1291 if (serviceSpec['port'] === (443 || 80)) {
1292 // omit port default values due to issues with redirect_url on the backend
1293 delete serviceSpec['port'];
1295 serviceSpec['ssl_protocols'] = [];
1296 if (values['ssl_protocols'] != this.DEFAULT_SSL_PROTOCOL_ITEM) {
1297 for (const key of Object.keys(values['ssl_protocols'])) {
1298 serviceSpec['ssl_protocols'].push(values['ssl_protocols'][key]['content']);
1301 serviceSpec['ssl_ciphers'] = values['ssl_ciphers']?.trim().split(':');
1304 serviceSpec['port'] = values['grafana_port'];
1305 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1307 case 'oauth2-proxy':
1308 serviceSpec['provider_display_name'] = values['provider_display_name']?.trim();
1309 serviceSpec['client_id'] = values['client_id']?.trim();
1310 serviceSpec['client_secret'] = values['client_secret']?.trim();
1311 serviceSpec['oidc_issuer_url'] = values['oidc_issuer_url']?.trim();
1312 serviceSpec['https_address'] = values['https_address']?.trim();
1313 serviceSpec['redirect_url'] = values['redirect_url']?.trim();
1314 serviceSpec['allowlist_domains'] = values['allowlist_domains']
1316 .map((domain: string) => {
1317 return domain.trim();
1319 if (values['ssl']) {
1320 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1321 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1326 this.taskWrapperService
1327 .wrapTaskAroundCall({
1328 task: new FinishedTask(taskUrl, {
1329 service_name: serviceName
1332 ? this.cephServiceService.update(serviceSpec)
1333 : this.cephServiceService.create(serviceSpec)
1337 self.serviceForm.setErrors({ cdSubmitButton: true });
1340 this.pageURL === 'services'
1341 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1342 : this.activeModal.close();
1347 clearValidations() {
1348 const snmpVersion = this.serviceForm.getValue('snmp_version');
1349 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1350 if (snmpVersion === 'V3') {
1351 this.serviceForm.get('snmp_community').clearValidators();
1353 this.serviceForm.get('engine_id').clearValidators();
1354 this.serviceForm.get('auth_protocol').clearValidators();
1355 this.serviceForm.get('privacy_protocol').clearValidators();
1356 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1357 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1359 if (privacyProtocol === null) {
1360 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1364 createMultisiteSetup() {
1365 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1368 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1369 this.setRgwFields();