Skip to content

Commit

Permalink
Delete Switch status along with switch (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar authored Nov 18, 2024
1 parent 59690db commit 3c22c0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/metal-api/internal/datastore/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,8 @@ func (rs *RethinkStore) GetSwitchStatus(id string) (*metal.SwitchStatus, error)
func (rs *RethinkStore) SetSwitchStatus(state *metal.SwitchStatus) error {
return rs.upsertEntity(rs.switchStatusTable(), state)
}

// DeleteSwitchStatus delete SwitchStatus
func (rs *RethinkStore) DeleteSwitchStatus(status *metal.SwitchStatus) error {
return rs.deleteEntity(rs.switchStatusTable(), status)
}
12 changes: 12 additions & 0 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ func (r *switchResource) deleteSwitch(request *restful.Request, response *restfu
return
}

status, err := r.ds.GetSwitchStatus(id)
if err == nil {
err = r.ds.DeleteSwitchStatus(status)
if err != nil {
r.sendError(request, response, defaultError(err))
return
}
} else if !metal.IsNotFound(err) {
r.sendError(request, response, defaultError(err))
return
}

resp, err := r.makeSwitchResponse(s)
if err != nil {
r.sendError(request, response, defaultError(err))
Expand Down

0 comments on commit 3c22c0d

Please sign in to comment.