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 @ViewChild(NgbTypeahead, { static: false })
53 typeahead: NgbTypeahead;
55 @Input() hiddenServices: string[] = [];
57 @Input() editing = false;
59 @Input() serviceName: string;
61 @Input() serviceType: string;
63 serviceForm: CdFormGroup;
66 serviceTypes: string[] = [];
67 serviceIds: string[] = [];
70 labelClick = new Subject<string>();
71 labelFocus = new Subject<string>();
73 rbdPools: Array<Pool>;
74 services: Array<CephServiceSpec> = [];
76 serviceList: CephServiceSpec[];
77 multisiteInfo: object[] = [];
79 defaultZonegroupId = '';
81 realmList: RgwRealm[] = [];
82 zonegroupList: RgwZonegroup[] = [];
83 zoneList: RgwZone[] = [];
84 bsModalRef: NgbModalRef;
85 defaultZonegroup: RgwZonegroup;
86 showRealmCreationForm = false;
87 defaultsInfo: { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string };
89 zonegroupNames: string[];
91 smbFeaturesList = ['domain'];
94 public actionLabels: ActionLabelsI18n,
95 private cephServiceService: CephServiceService,
96 private formBuilder: CdFormBuilder,
97 private hostService: HostService,
98 private poolService: PoolService,
99 private rbdService: RbdService,
100 private router: Router,
101 private taskWrapperService: TaskWrapperService,
102 public timerService: TimerService,
103 public timerServiceVariable: TimerServiceInterval,
104 public rgwRealmService: RgwRealmService,
105 public rgwZonegroupService: RgwZonegroupService,
106 public rgwZoneService: RgwZoneService,
107 public rgwMultisiteService: RgwMultisiteService,
108 private route: ActivatedRoute,
109 public activeModal: NgbActiveModal,
110 public modalService: ModalService
113 this.resource = $localize`service`;
116 messages: new SelectMessages({
117 empty: $localize`There are no hosts.`,
118 filter: $localize`Filter hosts`
125 this.serviceForm = this.formBuilder.group({
127 service_type: [null, [Validators.required]],
131 CdValidators.composeIf(
137 CdValidators.custom('mdsPattern', (value: string) => {
138 if (_.isEmpty(value)) {
141 return !this.MDS_SVC_ID_PATTERN.test(value);
145 CdValidators.requiredIf({
148 CdValidators.requiredIf({
149 service_type: 'iscsi'
151 CdValidators.requiredIf({
152 service_type: 'nvmeof'
154 CdValidators.requiredIf({
155 service_type: 'ingress'
157 CdValidators.requiredIf({
160 CdValidators.composeIf(
164 [Validators.required]
166 CdValidators.custom('uniqueName', (service_id: string) => {
167 return this.serviceIds && this.serviceIds.includes(service_id);
171 placement: ['hosts'],
175 CdValidators.requiredIf({
182 count: [null, [CdValidators.number(false)]],
189 CdValidators.requiredIf({
190 service_type: 'iscsi'
192 CdValidators.requiredIf({
193 service_type: 'nvmeof'
199 CdValidators.requiredIf({
200 service_type: 'nvmeof'
204 rgw_frontend_port: [null, [CdValidators.number(false)]],
206 zonegroup_name: [null],
209 trusted_ip_list: [null],
210 api_port: [null, [CdValidators.number(false)]],
214 CdValidators.requiredIf({
215 service_type: 'iscsi',
223 CdValidators.requiredIf({
224 service_type: 'iscsi',
233 CdValidators.requiredIf({
238 features: new CdFormGroup(
239 this.smbFeaturesList.reduce((acc: object, e) => {
240 acc[e] = new UntypedFormControl(false);
247 CdValidators.composeIf(
253 CdValidators.custom('configUriPattern', (value: string) => {
254 if (_.isEmpty(value)) {
257 return !this.SMB_CONFIG_URI_PATTERN.test(value);
264 join_sources: [null],
265 user_sources: [null],
266 include_ceph_users: [null],
271 CdValidators.requiredIf({
272 service_type: 'ingress'
279 CdValidators.requiredIf({
280 service_type: 'ingress'
287 CdValidators.number(false),
288 CdValidators.requiredIf({
289 service_type: 'ingress'
296 CdValidators.number(false),
297 CdValidators.requiredIf({
298 service_type: 'ingress'
302 virtual_interface_networks: [null],
303 // RGW, Ingress & iSCSI
308 CdValidators.composeIf(
314 [Validators.required, CdValidators.pemCert()]
316 CdValidators.composeIf(
318 service_type: 'iscsi',
322 [Validators.required, CdValidators.sslCert()]
324 CdValidators.composeIf(
326 service_type: 'ingress',
330 [Validators.required, CdValidators.pemCert()]
337 CdValidators.composeIf(
339 service_type: 'iscsi',
343 [Validators.required, CdValidators.sslPrivKey()]
351 CdValidators.requiredIf({
352 service_type: 'snmp-gateway'
360 CdValidators.requiredIf({
361 service_type: 'snmp-gateway'
363 CdValidators.custom('snmpDestinationPattern', (value: string) => {
364 if (_.isEmpty(value)) {
367 return !this.SNMP_DESTINATION_PATTERN.test(value);
375 CdValidators.requiredIf({
376 service_type: 'snmp-gateway'
378 CdValidators.custom('snmpEngineIdPattern', (value: string) => {
379 if (_.isEmpty(value)) {
382 return !this.SNMP_ENGINE_ID_PATTERN.test(value);
389 CdValidators.requiredIf({
390 service_type: 'snmp-gateway'
394 privacy_protocol: [null],
398 CdValidators.requiredIf({
403 snmp_v3_auth_username: [
406 CdValidators.requiredIf({
407 service_type: 'snmp-gateway'
411 snmp_v3_auth_password: [
414 CdValidators.requiredIf({
415 service_type: 'snmp-gateway'
419 snmp_v3_priv_password: [
422 CdValidators.requiredIf({
423 privacy_protocol: { op: '!empty' }
427 grafana_port: [null, [CdValidators.number(false)]],
428 grafana_admin_password: [null]
433 if (this.router.url.includes('services/(modal:create')) {
434 this.pageURL = 'services';
435 this.route.params.subscribe((params: { type: string }) => {
437 this.serviceType = params.type;
438 this.serviceForm.get('service_type').setValue(this.serviceType);
441 } else if (this.router.url.includes('services/(modal:edit')) {
443 this.pageURL = 'services';
444 this.route.params.subscribe((params: { type: string; name: string }) => {
445 this.serviceName = params.name;
446 this.serviceType = params.type;
452 this.action = this.actionLabels.CREATE;
455 this.cephServiceService
456 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }))
457 .observable.subscribe((services: CephServiceSpec[]) => {
458 this.serviceList = services;
459 this.services = services.filter((service: any) =>
460 this.INGRESS_SUPPORTED_SERVICE_TYPES.includes(service.service_type)
464 this.cephServiceService.getKnownTypes().subscribe((resp: Array<string>) => {
465 // Remove service types:
466 // osd - This is deployed a different way.
467 // container - This should only be used in the CLI.
468 this.hiddenServices.push('osd', 'container');
470 this.serviceTypes = _.difference(resp, this.hiddenServices).sort();
472 this.hostService.getAllHosts().subscribe((resp: object[]) => {
473 const options: SelectOption[] = [];
474 _.forEach(resp, (host: object) => {
475 if (_.get(host, 'sources.orchestrator', false)) {
476 const option = new SelectOption(false, _.get(host, 'hostname'), '');
477 options.push(option);
480 this.hosts.options = [...options];
482 this.hostService.getLabels().subscribe((resp: string[]) => {
485 this.poolService.getList().subscribe((resp: Pool[]) => {
487 this.rbdPools = this.pools.filter(this.rbdService.isRBDPool);
488 if (!this.editing && this.serviceType) {
489 this.onServiceTypeChange(this.serviceType);
494 this.action = this.actionLabels.EDIT;
495 this.disableForEditing(this.serviceType);
496 this.cephServiceService
497 .list(new HttpParams({ fromObject: { limit: -1, offset: 0 } }), this.serviceName)
498 .observable.subscribe((response: CephServiceSpec[]) => {
499 const formKeys = ['service_type', 'service_id', 'unmanaged'];
500 formKeys.forEach((keys) => {
501 this.serviceForm.get(keys).setValue(response[0][keys]);
503 if (!response[0]['unmanaged']) {
504 const placementKey = Object.keys(response[0]['placement'])[0];
505 let placementValue: string;
506 ['hosts', 'label'].indexOf(placementKey) >= 0
507 ? (placementValue = placementKey)
508 : (placementValue = 'hosts');
509 this.serviceForm.get('placement').setValue(placementValue);
510 this.serviceForm.get('count').setValue(response[0]['placement']['count']);
511 if (response[0]?.placement[placementValue]) {
512 this.serviceForm.get(placementValue).setValue(response[0]?.placement[placementValue]);
515 switch (this.serviceType) {
517 const specKeys = ['pool', 'api_password', 'api_user', 'trusted_ip_list', 'api_port'];
518 specKeys.forEach((key) => {
519 this.serviceForm.get(key).setValue(response[0].spec[key]);
521 this.serviceForm.get('ssl').setValue(response[0].spec?.api_secure);
522 if (response[0].spec?.api_secure) {
523 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
524 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
528 this.serviceForm.get('pool').setValue(response[0].spec.pool);
529 this.serviceForm.get('group').setValue(response[0].spec.group);
533 .get('rgw_frontend_port')
534 .setValue(response[0].spec?.rgw_frontend_port);
536 response[0].spec?.rgw_realm,
537 response[0].spec?.rgw_zonegroup,
538 response[0].spec?.rgw_zone
540 this.serviceForm.get('ssl').setValue(response[0].spec?.ssl);
541 if (response[0].spec?.ssl) {
544 .setValue(response[0].spec?.rgw_frontend_ssl_certificate);
548 const ingressSpecKeys = [
553 'virtual_interface_networks',
556 ingressSpecKeys.forEach((key) => {
557 this.serviceForm.get(key).setValue(response[0].spec[key]);
559 if (response[0].spec?.ssl) {
560 this.serviceForm.get('ssl_cert').setValue(response[0].spec?.ssl_cert);
561 this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
565 const smbSpecKeys = [
574 smbSpecKeys.forEach((key) => {
575 if (key === 'features') {
576 if (response[0].spec?.features) {
577 response[0].spec.features.forEach((feature) => {
578 this.serviceForm.get(`features.${feature}`).setValue(true);
582 this.serviceForm.get(key).setValue(response[0].spec[key]);
587 const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
588 snmpCommonSpecKeys.forEach((key) => {
589 this.serviceForm.get(key).setValue(response[0].spec[key]);
591 if (this.serviceForm.getValue('snmp_version') === 'V3') {
592 const snmpV3SpecKeys = [
596 'snmp_v3_auth_username',
597 'snmp_v3_auth_password',
598 'snmp_v3_priv_password'
600 snmpV3SpecKeys.forEach((key) => {
603 key === 'snmp_v3_auth_username' ||
604 key === 'snmp_v3_auth_password' ||
605 key === 'snmp_v3_priv_password'
607 this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
609 this.serviceForm.get(key).setValue(response[0].spec[key]);
615 .get('snmp_community')
616 .setValue(response[0].spec['credentials']['snmp_community']);
620 this.serviceForm.get('grafana_port').setValue(response[0].spec.port);
622 .get('grafana_admin_password')
623 .setValue(response[0].spec.initial_admin_password);
630 getDefaultsEntitiesForRgw(
631 defaultRealmId: string,
632 defaultZonegroupId: string,
633 defaultZoneId: string
634 ): { defaultRealmName: string; defaultZonegroupName: string; defaultZoneName: string } {
635 const defaultRealm = this.realmList.find((x: { id: string }) => x.id === defaultRealmId);
636 const defaultZonegroup = this.zonegroupList.find(
637 (x: { id: string }) => x.id === defaultZonegroupId
639 const defaultZone = this.zoneList.find((x: { id: string }) => x.id === defaultZoneId);
640 const defaultRealmName = defaultRealm !== undefined ? defaultRealm.name : null;
641 const defaultZonegroupName = defaultZonegroup !== undefined ? defaultZonegroup.name : 'default';
642 const defaultZoneName = defaultZone !== undefined ? defaultZone.name : 'default';
643 if (defaultZonegroupName === 'default' && !this.zonegroupNames.includes(defaultZonegroupName)) {
644 const defaultZonegroup = new RgwZonegroup();
645 defaultZonegroup.name = 'default';
646 this.zonegroupList.push(defaultZonegroup);
648 if (defaultZoneName === 'default' && !this.zoneNames.includes(defaultZoneName)) {
649 const defaultZone = new RgwZone();
650 defaultZone.name = 'default';
651 this.zoneList.push(defaultZone);
654 defaultRealmName: defaultRealmName,
655 defaultZonegroupName: defaultZonegroupName,
656 defaultZoneName: defaultZoneName
660 getDefaultPlacementCount(serviceType: string) {
662 * `defaults` from src/pybind/mgr/cephadm/module.py
664 switch (serviceType) {
666 this.serviceForm.get('count').setValue(5);
673 this.serviceForm.get('count').setValue(2);
676 case 'cephfs-mirror':
684 case 'elastic-serach':
685 case 'jaeger-collector':
688 this.serviceForm.get('count').setValue(1);
691 this.serviceForm.get('count').setValue(null);
695 setRgwFields(realm_name?: string, zonegroup_name?: string, zone_name?: string) {
696 const observables = [
697 this.rgwRealmService.getAllRealmsInfo(),
698 this.rgwZonegroupService.getAllZonegroupsInfo(),
699 this.rgwZoneService.getAllZonesInfo()
701 this.sub = forkJoin(observables).subscribe(
702 (multisiteInfo: [object, object, object]) => {
703 this.multisiteInfo = multisiteInfo;
705 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
706 ? this.multisiteInfo[0]['realms']
709 this.multisiteInfo[1] !== undefined && this.multisiteInfo[1].hasOwnProperty('zonegroups')
710 ? this.multisiteInfo[1]['zonegroups']
713 this.multisiteInfo[2] !== undefined && this.multisiteInfo[2].hasOwnProperty('zones')
714 ? this.multisiteInfo[2]['zones']
716 this.realmNames = this.realmList.map((realm) => {
717 return realm['name'];
719 this.zonegroupNames = this.zonegroupList.map((zonegroup) => {
720 return zonegroup['name'];
722 this.zoneNames = this.zoneList.map((zone) => {
725 this.defaultRealmId = multisiteInfo[0]['default_realm'];
726 this.defaultZonegroupId = multisiteInfo[1]['default_zonegroup'];
727 this.defaultZoneId = multisiteInfo[2]['default_zone'];
728 this.defaultsInfo = this.getDefaultsEntitiesForRgw(
730 this.defaultZonegroupId,
734 this.serviceForm.get('realm_name').setValue(this.defaultsInfo['defaultRealmName']);
736 .get('zonegroup_name')
737 .setValue(this.defaultsInfo['defaultZonegroupName']);
738 this.serviceForm.get('zone_name').setValue(this.defaultsInfo['defaultZoneName']);
740 if (realm_name && !this.realmNames.includes(realm_name)) {
741 const realm = new RgwRealm();
742 realm.name = realm_name;
743 this.realmList.push(realm);
745 if (zonegroup_name && !this.zonegroupNames.includes(zonegroup_name)) {
746 const zonegroup = new RgwZonegroup();
747 zonegroup.name = zonegroup_name;
748 this.zonegroupList.push(zonegroup);
750 if (zone_name && !this.zoneNames.includes(zone_name)) {
751 const zone = new RgwZone();
752 zone.name = zone_name;
753 this.zoneList.push(zone);
755 if (zonegroup_name === undefined && zone_name === undefined) {
756 zonegroup_name = 'default';
757 zone_name = 'default';
759 this.serviceForm.get('realm_name').setValue(realm_name);
760 this.serviceForm.get('zonegroup_name').setValue(zonegroup_name);
761 this.serviceForm.get('zone_name').setValue(zone_name);
763 if (this.realmList.length === 0) {
764 this.showRealmCreationForm = true;
766 this.showRealmCreationForm = false;
770 const defaultZone = new RgwZone();
771 defaultZone.name = 'default';
772 const defaultZonegroup = new RgwZonegroup();
773 defaultZonegroup.name = 'default';
774 this.zoneList.push(defaultZone);
775 this.zonegroupList.push(defaultZonegroup);
780 onNvmeofGroupChange(groupName: string) {
781 const pool = this.serviceForm.get('pool').value;
782 if (pool) this.serviceForm.get('service_id').setValue(`${pool}.${groupName}`);
783 else this.serviceForm.get('service_id').setValue(groupName);
786 getDefaultBlockPool(): string {
787 // returns 'rbd' pool otherwise the first block pool
789 this.rbdPools?.find((p: Pool) => p.pool_name === 'rbd')?.pool_name ||
790 this.rbdPools?.[0].pool_name
794 setNvmeofServiceIdAndPool(): void {
795 const defaultBlockPool: string = this.getDefaultBlockPool();
796 const group: string = this.serviceForm.get('group').value;
797 if (defaultBlockPool && group) {
798 this.serviceForm.get('pool').setValue(defaultBlockPool);
799 this.serviceForm.get('service_id').setValue(`${defaultBlockPool}.${group}`);
801 this.serviceForm.get('service_id').setValue(null);
805 requiresServiceId(serviceType: string) {
806 return ['mds', 'rgw', 'nfs', 'iscsi', 'nvmeof', 'smb', 'ingress'].includes(serviceType);
809 setServiceId(serviceId: string): void {
810 const requiresServiceId: boolean = this.requiresServiceId(serviceId);
811 if (requiresServiceId && serviceId === 'nvmeof') {
812 this.setNvmeofServiceIdAndPool();
813 } else if (requiresServiceId) {
814 this.serviceForm.get('service_id').setValue(null);
816 this.serviceForm.get('service_id').setValue(serviceId);
820 onServiceTypeChange(selectedServiceType: string) {
821 this.setServiceId(selectedServiceType);
823 this.serviceIds = this.serviceList
824 ?.filter((service) => service['service_type'] === selectedServiceType)
825 .map((service) => service['service_id']);
827 this.getDefaultPlacementCount(selectedServiceType);
829 if (selectedServiceType === 'rgw') {
834 onPlacementChange(selected: string) {
835 if (selected === 'label') {
836 this.serviceForm.get('count').setValue(null);
840 onBlockPoolChange() {
841 const selectedBlockPool = this.serviceForm.get('pool').value;
842 const group = this.serviceForm.get('group').value;
843 if (selectedBlockPool && group) {
844 this.serviceForm.get('service_id').setValue(`${selectedBlockPool}.${group}`);
845 } else if (selectedBlockPool) {
846 this.serviceForm.get('service_id').setValue(selectedBlockPool);
848 this.serviceForm.get('service_id').setValue(null);
852 disableForEditing(serviceType: string) {
853 const disableForEditKeys = ['service_type', 'service_id'];
854 disableForEditKeys.forEach((key) => {
855 this.serviceForm.get(key).disable();
857 switch (serviceType) {
859 this.serviceForm.get('backend_service').disable();
862 this.serviceForm.get('pool').disable();
863 this.serviceForm.get('group').disable();
868 searchLabels = (text$: Observable<string>) => {
870 text$.pipe(debounceTime(200), distinctUntilChanged()),
872 this.labelClick.pipe(filter(() => !this.typeahead.isPopupOpen()))
876 .filter((label: string) => label.toLowerCase().indexOf(value.toLowerCase()) > -1)
882 fileUpload(files: FileList, controlName: string) {
883 const file: File = files[0];
884 const reader = new FileReader();
885 reader.addEventListener('load', (event: ProgressEvent<FileReader>) => {
886 const control: AbstractControl = this.serviceForm.get(controlName);
887 control.setValue(event.target.result);
888 control.markAsDirty();
889 control.markAsTouched();
890 control.updateValueAndValidity();
892 reader.readAsText(file, 'utf8');
896 const control: AbstractControl = this.serviceForm.get('service_id');
897 const backendService = this.serviceForm.getValue('backend_service');
898 // Set Id as read-only
899 control.reset({ value: backendService, disabled: true });
904 const values: object = this.serviceForm.getRawValue();
905 const serviceType: string = values['service_type'];
906 let taskUrl = `service/${URLVerbs.CREATE}`;
908 taskUrl = `service/${URLVerbs.EDIT}`;
910 const serviceSpec: object = {
911 service_type: serviceType,
913 unmanaged: values['unmanaged']
915 if (serviceType === 'rgw') {
916 serviceSpec['rgw_realm'] = values['realm_name'] ? values['realm_name'] : null;
917 serviceSpec['rgw_zonegroup'] =
918 values['zonegroup_name'] !== 'default' ? values['zonegroup_name'] : null;
919 serviceSpec['rgw_zone'] = values['zone_name'] !== 'default' ? values['zone_name'] : null;
922 const serviceId: string = values['service_id'];
923 let serviceName: string = serviceType;
924 if (_.isString(serviceId) && !_.isEmpty(serviceId) && serviceId !== serviceType) {
925 serviceName = `${serviceType}.${serviceId}`;
926 serviceSpec['service_id'] = serviceId;
929 // These services has some fields to be
930 // filled out even if unmanaged is true
931 switch (serviceType) {
933 serviceSpec['backend_service'] = values['backend_service'];
934 serviceSpec['service_id'] = values['backend_service'];
935 if (_.isNumber(values['frontend_port']) && values['frontend_port'] > 0) {
936 serviceSpec['frontend_port'] = values['frontend_port'];
938 if (_.isString(values['virtual_ip']) && !_.isEmpty(values['virtual_ip'])) {
939 serviceSpec['virtual_ip'] = values['virtual_ip'].trim();
941 if (_.isNumber(values['monitor_port']) && values['monitor_port'] > 0) {
942 serviceSpec['monitor_port'] = values['monitor_port'];
947 serviceSpec['pool'] = values['pool'];
948 serviceSpec['group'] = values['group'];
951 serviceSpec['pool'] = values['pool'];
955 serviceSpec['cluster_id'] = values['cluster_id']?.trim();
956 serviceSpec['config_uri'] = values['config_uri']?.trim();
957 for (const feature in values['features']) {
958 if (values['features'][feature]) {
959 (serviceSpec['features'] = serviceSpec['features'] || []).push(feature);
962 serviceSpec['custom_dns'] = values['custom_dns']?.trim();
963 serviceSpec['join_sources'] = values['join_sources']?.trim();
964 serviceSpec['user_sources'] = values['user_sources']?.trim();
965 serviceSpec['include_ceph_users'] = values['include_ceph_users']?.trim();
969 serviceSpec['credentials'] = {};
970 serviceSpec['snmp_version'] = values['snmp_version'];
971 serviceSpec['snmp_destination'] = values['snmp_destination'];
972 if (values['snmp_version'] === 'V3') {
973 serviceSpec['engine_id'] = values['engine_id'];
974 serviceSpec['auth_protocol'] = values['auth_protocol'];
975 serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
976 serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
977 if (values['privacy_protocol'] !== null) {
978 serviceSpec['privacy_protocol'] = values['privacy_protocol'];
979 serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
982 serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
987 if (!values['unmanaged']) {
988 switch (values['placement']) {
990 if (values['hosts'].length > 0) {
991 serviceSpec['placement']['hosts'] = values['hosts'];
995 serviceSpec['placement']['label'] = values['label'];
998 if (_.isNumber(values['count']) && values['count'] > 0) {
999 serviceSpec['placement']['count'] = values['count'];
1001 switch (serviceType) {
1003 if (_.isNumber(values['rgw_frontend_port']) && values['rgw_frontend_port'] > 0) {
1004 serviceSpec['rgw_frontend_port'] = values['rgw_frontend_port'];
1006 serviceSpec['ssl'] = values['ssl'];
1007 if (values['ssl']) {
1008 serviceSpec['rgw_frontend_ssl_certificate'] = values['ssl_cert']?.trim();
1012 if (_.isString(values['trusted_ip_list']) && !_.isEmpty(values['trusted_ip_list'])) {
1013 serviceSpec['trusted_ip_list'] = values['trusted_ip_list'].trim();
1015 if (_.isNumber(values['api_port']) && values['api_port'] > 0) {
1016 serviceSpec['api_port'] = values['api_port'];
1018 serviceSpec['api_user'] = values['api_user'];
1019 serviceSpec['api_password'] = values['api_password'];
1020 serviceSpec['api_secure'] = values['ssl'];
1021 if (values['ssl']) {
1022 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1023 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1027 serviceSpec['ssl'] = values['ssl'];
1028 if (values['ssl']) {
1029 serviceSpec['ssl_cert'] = values['ssl_cert']?.trim();
1030 serviceSpec['ssl_key'] = values['ssl_key']?.trim();
1032 serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
1035 serviceSpec['port'] = values['grafana_port'];
1036 serviceSpec['initial_admin_password'] = values['grafana_admin_password'];
1040 this.taskWrapperService
1041 .wrapTaskAroundCall({
1042 task: new FinishedTask(taskUrl, {
1043 service_name: serviceName
1046 ? this.cephServiceService.update(serviceSpec)
1047 : this.cephServiceService.create(serviceSpec)
1051 self.serviceForm.setErrors({ cdSubmitButton: true });
1054 this.pageURL === 'services'
1055 ? this.router.navigate([this.pageURL, { outlets: { modal: null } }])
1056 : this.activeModal.close();
1061 clearValidations() {
1062 const snmpVersion = this.serviceForm.getValue('snmp_version');
1063 const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
1064 if (snmpVersion === 'V3') {
1065 this.serviceForm.get('snmp_community').clearValidators();
1067 this.serviceForm.get('engine_id').clearValidators();
1068 this.serviceForm.get('auth_protocol').clearValidators();
1069 this.serviceForm.get('privacy_protocol').clearValidators();
1070 this.serviceForm.get('snmp_v3_auth_username').clearValidators();
1071 this.serviceForm.get('snmp_v3_auth_password').clearValidators();
1073 if (privacyProtocol === null) {
1074 this.serviceForm.get('snmp_v3_priv_password').clearValidators();
1078 createMultisiteSetup() {
1079 this.bsModalRef = this.modalService.show(CreateRgwServiceEntitiesComponent, {
1082 this.bsModalRef.componentInstance.submitAction.subscribe(() => {
1083 this.setRgwFields();