Skip to content

Commit

Permalink
fix os vendor checks
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Oct 17, 2024
1 parent e00903b commit 30a347d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,6 @@ 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 All @@ -493,6 +488,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
}

err = r.ds.CreateSwitch(s)
if err != nil {
r.sendError(request, response, defaultError(err))
Expand All @@ -502,6 +502,12 @@ func (r *switchResource) registerSwitch(request *restful.Request, response *rest
returnCode = http.StatusCreated
} else if s.Mode == metal.SwitchReplace {
spec := v1.NewSwitch(requestPayload)

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

err = r.replaceSwitch(s, spec)
if err != nil {
r.sendError(request, response, defaultError(err))
Expand All @@ -513,6 +519,11 @@ func (r *switchResource) registerSwitch(request *restful.Request, response *rest
old := *s
spec := v1.NewSwitch(requestPayload)

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

uniqueNewNics := spec.Nics.ByIdentifier()
if len(requestPayload.Nics) != len(uniqueNewNics) {
r.sendError(request, response, httperrors.BadRequest(errors.New("duplicate identifier found in nics")))
Expand Down

0 comments on commit 30a347d

Please sign in to comment.