diff --git a/pkg/networkdevice/profile/profiledefinition/validation.go b/pkg/networkdevice/profile/profiledefinition/validation.go index 99f80769aa1f4..21e55dfb67329 100644 --- a/pkg/networkdevice/profile/profiledefinition/validation.go +++ b/pkg/networkdevice/profile/profiledefinition/validation.go @@ -47,6 +47,32 @@ const ( MetadataSymbol ) +// ValidateEnrichProfile validates a profile and normalizes it. +func ValidateEnrichProfile(profile *ProfileDefinition) []string { + NormalizeMetrics(profile.Metrics) + // migrate legacy profile.Device.Vendor to metadata field. + if profile.Device.Vendor != "" { + dev, ok := profile.Metadata["device"] + if !ok { + profile.Metadata["device"] = MetadataResourceConfig{ + Fields: make(map[string]MetadataField), + } + dev = profile.Metadata["device"] + } + _, ok = dev.Fields["vendor"] + if !ok { + dev.Fields["vendor"] = MetadataField{ + Value: profile.Device.Vendor, + } + } + profile.Device.Vendor = "" + } + errors := ValidateEnrichMetadata(profile.Metadata) + errors = append(errors, ValidateEnrichMetrics(profile.Metrics)...) + errors = append(errors, ValidateEnrichMetricTags(profile.MetricTags)...) + return errors +} + // ValidateEnrichMetricTags validates and normalizes metric tags func ValidateEnrichMetricTags(metricTags []MetricTagConfig) []string { var errors []string