mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fc214b4408
build: implement --label Signed-off-by: Evan Hazlett <ejhazlett@gmail.com> network: allow adding labels on create Signed-off-by: Evan Hazlett <ejhazlett@gmail.com> volume: allow adding labels on create Signed-off-by: Evan Hazlett <ejhazlett@gmail.com> add tests for build, network, volume Signed-off-by: Evan Hazlett <ejhazlett@gmail.com> vendor: libnetwork and engine-api bump Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package volume
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/docker/docker/api/server/httputils"
|
|
"github.com/docker/engine-api/types"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
volumes, warnings, err := v.backend.Volumes(r.Form.Get("filters"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return httputils.WriteJSON(w, http.StatusOK, &types.VolumesListResponse{Volumes: volumes, Warnings: warnings})
|
|
}
|
|
|
|
func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
volume, err := v.backend.VolumeInspect(vars["name"])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return httputils.WriteJSON(w, http.StatusOK, volume)
|
|
}
|
|
|
|
func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := httputils.CheckForJSON(r); err != nil {
|
|
return err
|
|
}
|
|
|
|
var req types.VolumeCreateRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return err
|
|
}
|
|
|
|
volume, err := v.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts, req.Labels)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return httputils.WriteJSON(w, http.StatusCreated, volume)
|
|
}
|
|
|
|
func (v *volumeRouter) deleteVolumes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
if err := httputils.ParseForm(r); err != nil {
|
|
return err
|
|
}
|
|
if err := v.backend.VolumeRm(vars["name"]); err != nil {
|
|
return err
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
return nil
|
|
}
|