]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts
import quincy beta 17.1.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / service-form / service-form.component.ts
index 6db898f0aa847cf4c350085703a031e913a84b10..ac4eec308f87971fdd01218fba95b2564cff78e4 100644 (file)
@@ -28,6 +28,8 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
 })
 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;
 
@@ -120,7 +122,7 @@ export class ServiceFormComponent extends CdForm implements OnInit {
         ]
       ],
       hosts: [[]],
-      count: [null, [CdValidators.number(false), Validators.min(1)]],
+      count: [null, [CdValidators.number(false)]],
       unmanaged: [false],
       // iSCSI
       pool: [
@@ -133,13 +135,10 @@ export class ServiceFormComponent extends CdForm implements OnInit {
         ]
       ],
       // 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,
         [
@@ -177,8 +176,8 @@ export class ServiceFormComponent extends CdForm implements OnInit {
           })
         ]
       ],
-      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],
@@ -215,6 +214,86 @@ export class ServiceFormComponent extends CdForm implements OnInit {
             [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' }
+          })
+        ]
       ]
     });
   }
@@ -317,6 +396,39 @@ export class ServiceFormComponent extends CdForm implements OnInit {
               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;
         }
       });
     }
@@ -456,6 +568,23 @@ export class ServiceFormComponent extends CdForm implements OnInit {
           }
           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;
       }
     }
 
@@ -477,4 +606,21 @@ export class ServiceFormComponent extends CdForm implements OnInit {
         }
       });
   }
+
+  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();
+    }
+  }
 }