mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-17 20:41:51 +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 ```
157 lines
4.5 KiB
Go
157 lines
4.5 KiB
Go
// Copyright 2016 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"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
var (
|
|
// ErrNodeAlreadyInSwarm is the error returned by InitSwarm and JoinSwarm
|
|
// when the node is already part of a Swarm.
|
|
ErrNodeAlreadyInSwarm = errors.New("node already in a Swarm")
|
|
|
|
// ErrNodeNotInSwarm is the error returned by LeaveSwarm and UpdateSwarm
|
|
// when the node is not part of a Swarm.
|
|
ErrNodeNotInSwarm = errors.New("node is not in a Swarm")
|
|
)
|
|
|
|
// InitSwarmOptions specify parameters to the InitSwarm function.
|
|
// See https://goo.gl/hzkgWu for more details.
|
|
type InitSwarmOptions struct {
|
|
swarm.InitRequest
|
|
Context context.Context
|
|
}
|
|
|
|
// InitSwarm initializes a new Swarm and returns the node ID.
|
|
// See https://goo.gl/ZWyG1M for more details.
|
|
func (c *Client) InitSwarm(opts InitSwarmOptions) (string, error) {
|
|
path := "/swarm/init"
|
|
resp, err := c.do("POST", path, doOptions{
|
|
data: opts.InitRequest,
|
|
forceJSON: true,
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && (e.Status == http.StatusNotAcceptable || e.Status == http.StatusServiceUnavailable) {
|
|
return "", ErrNodeAlreadyInSwarm
|
|
}
|
|
return "", err
|
|
}
|
|
defer resp.Body.Close()
|
|
var response string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return "", err
|
|
}
|
|
return response, nil
|
|
}
|
|
|
|
// JoinSwarmOptions specify parameters to the JoinSwarm function.
|
|
// See https://goo.gl/TdhJWU for more details.
|
|
type JoinSwarmOptions struct {
|
|
swarm.JoinRequest
|
|
Context context.Context
|
|
}
|
|
|
|
// JoinSwarm joins an existing Swarm.
|
|
// See https://goo.gl/N59IP1 for more details.
|
|
func (c *Client) JoinSwarm(opts JoinSwarmOptions) error {
|
|
path := "/swarm/join"
|
|
resp, err := c.do("POST", path, doOptions{
|
|
data: opts.JoinRequest,
|
|
forceJSON: true,
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && (e.Status == http.StatusNotAcceptable || e.Status == http.StatusServiceUnavailable) {
|
|
return ErrNodeAlreadyInSwarm
|
|
}
|
|
}
|
|
resp.Body.Close()
|
|
return err
|
|
}
|
|
|
|
// LeaveSwarmOptions specify parameters to the LeaveSwarm function.
|
|
// See https://goo.gl/UWDlLg for more details.
|
|
type LeaveSwarmOptions struct {
|
|
Force bool
|
|
Context context.Context
|
|
}
|
|
|
|
// LeaveSwarm leaves a Swarm.
|
|
// See https://goo.gl/FTX1aD for more details.
|
|
func (c *Client) LeaveSwarm(opts LeaveSwarmOptions) error {
|
|
params := make(url.Values)
|
|
params.Set("force", strconv.FormatBool(opts.Force))
|
|
path := "/swarm/leave?" + params.Encode()
|
|
resp, err := c.do("POST", path, doOptions{
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && (e.Status == http.StatusNotAcceptable || e.Status == http.StatusServiceUnavailable) {
|
|
return ErrNodeNotInSwarm
|
|
}
|
|
}
|
|
resp.Body.Close()
|
|
return err
|
|
}
|
|
|
|
// UpdateSwarmOptions specify parameters to the UpdateSwarm function.
|
|
// See https://goo.gl/vFbq36 for more details.
|
|
type UpdateSwarmOptions struct {
|
|
Version int
|
|
RotateWorkerToken bool
|
|
RotateManagerToken bool
|
|
Swarm swarm.Spec
|
|
Context context.Context
|
|
}
|
|
|
|
// UpdateSwarm updates a Swarm.
|
|
// See https://goo.gl/iJFnsw for more details.
|
|
func (c *Client) UpdateSwarm(opts UpdateSwarmOptions) error {
|
|
params := make(url.Values)
|
|
params.Set("version", strconv.Itoa(opts.Version))
|
|
params.Set("rotateWorkerToken", strconv.FormatBool(opts.RotateWorkerToken))
|
|
params.Set("rotateManagerToken", strconv.FormatBool(opts.RotateManagerToken))
|
|
path := "/swarm/update?" + params.Encode()
|
|
resp, err := c.do("POST", path, doOptions{
|
|
data: opts.Swarm,
|
|
forceJSON: true,
|
|
context: opts.Context,
|
|
})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && (e.Status == http.StatusNotAcceptable || e.Status == http.StatusServiceUnavailable) {
|
|
return ErrNodeNotInSwarm
|
|
}
|
|
}
|
|
resp.Body.Close()
|
|
return err
|
|
}
|
|
|
|
// InspectSwarm inspects a Swarm.
|
|
// See https://goo.gl/MFwgX9 for more details.
|
|
func (c *Client) InspectSwarm(ctx context.Context) (swarm.Swarm, error) {
|
|
response := swarm.Swarm{}
|
|
resp, err := c.do("GET", "/swarm", doOptions{
|
|
context: ctx,
|
|
})
|
|
if err != nil {
|
|
if e, ok := err.(*Error); ok && (e.Status == http.StatusNotAcceptable || e.Status == http.StatusServiceUnavailable) {
|
|
return response, ErrNodeNotInSwarm
|
|
}
|
|
return response, err
|
|
}
|
|
defer resp.Body.Close()
|
|
err = json.NewDecoder(resp.Body).Decode(&response)
|
|
return response, err
|
|
}
|