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 _ from 'lodash';
8 import { forkJoin, merge, Observable, Subject, Subscription } from 'rxjs';
9 import { debounceTime, distinctUntilChanged, filter, map } from 'rxjs/operators';
10 import { Pool } from '~/app/ceph/pool/pool';
11 import { CreateRgwServiceEntitiesComponent } from '~/app/ceph/rgw/create-rgw-service-entities/create-rgw-service-entities.component';
12 import { RgwRealm, RgwZonegroup, RgwZone } from '~/app/ceph/rgw/models/rgw-multisite';
14 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
15 import { HostService } from '~/app/shared/api/host.service';
16 import { PoolService } from '~/app/shared/api/pool.service';
17 import { RbdService } from '~/app/shared/api/rbd.service';
18 import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
19 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
20 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
21 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
22 import { SelectMessages } from '~/app/shared/components/select/select-messages.model';
23 import { SelectOption } from '~/app/shared/components/select/select-option.model';
28 } from '~/app/shared/constants/app.constants';
29 import { CdForm } from '~/app/shared/forms/cd-form';
30 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
31 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
32 import { CdValidators } from '~/app/shared/forms/cd-validators';
33 import { FinishedTask } from '~/app/shared/models/finished-task';
34 import { CephServiceSpec } from '~/app/shared/models/service.interface';
35 import { ModalService } from '~/app/shared/services/modal.service';
36 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
37 import { TimerService } from '~/app/shared/services/timer.service';
40 selector: 'cd-service-form',
41 templateUrl: './service-form.component.html',
42 styleUrls: ['./service-form.component.scss']
44 export class ServiceFormComponent extends CdForm implements OnInit {
45 public sub = new Subscription();
47 readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
48 readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
49 readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
50 readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
51 readonly SMB_CONFIG_URI_PATTERN = /^(http:|https:|rados:|rados:mon-config-key:)/;
52 readonly OAUTH2_ISSUER_URL_PATTERN = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)(:[0-9]{1,5})?(\/.*)?$/;
53 @ViewChild(NgbTypeahead, { static: false })
54 typeahead: NgbTypeahead;
56 @Input() hiddenServices: string[] = [];
58 @Input() editing = false;
60 @Input() serviceName: string;
62 @Input() serviceType: string;
64 serviceForm: CdFormGroup;
67 serviceTypes: string[] = [];
68 serviceIds: string[] = [];
71 labelClick = new Subject<string>();
72 labelFocus = new Subject<string>();
74 rbdPools: Array<Pool>;
75 services: Array<CephServiceSpec> = [];
77 serviceList: CephServiceSpec[];
78 multisiteInfo: object[] = [];
80 defaultZonegroupId = '';
82 realmList: RgwRealm[] = [];
83 zonegroupList: RgwZonegroup[] = [];
84 zoneList: RgwZone[] = [];
85 bsModalRef: NgbModalRef;
86 defaultZonegroup: RgwZonegroup;
87 showRealmCreationForm = false;
88 defaultsInfo: { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string };
90 zonegroupNames: string[];
92 smbFeaturesList = ['domain'];
95 public actionLabels: ActionLabelsI18n,
96 private cephServiceService: CephServiceService,
97 private formBuilder: CdFormBuilder,
98 private hostService: HostService,
99 private poolService: PoolService,
100 private rbdService: RbdService,
101 private router: Router,
102 private taskWrapperService: TaskWrapperService,
103 public timerService: TimerService,
104 public timerServiceVariable: TimerServiceInterval,
105 public rgwRealmService: RgwRealmService,
106 public rgwZonegroupService: RgwZonegroupService,
107 public rgwZoneService: RgwZoneService,
108 public rgwMultisiteService: RgwMultisiteService,
109 private route: ActivatedRoute,
110 public activeModal: NgbActiveModal,
111 public modalService: ModalService
114 this.resource = $localize`service`;
117 messages: new SelectMessages({
118 empty: $localize`There are no hosts.`,
119 filter: $localize`Filter hosts`
126 this.serviceForm = this.formBuilder.group({
128 service_type: [null, [Validators.required]],
132 CdValidators.composeIf(
138 CdValidators.custom('mdsPattern', (value: string) => {
139 if (_.isEmpty(value)) {
142 return !this.MDS_SVC_ID_PATTERN.test(value);
146 CdValidators.requiredIf({
149 CdValidators.requiredIf({
150 service_type: 'iscsi'
152 CdValidators.requiredIf({
153 service_type: 'nvmeof'
155 CdValidators.requiredIf({
156 service_type: 'ingress'
158 CdValidators.requiredIf({
161 CdValidators.composeIf(
165 [Validators.required]
167 CdValidators.custom('uniqueName', (service_id: string) => {
168 return this.serviceIds && this.serviceIds.includes(service_id);
172 placement: ['hosts'],
176 CdValidators.requiredIf({
183 count: [null, [CdValidators.number(false)]],
190 CdValidators.requiredIf({
191 service_type: 'iscsi'
193 CdValidators.requiredIf({
194 service_type: 'nvmeof'
200 CdValidators.requiredIf({
201 service_type: 'nvmeof'
205 rgw_frontend_port: [null, [CdValidators.number(false)]],
207 zonegroup_name: [null],
210 trusted_ip_list: [null],
211 api_port: [null, [CdValidators.number(false)]],
215 CdValidators.requiredIf({
216 service_type: 'iscsi',
224 CdValidators.requiredIf({
225 service_type: 'iscsi',
234 CdValidators.requiredIf({
239 features: new CdFormGroup(
240 this.smbFeaturesList.reduce((acc: object, e) => {
241 acc[e] = new UntypedFormControl(false);
248 CdValidators.composeIf(
254 CdValidators.custom('configUriPattern', (value: string) => {
255 if (_.isEmpty(value)) {
258 return !this.SMB_CONFIG_URI_PATTERN.test(value);
265 join_sources: [null],
266 user_sources: [null],
267 include_ceph_users: [null],
272 CdValidators.requiredIf({
273 service_type: 'ingress'
280 CdValidators.requiredIf({
281 service_type: 'ingress'
288 CdValidators.number(false),
289 CdValidators.requiredIf({
290 service_type: 'ingress'
297 CdValidators.number(false),
298 CdValidators.requiredIf({
299 service_type: 'ingress'
303 virtual_interface_networks: [null],
304 // RGW, Ingress & iSCSI
309 CdValidators.composeIf(
315 [Validators.required, CdValidators.pemCert()]
317 CdValidators.composeIf(
319 service_type: 'iscsi',
323 [Validators.required, CdValidators.sslCert()]
325 CdValidators.composeIf(
327 service_type: 'ingress',
331 [Validators.required, CdValidators.pemCert()]
333 CdValidators.composeIf(
335 service_type: 'oauth2-proxy',
339 [Validators.required, CdValidators.sslCert()]
346 CdValidators.composeIf(
348 service_type: 'iscsi',
352 [Validators.required, CdValidators.sslPrivKey()]
354 CdValidators.composeIf(
356 service_type: 'oauth2-proxy',
360 [Validators.required, CdValidators.sslPrivKey()]
368 CdValidators.requiredIf({
369 service_type: 'snmp-gateway'
377 CdValidators.requiredIf({
378 service_type: 'snmp-gateway'
380 CdValidators.custom('snmpDestinationPattern', (value: string) => {
381 if (_.isEmpty(value)) {
384 return !this.SNMP_DESTINATION_PATTERN.test(value);
392 CdValidators.requiredIf({
393 service_type: 'snmp-gateway'
395 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
396 if (_.isEmpty(value)) {
399 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
406 CdValidators.requiredIf({
407 service_type: 'snmp-gateway'
411 privacy_protocol: [null],
415 CdValidators.requiredIf({
420 snmp_v3_auth_username: [
423 CdValidators.requiredIf({
424 service_type: 'snmp-gateway'
428 snmp_v3_auth_password: [
431 CdValidators.requiredIf({
432 service_type: 'snmp-gateway'
436 snmp_v3_priv_password: [
439 CdValidators.requiredIf({
440 privacy_protocol: { op: '!empty' }
444 grafana_port: [null, [CdValidators.number(false)]],
445 grafana_admin_password: [null],
447 provider_display_name: [
450 CdValidators.requiredIf({
451 service_type: 'oauth2-proxy'
458 CdValidators.requiredIf({
459 service_type: 'oauth2-proxy'
466 CdValidators.requiredIf({
467 service_type: 'oauth2-proxy'
474 CdValidators.requiredIf({
475 service_type: 'oauth2-proxy'
477 CdValidators.custom('validUrl', (url: string) => {
478 if (_.isEmpty(url)) {
481 return !this.OAUTH2_ISSUER_URL_PATTERN.test(url);
485 https_address: [null, [CdValidators.oauthAddressTest()]],
486 redirect_url: [null],
487 allowlist_domains: [null]
492 if (this.router.url.includes('services/(modal:create')) {
493 this.pageURL = 'services';
494 this.route.params.subscribe((params: { type: string }) => {
496 this.serviceType = params.type;
497 this.serviceForm.get('service_type').setValue(this.serviceType);
500 } else if (this.router.url.includes('services/(modal:edit')) {
502 this.pageURL = 'services';
503 this.route.params.subscribe((params: { type: string; name: string }) => {
504 this.serviceName = params.name;
505 this.serviceType = params.type;
511 this.action = this.actionLabels.CREATE;
514 this.cephServiceService
515 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
516 .observable.subscribe((services: CephServiceSpec[]) => {
517 this.serviceList = services;
518 this.services = services.filter((service: any) =>
519 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
523 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
524 // Remove service types:
525 // osd - This is deployed a different way.
526 // container - This should only be used in the CLI.
527 this.hiddenServices.push('osd', 'container');
529 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
531 this.hostService.getAllHosts().subscribe((resp: object[]) => {
532 const options: SelectOption[] = [];
533 _.forEach(resp, (host: object) => {
534 if (_.get(host, 'sources.orchestrator', false)) {
535 const option = new SelectOption(false, _.get(host, 'hostname'), '');
536 options.push(option);
539 this.hosts.options = [...options];
541 this.hostService.getLabels().subscribe((resp: string[]) => {
544 this.poolService.getList().subscribe((resp: Pool[]) => {
546 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
547 if (!this.editing && this.serviceType) {
548 this.onServiceTypeChange(this.serviceType);
553 this.action = this.actionLabels.EDIT;
554 this.disableForEditing(this.serviceType);
555 this.cephServiceService
556 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
557 .observable.subscribe((response: CephServiceSpec[]) => {
558 const formKeys = ['service_type', 'service_id', 'unmanaged'];
559 formKeys.forEach((keys) => {
560 this.serviceForm.get(keys).setValue(response[0][keys]);
562 if (!response[0]['unmanaged']) {
563 const placementKey = Object.keys(response[0]['placement'])[0];
564 let placementValue: string;
565 ['hosts', 'label'].indexOf(placementKey) >= 0
566 ? (placementValue = placementKey)
567 : (placementValue = 'hosts');
568 this.serviceForm.get('placement').setValue(placementValue);
569 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
570 if (response[0]?.placement[placementValue]) {
571 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
574 switch (this.serviceType) {
576 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
577 specKeys.forEach((key) => {
578 this.serviceForm.get(key).setValue(response[0].spec[key]);
580 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
581 if (response[0].spec?.api_secure) {
582 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
583 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
587 this.serviceForm.get('pool').setValue(response[0].spec.pool);
588 this.serviceForm.get('group').setValue(response[0].spec.group);
592 .get('rgw_frontend_port')
593 .setValue(response[0].spec?.rgw_frontend_port);
595 response[0].spec?.rgw_realm,
596 response[0].spec?.rgw_zonegroup,
597 response[0].spec?.rgw_zone
599 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
600 if (response[0].spec?.ssl) {
603 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
607 const ingressSpecKeys = [
612 'virtual_interface_networks',
615 ingressSpecKeys.forEach((key) => {
616 this.serviceForm.get(key).setValue(response[0].spec[key]);
618 if (response[0].spec?.ssl) {
619 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
620 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
624 const smbSpecKeys = [
633 smbSpecKeys.forEach((key) => {
634 if (key === 'features') {
635 if (response[0].spec?.features) {
636 response[0].spec.features.forEach((feature) => {
637 this.serviceForm.get(`features.${feature}`).setValue(true);
641 this.serviceForm.get(key).setValue(response[0].spec[key]);
646 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
647 snmpCommonSpecKeys.forEach((key) => {
648 this.serviceForm.get(key).setValue(response[0].spec[key]);
650 if (this.serviceForm.getValue('snmp_version') === 'V3') {
651 const snmpV3SpecKeys = [
655 'snmp_v3_auth_username',
656 'snmp_v3_auth_password',
657 'snmp_v3_priv_password'
659 snmpV3SpecKeys.forEach((key) => {
662 key === 'snmp_v3_auth_username' ||
663 key === 'snmp_v3_auth_password' ||
664 key === 'snmp_v3_priv_password'
666 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
668 this.serviceForm.get(key).setValue(response[0].spec[key]);
674 .get('snmp_community')
675 .setValue(response[0].spec['credentials']['snmp_community']);
679 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
681 .get('grafana_admin_password')
682 .setValue(response[0].spec.initial_admin_password);
685 const oauth2SpecKeys = [
687 'provider_display_name',
694 oauth2SpecKeys.forEach((key) => {
695 this.serviceForm.get(key).setValue(response[0].spec[key]);
697 if (response[0].spec?.ssl) {
698 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
699 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
706 getDefaultsEntitiesForRgw(
707 defaultRealmId: string,
708 defaultZonegroupId: string,
709 defaultZoneId: string
710 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
711 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
712 const defaultZonegroup = this.zonegroupList.find(
713 (x: { id: string }) => x.id === defaultZonegroupId
715 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
716 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
717 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
718 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
719 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
720 const defaultZonegroup = new RgwZonegroup();
721 defaultZonegroup.name = 'default';
722 this.zonegroupList.push(defaultZonegroup);
724 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
725 const defaultZone = new RgwZone();
726 defaultZone.name = 'default';
727 this.zoneList.push(defaultZone);
730 defaultRealmName: defaultRealmName,
731 defaultZonegroupName: defaultZonegroupName,
732 defaultZoneName: defaultZoneName
736 getDefaultPlacementCount(serviceType: string) {
738 * `defaults` from src/pybind/mgr/cephadm/module.py
740 switch (serviceType) {
742 this.serviceForm.get('count').setValue(5);
749 this.serviceForm.get('count').setValue(2);
753 case 'cephfs-mirror':
761 case 'elastic-serach':
762 case 'jaeger-collector':
766 this.serviceForm.get('count').setValue(1);
769 this.serviceForm.get('count').setValue(null);
773 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
774 const observables = [
775 this.rgwRealmService.getAllRealmsInfo(),
776 this.rgwZonegroupService.getAllZonegroupsInfo(),
777 this.rgwZoneService.getAllZonesInfo()
779 this.sub = forkJoin(observables).subscribe(
780 (multisiteInfo: [object, object, object]) => {
781 this.multisiteInfo = multisiteInfo;
783 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
784 ? this.multisiteInfo[0]['realms']
787 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
788 ? this.multisiteInfo[1]['zonegroups']
791 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
792 ? this.multisiteInfo[2]['zones']
794 this.realmNames = this.realmList.map((realm) => {
795 return realm['name'];
797 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
798 return zonegroup['name'];
800 this.zoneNames = this.zoneList.map((zone) => {
803 this.defaultRealmId = multisiteInfo[0]['default_realm'];
804 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
805 this.defaultZoneId = multisiteInfo[2]['default_zone'];
806 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
808 this.defaultZonegroupId,
812 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
814 .get('zonegroup_name')
815 .setValue(this.defaultsInfo['defaultZonegroupName']);
816 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
818 if (realm_name && !this.realmNames.includes(realm_name)) {
819 const realm = new RgwRealm();
820 realm.name = realm_name;
821 this.realmList.push(realm);
823 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
824 const zonegroup = new RgwZonegroup();
825 zonegroup.name = zonegroup_name;
826 this.zonegroupList.push(zonegroup);
828 if (zone_name && !this.zoneNames.includes(zone_name)) {
829 const zone = new RgwZone();
830 zone.name = zone_name;
831 this.zoneList.push(zone);
833 if (zonegroup_name === undefined && zone_name === undefined) {
834 zonegroup_name = 'default';
835 zone_name = 'default';
837 this.serviceForm.get('realm_name').setValue(realm_name);
838 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
839 this.serviceForm.get('zone_name').setValue(zone_name);
841 if (this.realmList.length === 0) {
842 this.showRealmCreationForm = true;
844 this.showRealmCreationForm = false;
848 const defaultZone = new RgwZone();
849 defaultZone.name = 'default';
850 const defaultZonegroup = new RgwZonegroup();
851 defaultZonegroup.name = 'default';
852 this.zoneList.push(defaultZone);
853 this.zonegroupList.push(defaultZonegroup);
858 setNvmeofServiceId(): void {
859 const defaultRbdPool: string = this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')
861 if (defaultRbdPool) {
862 this.serviceForm.get('pool').setValue(defaultRbdPool);
866 onNvmeofGroupChange(groupName: string) {
867 this.serviceForm.get('service_id').setValue(groupName);
870 requiresServiceId(serviceType: string) {
871 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
874 setServiceId(serviceId: string): void {
875 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
876 if (requiresServiceId && serviceId === 'nvmeof') {
877 this.setNvmeofServiceId();
878 } else if (requiresServiceId) {
879 this.serviceForm.get('service_id').setValue(null);
881 this.serviceForm.get('service_id').setValue(serviceId);
885 onServiceTypeChange(selectedServiceType: string) {
886 this.setServiceId(selectedServiceType);
888 this.serviceIds = this.serviceList
889 ?.filter((service) => service['service_type'] === selectedServiceType)
890 .map((service) => service['service_id']);
892 this.getDefaultPlacementCount(selectedServiceType);
894 if (selectedServiceType === 'rgw') {
899 onPlacementChange(selected: string) {
900 if (selected === 'label') {
901 this.serviceForm.get('count').setValue(null);
905 onBlockPoolChange() {
906 const selectedBlockPool = this.serviceForm.get('pool').value;
907 if (selectedBlockPool) {
908 this.serviceForm.get('service_id').setValue(selectedBlockPool);
910 this.serviceForm.get('service_id').setValue(null);
914 disableForEditing(serviceType: string) {
915 const disableForEditKeys = ['service_type', 'service_id'];
916 disableForEditKeys.forEach((key) => {
917 this.serviceForm.get(key).disable();
919 switch (serviceType) {
921 this.serviceForm.get('backend_service').disable();
924 this.serviceForm.get('pool').disable();
925 this.serviceForm.get('group').disable();
930 searchLabels = (text$: Observable<string>) => {
932 text$.pipe(debounceTime(200), distinctUntilChanged()),
934 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
938 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
944 fileUpload(files: FileList, controlName: string) {
945 const file: File = files[0];
946 const reader = new FileReader();
947 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
948 const control: AbstractControl = this.serviceForm.get(controlName);
949 control.setValue(event.target.result);
950 control.markAsDirty();
951 control.markAsTouched();
952 control.updateValueAndValidity();
954 reader.readAsText(file, 'utf8');
958 const control: AbstractControl = this.serviceForm.get('service_id');
959 const backendService = this.serviceForm.getValue('backend_service');
960 // Set Id as read-only
961 control.reset({ value: backendService, disabled: true });
966 const values: object = this.serviceForm.getRawValue();
967 const serviceType: string = values['service_type'];
968 let taskUrl = `service/${URLVerbs.CREATE}`;
970 taskUrl = `service/${URLVerbs.EDIT}`;
972 const serviceSpec: object = {
973 service_type: serviceType,
975 unmanaged: values['unmanaged']
977 if (serviceType === 'rgw') {
978 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
979 serviceSpec['rgw_zonegroup'] =
980 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
981 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
984 const serviceId: string = values['service_id'];
985 let serviceName: string = serviceType;
986 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
987 serviceName = `${serviceType}.${serviceId}`;
988 serviceSpec['service_id'] = serviceId;
991 // These services has some fields to be
992 // filled out even if unmanaged is true
993 switch (serviceType) {
995 serviceSpec['backend_service'] = values['backend_service'];
996 serviceSpec['service_id'] = values['backend_service'];
997 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
998 serviceSpec['frontend_port'] = values['frontend_port'];
1000 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
1001 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
1003 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
1004 serviceSpec['monitor_port'] = values['monitor_port'];
1009 serviceSpec['pool'] = values['pool'];
1010 serviceSpec['group'] = values['group'];
1013 serviceSpec['pool'] = values['pool'];
1017 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
1018 serviceSpec['config_uri'] = values['config_uri']?.trim();
1019 for (const feature in values['features']) {
1020 if (values['features'][feature]) {
1021 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
1024 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
1025 serviceSpec['join_sources'] = values['join_sources']?.trim();
1026 serviceSpec['user_sources'] = values['user_sources']?.trim();
1027 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
1030 case 'snmp-gateway':
1031 serviceSpec['credentials'] = {};
1032 serviceSpec['snmp_version'] = values['snmp_version'];
1033 serviceSpec['snmp_destination'] = values['snmp_destination'];
1034 if (values['snmp_version'] === 'V3') {
1035 serviceSpec['engine_id'] = values['engine_id'];
1036 serviceSpec['auth_protocol'] = values['auth_protocol'];
1037 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
1038 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
1039 if (values['privacy_protocol'] !== null) {
1040 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
1041 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
1044 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
1049 if (!values['unmanaged']) {
1050 switch (values['placement']) {
1052 if (values['hosts'].length > 0) {
1053 serviceSpec['placement']['hosts'] = values['hosts'];
1057 serviceSpec['placement']['label'] = values['label'];
1060 if (_.isNumber(values['count']) && values['count'] > 0) {
1061 serviceSpec['placement']['count'] = values['count'];
1063 switch (serviceType) {
1065 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1066 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1068 serviceSpec['ssl'] = values['ssl'];
1069 if (values['ssl']) {
1070 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1074 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1075 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1077 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1078 serviceSpec['api_port'] = values['api_port'];
1080 serviceSpec['api_user'] = values['api_user'];
1081 serviceSpec['api_password'] = values['api_password'];
1082 serviceSpec['api_secure'] = values['ssl'];
1083 if (values['ssl']) {
1084 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1085 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1089 serviceSpec['ssl'] = values['ssl'];
1090 if (values['ssl']) {
1091 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1092 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1094 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1097 serviceSpec['port'] = values['grafana_port'];
1098 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1100 case 'oauth2-proxy':
1101 serviceSpec['provider_display_name'] = values['provider_display_name']?.trim();
1102 serviceSpec['client_id'] = values['client_id']?.trim();
1103 serviceSpec['client_secret'] = values['client_secret']?.trim();
1104 serviceSpec['oidc_issuer_url'] = values['oidc_issuer_url']?.trim();
1105 serviceSpec['https_address'] = values['https_address']?.trim();
1106 serviceSpec['redirect_url'] = values['redirect_url']?.trim();
1107 serviceSpec['allowlist_domains'] = values['allowlist_domains']?.trim().split(',');
1108 if (values['ssl']) {
1109 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1110 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1115 this.taskWrapperService
1116 .wrapTaskAroundCall({
1117 task: new FinishedTask(taskUrl, {
1118 service_name: serviceName
1121 ? this.cephServiceService.update(serviceSpec)
1122 : this.cephServiceService.create(serviceSpec)
1126 self.serviceForm.setErrors({ cdSubmitButton: true });
1129 this.pageURL === 'services'
1130 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1131 : this.activeModal.close();
1136 clearValidations() {
1137 const snmpVersion = this.serviceForm.getValue('snmp_version');
1138 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1139 if (snmpVersion === 'V3') {
1140 this.serviceForm.get('snmp_community').clearValidators();
1142 this.serviceForm.get('engine_id').clearValidators();
1143 this.serviceForm.get('auth_protocol').clearValidators();
1144 this.serviceForm.get('privacy_protocol').clearValidators();
1145 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1146 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1148 if (privacyProtocol === null) {
1149 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1153 createMultisiteSetup() {
1154 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1157 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1158 this.setRgwFields();