_validation.tpl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. {{/* External Interface Validation */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.externalInterface.validation" (dict "objectData" $objectData) -}}
  4. objectData: The object data to validate that contains the external interface configuratioon.
  5. */}}
  6. {{- define "ix.v1.common.lib.externalInterface.validation" -}}
  7. {{- $objectData := .objectData -}}
  8. {{- if and $objectData.targetSelector (not (kindIs "slice" $objectData.targetSelector)) -}}
  9. {{- fail (printf "External Interface - Expected <targetSelector> to be a [list], but got [%s]" (kindOf $objectData.targetSelector)) -}}
  10. {{- end -}}
  11. {{- if not $objectData.hostInterface -}}
  12. {{- fail "External Interface - Expected non-empty <hostInterface>" -}}
  13. {{- end -}}
  14. {{- if not $objectData.ipam -}}
  15. {{- fail "External Interface - Expected non-empty <ipam>" -}}
  16. {{- end -}}
  17. {{- if not $objectData.ipam.type -}}
  18. {{- fail "External Interface - Expected non-empty <ipam.type>" -}}
  19. {{- end -}}
  20. {{- $types := (list "dhcp" "static") -}}
  21. {{- if not (mustHas $objectData.ipam.type $types) -}}
  22. {{- fail (printf "External Interface - Expected <ipam.type> to be one of [%s], but got [%s]" (join ", " $types) $objectData.ipam.type) -}}
  23. {{- end -}}
  24. {{- if and (or $objectData.staticIPConfigurations $objectData.staticRoutes) (ne $objectData.ipam.type "static") -}}
  25. {{- fail "External Interface - Expected empty <staticIPConfigurations> and <staticRoutes> when <ipam.type> is not [static]" -}}
  26. {{- end -}}
  27. {{- if eq $objectData.ipam.type "static" -}}
  28. {{- if not $objectData.staticIPConfigurations -}}
  29. {{- fail "External Interface - Expected non-empty <staticIPConfigurations> when <ipam.type> is [static]" -}}
  30. {{- end -}}
  31. {{- with $objectData.staticRoutes -}}
  32. {{- range . -}}
  33. {{- if not .destination -}}
  34. {{- fail "External Interface - Expected non-empty <destination> in <staticRoutes>" -}}
  35. {{- end -}}
  36. {{- if not .gateway -}}
  37. {{- fail "External Interface - Expected non-empty <gateway> in <staticRoutes>" -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{- end -}}
  41. {{- end -}}
  42. {{- end -}}