mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-12 20:27:48 +00:00
``` gvt delete github.com/fsouza/go-dockerclient gvt delete github.com/docker/docker/opts gvt delete github.com/docker/docker/pkg/archive gvt delete github.com/docker/docker/pkg/fileutils gvt delete github.com/docker/docker/pkg/homedir gvt delete github.com/docker/docker/pkg/idtools gvt delete github.com/docker/docker/pkg/ioutils gvt delete github.com/docker/docker/pkg/longpath gvt delete github.com/docker/docker/pkg/mflag gvt delete github.com/docker/docker/pkg/mount gvt delete github.com/docker/docker/pkg/parsers gvt delete github.com/docker/docker/pkg/pools gvt delete github.com/docker/docker/pkg/promise gvt delete github.com/docker/docker/pkg/stdcopy gvt delete github.com/docker/docker/pkg/system gvt delete github.com/docker/docker/pkg/term gvt delete github.com/docker/docker/pkg/units gvt delete github.com/docker/libcontainer/cgroups gvt delete github.com/docker/distribution/digest gvt delete github.com/docker/distribution/reference gvt delete github.com/docker/distribution/vendor/github.com/stevvooe/resumable gvt fetch --tag 1.2.0 github.com/fsouza/go-dockerclient 2018/07/23 17:03:36 Fetching: github.com/fsouza/go-dockerclient 2018/07/23 17:03:39 · Skipping (existing): github.com/docker/go-units 2018/07/23 17:03:39 · Fetching recursive dependency: github.com/docker/docker/pkg/jsonmessage 2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Nvveen/Gotty 2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-units 2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/pkg/term 2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Azure/go-ansiterm 2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/sirupsen/logrus 2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/unix 2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/crypto/ssh/terminal 2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/sys/windows 2018/07/23 17:03:51 · Skipping (existing): github.com/gorilla/mux 2018/07/23 17:03:51 · Fetching recursive dependency: github.com/docker/docker/api/types/swarm 2018/07/23 17:03:51 ·· Fetching recursive dependency: github.com/docker/docker/api/types/network 2018/07/23 17:03:51 ··· Fetching recursive dependency: github.com/docker/docker/api/types/filters 2018/07/23 17:03:51 ···· Fetching recursive dependency: github.com/docker/docker/api/types/versions 2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/go-connections/nat 2018/07/23 17:03:51 ····· Fetching recursive dependency: github.com/docker/docker/api/types 2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/errdefs 2018/07/23 17:03:51 ······ Fetching recursive dependency: github.com/docker/docker/pkg/streamformatter 2018/07/23 17:03:51 ······· Fetching recursive dependency: github.com/docker/docker/pkg/progress 2018/07/23 17:03:51 ········ Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/time/rate 2018/07/23 17:03:51 ········· Fetching recursive dependency: github.com/docker/docker/vendor/golang.org/x/net/context 2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/gogo/protobuf/proto 2018/07/23 17:03:52 ······ Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go/v1 2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/go-digest 2018/07/23 17:03:52 ······· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/image-spec/specs-go 2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/homedir 2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/idtools 2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/system 2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/pkg/errors 2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/Microsoft/go-winio 2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/containerd/continuity/pathdriver 2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/mount 2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/user 2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/stdcopy 2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/pkg/archive 2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/pools 2018/07/23 17:03:52 ··· Fetching recursive dependency: github.com/docker/docker/pkg/ioutils 2018/07/23 17:03:52 ···· Fetching recursive dependency: github.com/docker/docker/pkg/longpath 2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/opencontainers/runc/libcontainer/system 2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/pkg/fileutils 2018/07/23 17:03:52 ·· Fetching recursive dependency: github.com/docker/docker/vendor/archive/tar 2018/07/23 17:03:52 · Skipping (existing): golang.org/x/net/context 2018/07/23 17:03:52 · Fetching recursive dependency: github.com/docker/docker/opts 2018/07/23 17:03:53 ·· Fetching recursive dependency: github.com/docker/docker/vendor/github.com/docker/libnetwork/ipamutils 2018/07/23 17:03:53 · Skipping (existing): golang.org/x/net/context/ctxhttp 2018/07/23 17:03:53 · Fetching recursive dependency: github.com/Microsoft/go-winio 2018/07/23 17:03:55 ·· Fetching recursive dependency: golang.org/x/sys/windows ```
172 lines
4.6 KiB
Go
172 lines
4.6 KiB
Go
// Copyright 2015 go-dockerclient authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package docker
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
var (
|
|
// ErrNoSuchVolume is the error returned when the volume does not exist.
|
|
ErrNoSuchVolume = errors.New("no such volume")
|
|
|
|
// ErrVolumeInUse is the error returned when the volume requested to be removed is still in use.
|
|
ErrVolumeInUse = errors.New("volume in use and cannot be removed")
|
|
)
|
|
|
|
// Volume represents a volume.
|
|
//
|
|
// See https://goo.gl/FZA4BK for more details.
|
|
type Volume struct {
|
|
Name string `json:"Name" yaml:"Name" toml:"Name"`
|
|
Driver string `json:"Driver,omitempty" yaml:"Driver,omitempty" toml:"Driver,omitempty"`
|
|
Mountpoint string `json:"Mountpoint,omitempty" yaml:"Mountpoint,omitempty" toml:"Mountpoint,omitempty"`
|
|
Labels map[string]string `json:"Labels,omitempty" yaml:"Labels,omitempty" toml:"Labels,omitempty"`
|
|
}
|
|
|
|
// ListVolumesOptions specify parameters to the ListVolumes function.
|
|
//
|
|
// See https://goo.gl/FZA4BK for more details.
|
|
type ListVolumesOptions struct {
|
|
Filters map[string][]string
|
|
Context context.Context
|
|
}
|
|
|
|
// ListVolumes returns a list of available volumes in the server.
|
|
//
|
|
// See https://goo.gl/FZA4BK for more details.
|
|
func (c *Client) ListVolumes(opts ListVolumesOptions) ([]Volume, error) {
|
|
resp, err := c.do("GET", "/volumes?"+queryString(opts), doOptions{
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
m := make(map[string]interface{})
|
|
if err = json.NewDecoder(resp.Body).Decode(&m); err != nil {
|
|
return nil, err
|
|
}
|
|
var volumes []Volume
|
|
volumesJSON, ok := m["Volumes"]
|
|
if !ok {
|
|
return volumes, nil
|
|
}
|
|
data, err := json.Marshal(volumesJSON)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := json.Unmarshal(data, &volumes); err != nil {
|
|
return nil, err
|
|
}
|
|
return volumes, nil
|
|
}
|
|
|
|
// CreateVolumeOptions specify parameters to the CreateVolume function.
|
|
//
|
|
// See https://goo.gl/pBUbZ9 for more details.
|
|
type CreateVolumeOptions struct {
|
|
Name string
|
|
Driver string
|
|
DriverOpts map[string]string
|
|
Context context.Context `json:"-"`
|
|
Labels map[string]string
|
|
}
|
|
|
|
// CreateVolume creates a volume on the server.
|
|
//
|
|
// See https://goo.gl/pBUbZ9 for more details.
|
|
func (c *Client) CreateVolume(opts CreateVolumeOptions) (*Volume, error) {
|
|
resp, err := c.do("POST", "/volumes/create", doOptions{
|
|
data: opts,
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
var volume Volume
|
|
if err := json.NewDecoder(resp.Body).Decode(&volume); err != nil {
|
|
return nil, err
|
|
}
|
|
return &volume, nil
|
|
}
|
|
|
|
// InspectVolume returns a volume by its name.
|
|
//
|
|
// See https://goo.gl/0g9A6i for more details.
|
|
func (c *Client) InspectVolume(name string) (*Volume, error) {
|
|
resp, err := c.do("GET", "/volumes/"+name, doOptions{})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
|
|
return nil, ErrNoSuchVolume
|
|
}
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
var volume Volume
|
|
if err := json.NewDecoder(resp.Body).Decode(&volume); err != nil {
|
|
return nil, err
|
|
}
|
|
return &volume, nil
|
|
}
|
|
|
|
// RemoveVolume removes a volume by its name.
|
|
//
|
|
// See https://goo.gl/79GNQz for more details.
|
|
func (c *Client) RemoveVolume(name string) error {
|
|
resp, err := c.do("DELETE", "/volumes/"+name, doOptions{})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok {
|
|
if e.Status == http.StatusNotFound {
|
|
return ErrNoSuchVolume
|
|
}
|
|
if e.Status == http.StatusConflict {
|
|
return ErrVolumeInUse
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
return nil
|
|
}
|
|
|
|
// PruneVolumesOptions specify parameters to the PruneVolumes function.
|
|
//
|
|
// See https://goo.gl/pFN1Hj for more details.
|
|
type PruneVolumesOptions struct {
|
|
Filters map[string][]string
|
|
Context context.Context
|
|
}
|
|
|
|
// PruneVolumesResults specify results from the PruneVolumes function.
|
|
//
|
|
// See https://goo.gl/pFN1Hj for more details.
|
|
type PruneVolumesResults struct {
|
|
VolumesDeleted []string
|
|
SpaceReclaimed int64
|
|
}
|
|
|
|
// PruneVolumes deletes volumes which are unused.
|
|
//
|
|
// See https://goo.gl/pFN1Hj for more details.
|
|
func (c *Client) PruneVolumes(opts PruneVolumesOptions) (*PruneVolumesResults, error) {
|
|
path := "/volumes/prune?" + queryString(opts)
|
|
resp, err := c.do("POST", path, doOptions{context: opts.Context})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
var results PruneVolumesResults
|
|
if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
|
|
return nil, err
|
|
}
|
|
return &results, nil
|
|
}
|