Skip to content

Commit

Permalink
add switch os vendor validation
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Oct 17, 2024
1 parent 1dc69c4 commit e00903b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/metal-api/internal/metal/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func SwitchModeFrom(name string) SwitchMode {
}
}

func ValidateSwitchOSVendor(os SwitchOSVendor) error {
if os != SwitchOSVendorCumulus && os != SwitchOSVendorSonic {
return fmt.Errorf("unknown switch os vendor %s", os)
}
return nil
}

// ByNicName builds a map of nic names to machine connection
func (c ConnectionMap) ByNicName() (map[string]Connection, error) {
res := make(map[string]Connection)
Expand Down
10 changes: 10 additions & 0 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ func (r *switchResource) registerSwitch(request *restful.Request, response *rest
return
}

if err := metal.ValidateSwitchOSVendor(s.OS.Vendor); err != nil {
r.sendError(request, response, defaultError(err))
return
}

returnCode := http.StatusOK
if s == nil {
s = v1.NewSwitch(requestPayload)
Expand Down Expand Up @@ -601,6 +606,11 @@ func (r *switchResource) migrate(request *restful.Request, response *restful.Res
return
}

if err := metal.ValidateSwitchOSVendor(new.OS.Vendor); err != nil {
r.sendError(request, response, defaultError(err))
return
}

if old.RackID != new.RackID {
r.sendError(request, response, httperrors.BadRequest(fmt.Errorf("new switch must be in the same rack as the old one")))
return
Expand Down

0 comments on commit e00903b

Please sign in to comment.