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'
198 group: [null, Validators.required],
200 rgw_frontend_port: [null, [CdValidators.number(false)]],
202 zonegroup_name: [null],
205 trusted_ip_list: [null],
206 api_port: [null, [CdValidators.number(false)]],
210 CdValidators.requiredIf({
211 service_type: 'iscsi',
219 CdValidators.requiredIf({
220 service_type: 'iscsi',
229 CdValidators.requiredIf({
234 features: new CdFormGroup(
235 this.smbFeaturesList.reduce((acc: object, e) => {
236 acc[e] = new UntypedFormControl(false);
243 CdValidators.composeIf(
249 CdValidators.custom('configUriPattern', (value: string) => {
250 if (_.isEmpty(value)) {
253 return !this.SMB_CONFIG_URI_PATTERN.test(value);
260 join_sources: [null],
261 user_sources: [null],
262 include_ceph_users: [null],
267 CdValidators.requiredIf({
268 service_type: 'ingress'
275 CdValidators.requiredIf({
276 service_type: 'ingress'
283 CdValidators.number(false),
284 CdValidators.requiredIf({
285 service_type: 'ingress'
292 CdValidators.number(false),
293 CdValidators.requiredIf({
294 service_type: 'ingress'
298 virtual_interface_networks: [null],
299 // RGW, Ingress & iSCSI
304 CdValidators.composeIf(
310 [Validators.required, CdValidators.pemCert()]
312 CdValidators.composeIf(
314 service_type: 'iscsi',
318 [Validators.required, CdValidators.sslCert()]
320 CdValidators.composeIf(
322 service_type: 'ingress',
326 [Validators.required, CdValidators.pemCert()]
333 CdValidators.composeIf(
335 service_type: 'iscsi',
339 [Validators.required, CdValidators.sslPrivKey()]
347 CdValidators.requiredIf({
348 service_type: 'snmp-gateway'
356 CdValidators.requiredIf({
357 service_type: 'snmp-gateway'
359 CdValidators.custom('snmpDestinationPattern', (value: string) => {
360 if (_.isEmpty(value)) {
363 return !this.SNMP_DESTINATION_PATTERN.test(value);
371 CdValidators.requiredIf({
372 service_type: 'snmp-gateway'
374 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
375 if (_.isEmpty(value)) {
378 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
385 CdValidators.requiredIf({
386 service_type: 'snmp-gateway'
390 privacy_protocol: [null],
394 CdValidators.requiredIf({
399 snmp_v3_auth_username: [
402 CdValidators.requiredIf({
403 service_type: 'snmp-gateway'
407 snmp_v3_auth_password: [
410 CdValidators.requiredIf({
411 service_type: 'snmp-gateway'
415 snmp_v3_priv_password: [
418 CdValidators.requiredIf({
419 privacy_protocol: { op: '!empty' }
423 grafana_port: [null, [CdValidators.number(false)]],
424 grafana_admin_password: [null]
429 if (this.router.url.includes('services/(modal:create')) {
430 this.pageURL = 'services';
431 this.route.params.subscribe((params: { type: string }) => {
433 this.serviceType = params.type;
434 this.serviceForm.get('service_type').setValue(this.serviceType);
437 } else if (this.router.url.includes('services/(modal:edit')) {
439 this.pageURL = 'services';
440 this.route.params.subscribe((params: { type: string; name: string }) => {
441 this.serviceName = params.name;
442 this.serviceType = params.type;
448 this.action = this.actionLabels.CREATE;
451 this.cephServiceService
452 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
453 .observable.subscribe((services: CephServiceSpec[]) => {
454 this.serviceList = services;
455 this.services = services.filter((service: any) =>
456 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
460 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
461 // Remove service types:
462 // osd - This is deployed a different way.
463 // container - This should only be used in the CLI.
464 this.hiddenServices.push('osd', 'container');
466 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
468 const hostContext = new CdTableFetchDataContext(() => undefined);
469 this.hostService.list(hostContext.toParams(), 'false').subscribe((resp: object[]) => {
470 const options: SelectOption[] = [];
471 _.forEach(resp, (host: object) => {
472 if (_.get(host, 'sources.orchestrator', false)) {
473 const option = new SelectOption(false, _.get(host, 'hostname'), '');
474 options.push(option);
477 this.hosts.options = [...options];
479 this.hostService.getLabels().subscribe((resp: string[]) => {
482 this.poolService.getList().subscribe((resp: Pool[]) => {
484 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
485 if (!this.editing && this.serviceType) {
486 this.onServiceTypeChange(this.serviceType);
491 this.action = this.actionLabels.EDIT;
492 this.disableForEditing(this.serviceType);
493 this.cephServiceService
494 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
495 .observable.subscribe((response: CephServiceSpec[]) => {
496 const formKeys = ['service_type', 'service_id', 'unmanaged'];
497 formKeys.forEach((keys) => {
498 this.serviceForm.get(keys).setValue(response[0][keys]);
500 if (!response[0]['unmanaged']) {
501 const placementKey = Object.keys(response[0]['placement'])[0];
502 let placementValue: string;
503 ['hosts', 'label'].indexOf(placementKey) >= 0
504 ? (placementValue = placementKey)
505 : (placementValue = 'hosts');
506 this.serviceForm.get('placement').setValue(placementValue);
507 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
508 if (response[0]?.placement[placementValue]) {
509 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
512 switch (this.serviceType) {
514 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
515 specKeys.forEach((key) => {
516 this.serviceForm.get(key).setValue(response[0].spec[key]);
518 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
519 if (response[0].spec?.api_secure) {
520 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
521 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
525 this.serviceForm.get('pool').setValue(response[0].spec.pool);
526 this.serviceForm.get('group').setValue(response[0].spec.group);
530 .get('rgw_frontend_port')
531 .setValue(response[0].spec?.rgw_frontend_port);
533 response[0].spec?.rgw_realm,
534 response[0].spec?.rgw_zonegroup,
535 response[0].spec?.rgw_zone
537 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
538 if (response[0].spec?.ssl) {
541 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
545 const ingressSpecKeys = [
550 'virtual_interface_networks',
553 ingressSpecKeys.forEach((key) => {
554 this.serviceForm.get(key).setValue(response[0].spec[key]);
556 if (response[0].spec?.ssl) {
557 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
558 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
562 const smbSpecKeys = [
571 smbSpecKeys.forEach((key) => {
572 if (key === 'features') {
573 if (response[0].spec?.features) {
574 response[0].spec.features.forEach((feature) => {
575 this.serviceForm.get(`features.${feature}`).setValue(true);
579 this.serviceForm.get(key).setValue(response[0].spec[key]);
584 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
585 snmpCommonSpecKeys.forEach((key) => {
586 this.serviceForm.get(key).setValue(response[0].spec[key]);
588 if (this.serviceForm.getValue('snmp_version') === 'V3') {
589 const snmpV3SpecKeys = [
593 'snmp_v3_auth_username',
594 'snmp_v3_auth_password',
595 'snmp_v3_priv_password'
597 snmpV3SpecKeys.forEach((key) => {
600 key === 'snmp_v3_auth_username' ||
601 key === 'snmp_v3_auth_password' ||
602 key === 'snmp_v3_priv_password'
604 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
606 this.serviceForm.get(key).setValue(response[0].spec[key]);
612 .get('snmp_community')
613 .setValue(response[0].spec['credentials']['snmp_community']);
617 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
619 .get('grafana_admin_password')
620 .setValue(response[0].spec.initial_admin_password);
627 getDefaultsEntitiesForRgw(
628 defaultRealmId: string,
629 defaultZonegroupId: string,
630 defaultZoneId: string
631 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
632 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
633 const defaultZonegroup = this.zonegroupList.find(
634 (x: { id: string }) => x.id === defaultZonegroupId
636 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
637 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
638 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
639 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
640 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
641 const defaultZonegroup = new RgwZonegroup();
642 defaultZonegroup.name = 'default';
643 this.zonegroupList.push(defaultZonegroup);
645 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
646 const defaultZone = new RgwZone();
647 defaultZone.name = 'default';
648 this.zoneList.push(defaultZone);
651 defaultRealmName: defaultRealmName,
652 defaultZonegroupName: defaultZonegroupName,
653 defaultZoneName: defaultZoneName
657 getDefaultPlacementCount(serviceType: string) {
659 * `defaults` from src/pybind/mgr/cephadm/module.py
661 switch (serviceType) {
663 this.serviceForm.get('count').setValue(5);
670 this.serviceForm.get('count').setValue(2);
674 case 'cephfs-mirror':
682 case 'elastic-serach':
683 case 'jaeger-collector':
686 this.serviceForm.get('count').setValue(1);
689 this.serviceForm.get('count').setValue(null);
693 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
694 const observables = [
695 this.rgwRealmService.getAllRealmsInfo(),
696 this.rgwZonegroupService.getAllZonegroupsInfo(),
697 this.rgwZoneService.getAllZonesInfo()
699 this.sub = forkJoin(observables).subscribe(
700 (multisiteInfo: [object, object, object]) => {
701 this.multisiteInfo = multisiteInfo;
703 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
704 ? this.multisiteInfo[0]['realms']
707 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
708 ? this.multisiteInfo[1]['zonegroups']
711 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
712 ? this.multisiteInfo[2]['zones']
714 this.realmNames = this.realmList.map((realm) => {
715 return realm['name'];
717 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
718 return zonegroup['name'];
720 this.zoneNames = this.zoneList.map((zone) => {
723 this.defaultRealmId = multisiteInfo[0]['default_realm'];
724 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
725 this.defaultZoneId = multisiteInfo[2]['default_zone'];
726 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
728 this.defaultZonegroupId,
732 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
734 .get('zonegroup_name')
735 .setValue(this.defaultsInfo['defaultZonegroupName']);
736 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
738 if (realm_name && !this.realmNames.includes(realm_name)) {
739 const realm = new RgwRealm();
740 realm.name = realm_name;
741 this.realmList.push(realm);
743 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
744 const zonegroup = new RgwZonegroup();
745 zonegroup.name = zonegroup_name;
746 this.zonegroupList.push(zonegroup);
748 if (zone_name && !this.zoneNames.includes(zone_name)) {
749 const zone = new RgwZone();
750 zone.name = zone_name;
751 this.zoneList.push(zone);
753 if (zonegroup_name === undefined && zone_name === undefined) {
754 zonegroup_name = 'default';
755 zone_name = 'default';
757 this.serviceForm.get('realm_name').setValue(realm_name);
758 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
759 this.serviceForm.get('zone_name').setValue(zone_name);
761 if (this.realmList.length === 0) {
762 this.showRealmCreationForm = true;
764 this.showRealmCreationForm = false;
768 const defaultZone = new RgwZone();
769 defaultZone.name = 'default';
770 const defaultZonegroup = new RgwZonegroup();
771 defaultZonegroup.name = 'default';
772 this.zoneList.push(defaultZone);
773 this.zonegroupList.push(defaultZonegroup);
778 setNvmeofServiceId(): void {
779 const defaultRbdPool: string = this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')
781 if (defaultRbdPool) {
782 this.serviceForm.get('pool').setValue(defaultRbdPool);
786 onNvmeofGroupChange(groupName: string) {
787 this.serviceForm.get('service_id').setValue(groupName);
790 requiresServiceId(serviceType: string) {
791 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
794 setServiceId(serviceId: string): void {
795 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
796 if (requiresServiceId && serviceId === 'nvmeof') {
797 this.setNvmeofServiceId();
798 } else if (requiresServiceId) {
799 this.serviceForm.get('service_id').setValue(null);
801 this.serviceForm.get('service_id').setValue(serviceId);
805 onServiceTypeChange(selectedServiceType: string) {
806 this.setServiceId(selectedServiceType);
808 this.serviceIds = this.serviceList
809 ?.filter((service) => service['service_type'] === selectedServiceType)
810 .map((service) => service['service_id']);
812 this.getDefaultPlacementCount(selectedServiceType);
814 if (selectedServiceType === 'rgw') {
819 onPlacementChange(selected: string) {
820 if (selected === 'label') {
821 this.serviceForm.get('count').setValue(null);
825 onBlockPoolChange() {
826 const selectedBlockPool = this.serviceForm.get('pool').value;
827 if (selectedBlockPool) {
828 this.serviceForm.get('service_id').setValue(selectedBlockPool);
830 this.serviceForm.get('service_id').setValue(null);
834 disableForEditing(serviceType: string) {
835 const disableForEditKeys = ['service_type', 'service_id'];
836 disableForEditKeys.forEach((key) => {
837 this.serviceForm.get(key).disable();
839 switch (serviceType) {
841 this.serviceForm.get('backend_service').disable();
844 this.serviceForm.get('pool').disable();
845 this.serviceForm.get('group').disable();
850 searchLabels = (text$: Observable<string>) => {
852 text$.pipe(debounceTime(200), distinctUntilChanged()),
854 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
858 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
864 fileUpload(files: FileList, controlName: string) {
865 const file: File = files[0];
866 const reader = new FileReader();
867 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
868 const control: AbstractControl = this.serviceForm.get(controlName);
869 control.setValue(event.target.result);
870 control.markAsDirty();
871 control.markAsTouched();
872 control.updateValueAndValidity();
874 reader.readAsText(file, 'utf8');
878 const control: AbstractControl = this.serviceForm.get('service_id');
879 const backendService = this.serviceForm.getValue('backend_service');
880 // Set Id as read-only
881 control.reset({ value: backendService, disabled: true });
886 const values: object = this.serviceForm.getRawValue();
887 const serviceType: string = values['service_type'];
888 let taskUrl = `service/${URLVerbs.CREATE}`;
890 taskUrl = `service/${URLVerbs.EDIT}`;
892 const serviceSpec: object = {
893 service_type: serviceType,
895 unmanaged: values['unmanaged']
897 if (serviceType === 'rgw') {
898 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
899 serviceSpec['rgw_zonegroup'] =
900 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
901 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
904 const serviceId: string = values['service_id'];
905 let serviceName: string = serviceType;
906 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
907 serviceName = `${serviceType}.${serviceId}`;
908 serviceSpec['service_id'] = serviceId;
911 // These services has some fields to be
912 // filled out even if unmanaged is true
913 switch (serviceType) {
915 serviceSpec['backend_service'] = values['backend_service'];
916 serviceSpec['service_id'] = values['backend_service'];
917 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
918 serviceSpec['frontend_port'] = values['frontend_port'];
920 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
921 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
923 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
924 serviceSpec['monitor_port'] = values['monitor_port'];
929 serviceSpec['pool'] = values['pool'];
930 serviceSpec['group'] = values['group'];
933 serviceSpec['pool'] = values['pool'];
937 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
938 serviceSpec['config_uri'] = values['config_uri']?.trim();
939 for (const feature in values['features']) {
940 if (values['features'][feature]) {
941 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
944 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
945 serviceSpec['join_sources'] = values['join_sources']?.trim();
946 serviceSpec['user_sources'] = values['user_sources']?.trim();
947 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
951 serviceSpec['credentials'] = {};
952 serviceSpec['snmp_version'] = values['snmp_version'];
953 serviceSpec['snmp_destination'] = values['snmp_destination'];
954 if (values['snmp_version'] === 'V3') {
955 serviceSpec['engine_id'] = values['engine_id'];
956 serviceSpec['auth_protocol'] = values['auth_protocol'];
957 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
958 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
959 if (values['privacy_protocol'] !== null) {
960 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
961 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
964 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
969 if (!values['unmanaged']) {
970 switch (values['placement']) {
972 if (values['hosts'].length > 0) {
973 serviceSpec['placement']['hosts'] = values['hosts'];
977 serviceSpec['placement']['label'] = values['label'];
980 if (_.isNumber(values['count']) && values['count'] > 0) {
981 serviceSpec['placement']['count'] = values['count'];
983 switch (serviceType) {
985 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
986 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
988 serviceSpec['ssl'] = values['ssl'];
990 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
994 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
995 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
997 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
998 serviceSpec['api_port'] = values['api_port'];
1000 serviceSpec['api_user'] = values['api_user'];
1001 serviceSpec['api_password'] = values['api_password'];
1002 serviceSpec['api_secure'] = values['ssl'];
1003 if (values['ssl']) {
1004 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1005 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1009 serviceSpec['ssl'] = values['ssl'];
1010 if (values['ssl']) {
1011 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1012 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1014 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1017 serviceSpec['port'] = values['grafana_port'];
1018 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1022 this.taskWrapperService
1023 .wrapTaskAroundCall({
1024 task: new FinishedTask(taskUrl, {
1025 service_name: serviceName
1028 ? this.cephServiceService.update(serviceSpec)
1029 : this.cephServiceService.create(serviceSpec)
1033 self.serviceForm.setErrors({ cdSubmitButton: true });
1036 this.pageURL === 'services'
1037 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1038 : this.activeModal.close();
1043 clearValidations() {
1044 const snmpVersion = this.serviceForm.getValue('snmp_version');
1045 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1046 if (snmpVersion === 'V3') {
1047 this.serviceForm.get('snmp_community').clearValidators();
1049 this.serviceForm.get('engine_id').clearValidators();
1050 this.serviceForm.get('auth_protocol').clearValidators();
1051 this.serviceForm.get('privacy_protocol').clearValidators();
1052 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1053 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1055 if (privacyProtocol === null) {
1056 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1060 createMultisiteSetup() {
1061 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1064 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1065 this.setRgwFields();