})
export class ServiceFormComponent extends CdForm implements OnInit {
readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/;
+ readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/;
+ readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g;
@ViewChild(NgbTypeahead, { static: false })
typeahead: NgbTypeahead;
]
],
hosts: [[]],
- count: [null, [CdValidators.number(false), Validators.min(1)]],
+ count: [null, [CdValidators.number(false)]],
unmanaged: [false],
// iSCSI
pool: [
]
],
// RGW
- rgw_frontend_port: [
- null,
- [CdValidators.number(false), Validators.min(1), Validators.max(65535)]
- ],
+ rgw_frontend_port: [null, [CdValidators.number(false)]],
// iSCSI
trusted_ip_list: [null],
- api_port: [null, [CdValidators.number(false), Validators.min(1), Validators.max(65535)]],
+ api_port: [null, [CdValidators.number(false)]],
api_user: [
null,
[
})
]
],
- frontend_port: [null, [CdValidators.number(false), Validators.min(1), Validators.max(65535)]],
- monitor_port: [null, [CdValidators.number(false), Validators.min(1), Validators.max(65535)]],
+ frontend_port: [null, [CdValidators.number(false)]],
+ monitor_port: [null, [CdValidators.number(false)]],
virtual_interface_networks: [null],
// RGW, Ingress & iSCSI
ssl: [false],
[Validators.required, CdValidators.sslPrivKey()]
)
]
+ ],
+ // snmp-gateway
+ snmp_version: [
+ null,
+ [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ })
+ ]
+ ],
+ snmp_destination: [
+ null,
+ {
+ validators: [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ }),
+ CdValidators.custom('snmpDestinationPattern', (value: string) => {
+ if (_.isEmpty(value)) {
+ return false;
+ }
+ return !this.SNMP_DESTINATION_PATTERN.test(value);
+ })
+ ]
+ }
+ ],
+ engine_id: [
+ null,
+ [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ }),
+ CdValidators.custom('snmpEngineIdPattern', (value: string) => {
+ if (_.isEmpty(value)) {
+ return false;
+ }
+ return !this.SNMP_ENGINE_ID_PATTERN.test(value);
+ })
+ ]
+ ],
+ auth_protocol: [
+ 'SHA',
+ [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ })
+ ]
+ ],
+ privacy_protocol: [null],
+ snmp_community: [
+ null,
+ [
+ CdValidators.requiredIf({
+ snmp_version: 'V2c'
+ })
+ ]
+ ],
+ snmp_v3_auth_username: [
+ null,
+ [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ })
+ ]
+ ],
+ snmp_v3_auth_password: [
+ null,
+ [
+ CdValidators.requiredIf({
+ service_type: 'snmp-gateway'
+ })
+ ]
+ ],
+ snmp_v3_priv_password: [
+ null,
+ [
+ CdValidators.requiredIf({
+ privacy_protocol: { op: '!empty' }
+ })
+ ]
]
});
}
this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key);
}
break;
+ case 'snmp-gateway':
+ const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination'];
+ snmpCommonSpecKeys.forEach((key) => {
+ this.serviceForm.get(key).setValue(response[0].spec[key]);
+ });
+ if (this.serviceForm.getValue('snmp_version') === 'V3') {
+ const snmpV3SpecKeys = [
+ 'engine_id',
+ 'auth_protocol',
+ 'privacy_protocol',
+ 'snmp_v3_auth_username',
+ 'snmp_v3_auth_password',
+ 'snmp_v3_priv_password'
+ ];
+ snmpV3SpecKeys.forEach((key) => {
+ if (key !== null) {
+ if (
+ key === 'snmp_v3_auth_username' ||
+ key === 'snmp_v3_auth_password' ||
+ key === 'snmp_v3_priv_password'
+ ) {
+ this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]);
+ } else {
+ this.serviceForm.get(key).setValue(response[0].spec[key]);
+ }
+ }
+ });
+ } else {
+ this.serviceForm
+ .get('snmp_community')
+ .setValue(response[0].spec['credentials']['snmp_community']);
+ }
+ break;
}
});
}
}
serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks'];
break;
+ case 'snmp-gateway':
+ serviceSpec['credentials'] = {};
+ serviceSpec['snmp_version'] = values['snmp_version'];
+ serviceSpec['snmp_destination'] = values['snmp_destination'];
+ if (values['snmp_version'] === 'V3') {
+ serviceSpec['engine_id'] = values['engine_id'];
+ serviceSpec['auth_protocol'] = values['auth_protocol'];
+ serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username'];
+ serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password'];
+ if (values['privacy_protocol'] !== null) {
+ serviceSpec['privacy_protocol'] = values['privacy_protocol'];
+ serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password'];
+ }
+ } else {
+ serviceSpec['credentials']['snmp_community'] = values['snmp_community'];
+ }
+ break;
}
}
}
});
}
+
+ clearValidations() {
+ const snmpVersion = this.serviceForm.getValue('snmp_version');
+ const privacyProtocol = this.serviceForm.getValue('privacy_protocol');
+ if (snmpVersion === 'V3') {
+ this.serviceForm.get('snmp_community').clearValidators();
+ } else {
+ this.serviceForm.get('engine_id').clearValidators();
+ this.serviceForm.get('auth_protocol').clearValidators();
+ this.serviceForm.get('privacy_protocol').clearValidators();
+ this.serviceForm.get('snmp_v3_auth_username').clearValidators();
+ this.serviceForm.get('snmp_v3_auth_password').clearValidators();
+ }
+ if (privacyProtocol === null) {
+ this.serviceForm.get('snmp_v3_priv_password').clearValidators();
+ }
+ }
}