diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/compat/networks.go | 37 | ||||
-rw-r--r-- | pkg/domain/infra/abi/network.go | 2 |
2 files changed, 27 insertions, 12 deletions
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index 64ddebf9c..0158dad51 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -289,25 +289,40 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) { func RemoveNetwork(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - config, err := runtime.GetConfig() - if err != nil { - utils.InternalServerError(w, err) + ic := abi.ContainerEngine{Libpod: runtime} + + query := struct { + Force bool `schema:"force"` + }{ + // This is where you can override the golang default value for one of fields + } + + decoder := r.Context().Value("decoder").(*schema.Decoder) + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String())) return } + + options := entities.NetworkRmOptions{ + Force: query.Force, + } + name := utils.GetName(r) - exists, err := network.Exists(config, name) + reports, err := ic.NetworkRm(r.Context(), []string{name}, options) if err != nil { - utils.InternalServerError(w, err) - return - } - if !exists { - utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork) + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "remove Network create")) return } - if err := network.RemoveNetwork(config, name); err != nil { - utils.InternalServerError(w, err) + report := reports[0] + if report.Err != nil { + if errors.Cause(report.Err) == define.ErrNoSuchNetwork { + utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork) + return + } + utils.InternalServerError(w, report.Err) return } + utils.WriteResponse(w, http.StatusNoContent, "") } diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go index 06941f8d0..b7f90a034 100644 --- a/pkg/domain/infra/abi/network.go +++ b/pkg/domain/infra/abi/network.go @@ -96,7 +96,7 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o if err := ic.Libpod.RemovePod(ctx, pod, true, true); err != nil { return reports, err } - } else if err := ic.Libpod.RemoveContainer(ctx, c, true, true); err != nil { + } else if err := ic.Libpod.RemoveContainer(ctx, c, true, true); err != nil && errors.Cause(err) != define.ErrNoSuchCtr { return reports, err } } |