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 { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
34 import { FinishedTask } from '~/app/shared/models/finished-task';
35 import { CephServiceSpec } from '~/app/shared/models/service.interface';
36 import { ModalService } from '~/app/shared/services/modal.service';
37 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
38 import { TimerService } from '~/app/shared/services/timer.service';
41 selector: 'cd-service-form',
42 templateUrl: './service-form.component.html',
43 styleUrls: ['./service-form.component.scss']
45 export class ServiceFormComponent extends CdForm implements OnInit {
46 public sub = new Subscription();
48 readonly MDS_SVC_ID_PATTERN = /^[a-zA-Z_.-][a-zA-Z0-9_.-]*$/;
49 readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
50 readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
51 readonly INGRESS_SUPPORTED_SERVICE_TYPES = ['rgw', 'nfs'];
52 readonly SMB_CONFIG_URI_PATTERN = /^(http:|https:|rados:|rados:mon-config-key:)/;
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'
199 rgw_frontend_port: [null, [CdValidators.number(false)]],
201 zonegroup_name: [null],
204 trusted_ip_list: [null],
205 api_port: [null, [CdValidators.number(false)]],
209 CdValidators.requiredIf({
210 service_type: 'iscsi',
218 CdValidators.requiredIf({
219 service_type: 'iscsi',
228 CdValidators.requiredIf({
233 features: new CdFormGroup(
234 this.smbFeaturesList.reduce((acc: object, e) => {
235 acc[e] = new UntypedFormControl(false);
242 CdValidators.composeIf(
248 CdValidators.custom('configUriPattern', (value: string) => {
249 if (_.isEmpty(value)) {
252 return !this.SMB_CONFIG_URI_PATTERN.test(value);
259 join_sources: [null],
260 user_sources: [null],
261 include_ceph_users: [null],
266 CdValidators.requiredIf({
267 service_type: 'ingress'
274 CdValidators.requiredIf({
275 service_type: 'ingress'
282 CdValidators.number(false),
283 CdValidators.requiredIf({
284 service_type: 'ingress'
291 CdValidators.number(false),
292 CdValidators.requiredIf({
293 service_type: 'ingress'
297 virtual_interface_networks: [null],
298 // RGW, Ingress & iSCSI
303 CdValidators.composeIf(
309 [Validators.required, CdValidators.pemCert()]
311 CdValidators.composeIf(
313 service_type: 'iscsi',
317 [Validators.required, CdValidators.sslCert()]
319 CdValidators.composeIf(
321 service_type: 'ingress',
325 [Validators.required, CdValidators.pemCert()]
332 CdValidators.composeIf(
334 service_type: 'iscsi',
338 [Validators.required, CdValidators.sslPrivKey()]
346 CdValidators.requiredIf({
347 service_type: 'snmp-gateway'
355 CdValidators.requiredIf({
356 service_type: 'snmp-gateway'
358 CdValidators.custom('snmpDestinationPattern', (value: string) => {
359 if (_.isEmpty(value)) {
362 return !this.SNMP_DESTINATION_PATTERN.test(value);
370 CdValidators.requiredIf({
371 service_type: 'snmp-gateway'
373 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
374 if (_.isEmpty(value)) {
377 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
384 CdValidators.requiredIf({
385 service_type: 'snmp-gateway'
389 privacy_protocol: [null],
393 CdValidators.requiredIf({
398 snmp_v3_auth_username: [
401 CdValidators.requiredIf({
402 service_type: 'snmp-gateway'
406 snmp_v3_auth_password: [
409 CdValidators.requiredIf({
410 service_type: 'snmp-gateway'
414 snmp_v3_priv_password: [
417 CdValidators.requiredIf({
418 privacy_protocol: { op: '!empty' }
422 grafana_port: [null, [CdValidators.number(false)]],
423 grafana_admin_password: [null]
428 if (this.router.url.includes('services/(modal:create')) {
429 this.pageURL = 'services';
430 this.route.params.subscribe((params: { type: string }) => {
432 this.serviceType = params.type;
433 this.serviceForm.get('service_type').setValue(this.serviceType);
436 } else if (this.router.url.includes('services/(modal:edit')) {
438 this.pageURL = 'services';
439 this.route.params.subscribe((params: { type: string; name: string }) => {
440 this.serviceName = params.name;
441 this.serviceType = params.type;
447 this.action = this.actionLabels.CREATE;
450 this.cephServiceService
451 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
452 .observable.subscribe((services: CephServiceSpec[]) => {
453 this.serviceList = services;
454 this.services = services.filter((service: any) =>
455 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
459 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
460 // Remove service types:
461 // osd - This is deployed a different way.
462 // container - This should only be used in the CLI.
463 this.hiddenServices.push('osd', 'container');
465 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
467 const hostContext = new CdTableFetchDataContext(() => undefined);
468 this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
469 const options: SelectOption[] = [];
470 _.forEach(resp, (host: object) => {
471 if (_.get(host, 'sources.orchestrator', false)) {
472 const option = new SelectOption(false, _.get(host, 'hostname'), '');
473 options.push(option);
476 this.hosts.options = [...options];
478 this.hostService.getLabels().subscribe((resp: string[]) => {
481 this.poolService.getList().subscribe((resp: Pool[]) => {
483 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
484 if (!this.editing && this.serviceType) {
485 this.onServiceTypeChange(this.serviceType);
490 this.action = this.actionLabels.EDIT;
491 this.disableForEditing(this.serviceType);
492 this.cephServiceService
493 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
494 .observable.subscribe((response: CephServiceSpec[]) => {
495 const formKeys = ['service_type', 'service_id', 'unmanaged'];
496 formKeys.forEach((keys) => {
497 this.serviceForm.get(keys).setValue(response[0][keys]);
499 if (!response[0]['unmanaged']) {
500 const placementKey = Object.keys(response[0]['placement'])[0];
501 let placementValue: string;
502 ['hosts', 'label'].indexOf(placementKey) >= 0
503 ? (placementValue = placementKey)
504 : (placementValue = 'hosts');
505 this.serviceForm.get('placement').setValue(placementValue);
506 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
507 if (response[0]?.placement[placementValue]) {
508 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
511 switch (this.serviceType) {
513 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
514 specKeys.forEach((key) => {
515 this.serviceForm.get(key).setValue(response[0].spec[key]);
517 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
518 if (response[0].spec?.api_secure) {
519 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
520 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
524 this.serviceForm.get('pool').setValue(response[0].spec.pool);
528 .get('rgw_frontend_port')
529 .setValue(response[0].spec?.rgw_frontend_port);
531 response[0].spec?.rgw_realm,
532 response[0].spec?.rgw_zonegroup,
533 response[0].spec?.rgw_zone
535 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
536 if (response[0].spec?.ssl) {
539 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
543 const ingressSpecKeys = [
548 'virtual_interface_networks',
551 ingressSpecKeys.forEach((key) => {
552 this.serviceForm.get(key).setValue(response[0].spec[key]);
554 if (response[0].spec?.ssl) {
555 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
556 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
560 const smbSpecKeys = [
569 smbSpecKeys.forEach((key) => {
570 if (key === 'features') {
571 if (response[0].spec?.features) {
572 response[0].spec.features.forEach((feature) => {
573 this.serviceForm.get(`features.${feature}`).setValue(true);
577 this.serviceForm.get(key).setValue(response[0].spec[key]);
582 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
583 snmpCommonSpecKeys.forEach((key) => {
584 this.serviceForm.get(key).setValue(response[0].spec[key]);
586 if (this.serviceForm.getValue('snmp_version') === 'V3') {
587 const snmpV3SpecKeys = [
591 'snmp_v3_auth_username',
592 'snmp_v3_auth_password',
593 'snmp_v3_priv_password'
595 snmpV3SpecKeys.forEach((key) => {
598 key === 'snmp_v3_auth_username' ||
599 key === 'snmp_v3_auth_password' ||
600 key === 'snmp_v3_priv_password'
602 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
604 this.serviceForm.get(key).setValue(response[0].spec[key]);
610 .get('snmp_community')
611 .setValue(response[0].spec['credentials']['snmp_community']);
615 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
617 .get('grafana_admin_password')
618 .setValue(response[0].spec.initial_admin_password);
625 getDefaultsEntitiesForRgw(
626 defaultRealmId: string,
627 defaultZonegroupId: string,
628 defaultZoneId: string
629 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
630 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
631 const defaultZonegroup = this.zonegroupList.find(
632 (x: { id: string }) => x.id === defaultZonegroupId
634 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
635 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
636 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
637 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
638 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
639 const defaultZonegroup = new RgwZonegroup();
640 defaultZonegroup.name = 'default';
641 this.zonegroupList.push(defaultZonegroup);
643 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
644 const defaultZone = new RgwZone();
645 defaultZone.name = 'default';
646 this.zoneList.push(defaultZone);
649 defaultRealmName: defaultRealmName,
650 defaultZonegroupName: defaultZonegroupName,
651 defaultZoneName: defaultZoneName
655 getDefaultPlacementCount(serviceType: string) {
657 * `defaults` from src/pybind/mgr/cephadm/module.py
659 switch (serviceType) {
661 this.serviceForm.get('count').setValue(5);
668 this.serviceForm.get('count').setValue(2);
672 case 'cephfs-mirror':
680 case 'elastic-serach':
681 case 'jaeger-collector':
684 this.serviceForm.get('count').setValue(1);
687 this.serviceForm.get('count').setValue(null);
691 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
692 const observables = [
693 this.rgwRealmService.getAllRealmsInfo(),
694 this.rgwZonegroupService.getAllZonegroupsInfo(),
695 this.rgwZoneService.getAllZonesInfo()
697 this.sub = forkJoin(observables).subscribe(
698 (multisiteInfo: [object, object, object]) => {
699 this.multisiteInfo = multisiteInfo;
701 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
702 ? this.multisiteInfo[0]['realms']
705 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
706 ? this.multisiteInfo[1]['zonegroups']
709 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
710 ? this.multisiteInfo[2]['zones']
712 this.realmNames = this.realmList.map((realm) => {
713 return realm['name'];
715 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
716 return zonegroup['name'];
718 this.zoneNames = this.zoneList.map((zone) => {
721 this.defaultRealmId = multisiteInfo[0]['default_realm'];
722 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
723 this.defaultZoneId = multisiteInfo[2]['default_zone'];
724 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
726 this.defaultZonegroupId,
730 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
732 .get('zonegroup_name')
733 .setValue(this.defaultsInfo['defaultZonegroupName']);
734 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
736 if (realm_name && !this.realmNames.includes(realm_name)) {
737 const realm = new RgwRealm();
738 realm.name = realm_name;
739 this.realmList.push(realm);
741 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
742 const zonegroup = new RgwZonegroup();
743 zonegroup.name = zonegroup_name;
744 this.zonegroupList.push(zonegroup);
746 if (zone_name && !this.zoneNames.includes(zone_name)) {
747 const zone = new RgwZone();
748 zone.name = zone_name;
749 this.zoneList.push(zone);
751 if (zonegroup_name === undefined && zone_name === undefined) {
752 zonegroup_name = 'default';
753 zone_name = 'default';
755 this.serviceForm.get('realm_name').setValue(realm_name);
756 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
757 this.serviceForm.get('zone_name').setValue(zone_name);
759 if (this.realmList.length === 0) {
760 this.showRealmCreationForm = true;
762 this.showRealmCreationForm = false;
766 const defaultZone = new RgwZone();
767 defaultZone.name = 'default';
768 const defaultZonegroup = new RgwZonegroup();
769 defaultZonegroup.name = 'default';
770 this.zoneList.push(defaultZone);
771 this.zonegroupList.push(defaultZonegroup);
776 setNvmeofServiceId(): void {
777 const defaultRbdPool: string = this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')
779 if (defaultRbdPool) {
780 this.serviceForm.get('pool').setValue(defaultRbdPool);
781 this.serviceForm.get('service_id').setValue(defaultRbdPool);
785 requiresServiceId(serviceType: string) {
786 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
789 setServiceId(serviceId: string): void {
790 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
791 if (requiresServiceId && serviceId === 'nvmeof') {
792 this.setNvmeofServiceId();
793 } else if (requiresServiceId) {
794 this.serviceForm.get('service_id').setValue(null);
796 this.serviceForm.get('service_id').setValue(serviceId);
800 onServiceTypeChange(selectedServiceType: string) {
801 this.setServiceId(selectedServiceType);
803 this.serviceIds = this.serviceList
804 ?.filter((service) => service['service_type'] === selectedServiceType)
805 .map((service) => service['service_id']);
807 this.getDefaultPlacementCount(selectedServiceType);
809 if (selectedServiceType === 'rgw') {
814 onBlockPoolChange() {
815 const selectedBlockPool = this.serviceForm.get('pool').value;
816 if (selectedBlockPool) {
817 this.serviceForm.get('service_id').setValue(selectedBlockPool);
819 this.serviceForm.get('service_id').setValue(null);
823 disableForEditing(serviceType: string) {
824 const disableForEditKeys = ['service_type', 'service_id'];
825 disableForEditKeys.forEach((key) => {
826 this.serviceForm.get(key).disable();
828 switch (serviceType) {
830 this.serviceForm.get('backend_service').disable();
833 this.serviceForm.get('pool').disable();
838 searchLabels = (text$: Observable<string>) => {
840 text$.pipe(debounceTime(200), distinctUntilChanged()),
842 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
846 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
852 fileUpload(files: FileList, controlName: string) {
853 const file: File = files[0];
854 const reader = new FileReader();
855 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
856 const control: AbstractControl = this.serviceForm.get(controlName);
857 control.setValue(event.target.result);
858 control.markAsDirty();
859 control.markAsTouched();
860 control.updateValueAndValidity();
862 reader.readAsText(file, 'utf8');
866 const control: AbstractControl = this.serviceForm.get('service_id');
867 const backendService = this.serviceForm.getValue('backend_service');
868 // Set Id as read-only
869 control.reset({ value: backendService, disabled: true });
874 const values: object = this.serviceForm.getRawValue();
875 const serviceType: string = values['service_type'];
876 let taskUrl = `service/${URLVerbs.CREATE}`;
878 taskUrl = `service/${URLVerbs.EDIT}`;
880 const serviceSpec: object = {
881 service_type: serviceType,
883 unmanaged: values['unmanaged']
885 if (serviceType === 'rgw') {
886 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
887 serviceSpec['rgw_zonegroup'] =
888 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
889 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
892 const serviceId: string = values['service_id'];
893 let serviceName: string = serviceType;
894 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
895 serviceName = `${serviceType}.${serviceId}`;
896 serviceSpec['service_id'] = serviceId;
899 // These services has some fields to be
900 // filled out even if unmanaged is true
901 switch (serviceType) {
903 serviceSpec['backend_service'] = values['backend_service'];
904 serviceSpec['service_id'] = values['backend_service'];
905 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
906 serviceSpec['frontend_port'] = values['frontend_port'];
908 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
909 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
911 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
912 serviceSpec['monitor_port'] = values['monitor_port'];
918 serviceSpec['pool'] = values['pool'];
922 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
923 serviceSpec['config_uri'] = values['config_uri']?.trim();
924 for (const feature in values['features']) {
925 if (values['features'][feature]) {
926 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
929 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
930 serviceSpec['join_sources'] = values['join_sources']?.trim();
931 serviceSpec['user_sources'] = values['user_sources']?.trim();
932 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
936 serviceSpec['credentials'] = {};
937 serviceSpec['snmp_version'] = values['snmp_version'];
938 serviceSpec['snmp_destination'] = values['snmp_destination'];
939 if (values['snmp_version'] === 'V3') {
940 serviceSpec['engine_id'] = values['engine_id'];
941 serviceSpec['auth_protocol'] = values['auth_protocol'];
942 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
943 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
944 if (values['privacy_protocol'] !== null) {
945 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
946 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
949 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
954 if (!values['unmanaged']) {
955 switch (values['placement']) {
957 if (values['hosts'].length > 0) {
958 serviceSpec['placement']['hosts'] = values['hosts'];
962 serviceSpec['placement']['label'] = values['label'];
965 if (_.isNumber(values['count']) && values['count'] > 0) {
966 serviceSpec['placement']['count'] = values['count'];
968 switch (serviceType) {
970 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
971 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
973 serviceSpec['ssl'] = values['ssl'];
975 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
979 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
980 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
982 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
983 serviceSpec['api_port'] = values['api_port'];
985 serviceSpec['api_user'] = values['api_user'];
986 serviceSpec['api_password'] = values['api_password'];
987 serviceSpec['api_secure'] = values['ssl'];
989 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
990 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
994 serviceSpec['ssl'] = values['ssl'];
996 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
997 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
999 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1002 serviceSpec['port'] = values['grafana_port'];
1003 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1007 this.taskWrapperService
1008 .wrapTaskAroundCall({
1009 task: new FinishedTask(taskUrl, {
1010 service_name: serviceName
1013 ? this.cephServiceService.update(serviceSpec)
1014 : this.cephServiceService.create(serviceSpec)
1018 self.serviceForm.setErrors({ cdSubmitButton: true });
1021 this.pageURL === 'services'
1022 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1023 : this.activeModal.close();
1028 clearValidations() {
1029 const snmpVersion = this.serviceForm.getValue('snmp_version');
1030 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1031 if (snmpVersion === 'V3') {
1032 this.serviceForm.get('snmp_community').clearValidators();
1034 this.serviceForm.get('engine_id').clearValidators();
1035 this.serviceForm.get('auth_protocol').clearValidators();
1036 this.serviceForm.get('privacy_protocol').clearValidators();
1037 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1038 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1040 if (privacyProtocol === null) {
1041 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1045 createMultisiteSetup() {
1046 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1049 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1050 this.setRgwFields();