From 3c22c0d0061c692ae253b64567f936ea03d68824 Mon Sep 17 00:00:00 2001 From: Ilja Rotar <77339620+iljarotar@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:47:49 +0100 Subject: [PATCH] Delete Switch status along with switch (#591) --- cmd/metal-api/internal/datastore/switch.go | 5 +++++ cmd/metal-api/internal/service/switch-service.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cmd/metal-api/internal/datastore/switch.go b/cmd/metal-api/internal/datastore/switch.go index 8d6e8215..4a54d051 100644 --- a/cmd/metal-api/internal/datastore/switch.go +++ b/cmd/metal-api/internal/datastore/switch.go @@ -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) +} diff --git a/cmd/metal-api/internal/service/switch-service.go b/cmd/metal-api/internal/service/switch-service.go index 2ef392ce..88a9d433 100644 --- a/cmd/metal-api/internal/service/switch-service.go +++ b/cmd/metal-api/internal/service/switch-service.go @@ -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))