mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Merge pull request #9710 from jmguzik/network-prune-filters-http-api
Network prune filters for http api (compat and libpod)
This commit is contained in:
@ -400,10 +400,24 @@ func Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Prune removes unused networks
|
||||
func Prune(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO Filters are not implemented
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
filters, err := filtersFromRequest(r)
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
|
||||
return
|
||||
}
|
||||
filterMap := map[string][]string{}
|
||||
for _, filter := range filters {
|
||||
split := strings.SplitN(filter, "=", 2)
|
||||
if len(split) > 1 {
|
||||
filterMap[split[0]] = append(filterMap[split[0]], split[1])
|
||||
}
|
||||
}
|
||||
|
||||
ic := abi.ContainerEngine{Libpod: runtime}
|
||||
pruneOptions := entities.NetworkPruneOptions{}
|
||||
pruneOptions := entities.NetworkPruneOptions{
|
||||
Filters: filterMap,
|
||||
}
|
||||
pruneReports, err := ic.NetworkPrune(r.Context(), pruneOptions)
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
||||
|
@ -177,10 +177,23 @@ func ExistsNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Prune removes unused networks
|
||||
func Prune(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO Filters are not implemented
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
query := struct {
|
||||
Filters map[string][]string `schema:"filters"`
|
||||
}{
|
||||
// override any golang type defaults
|
||||
}
|
||||
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
pruneOptions := entities.NetworkPruneOptions{
|
||||
Filters: query.Filters,
|
||||
}
|
||||
ic := abi.ContainerEngine{Libpod: runtime}
|
||||
pruneOptions := entities.NetworkPruneOptions{}
|
||||
pruneReports, err := ic.NetworkPrune(r.Context(), pruneOptions)
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
|
||||
|
@ -172,7 +172,6 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
|
||||
// name: filters
|
||||
// type: string
|
||||
// description: |
|
||||
// NOT IMPLEMENTED
|
||||
// Filters to process on the prune list, encoded as JSON (a map[string][]string).
|
||||
// Available filters:
|
||||
// - until=<timestamp> Prune networks created before this timestamp. The <timestamp> can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the daemon machine’s time.
|
||||
|
Reference in New Issue
Block a user