Upgrade go-dockerclient dependency to support CgroupParent

This commit is contained in:
Tobi Knaup
2015-04-23 20:46:45 +00:00
parent f7831dcd93
commit 522d4c3b85
14 changed files with 329 additions and 123 deletions

View File

@@ -56,7 +56,7 @@ type APIContainers struct {
// See http://goo.gl/6Y4Gz7 for more details.
func (c *Client) ListContainers(opts ListContainersOptions) ([]APIContainers, error) {
path := "/containers/json?" + queryString(opts)
body, _, err := c.do("GET", path, nil, false)
body, _, err := c.do("GET", path, doOptions{})
if err != nil {
return nil, err
}
@@ -90,6 +90,7 @@ func (p Port) Proto() string {
type State struct {
Running bool `json:"Running,omitempty" yaml:"Running,omitempty"`
Paused bool `json:"Paused,omitempty" yaml:"Paused,omitempty"`
Restarting bool `json:"Restarting,omitempty" yaml:"Restarting,omitempty"`
OOMKilled bool `json:"OOMKilled,omitempty" yaml:"OOMKilled,omitempty"`
Pid int `json:"Pid,omitempty" yaml:"Pid,omitempty"`
ExitCode int `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty"`
@@ -263,7 +264,7 @@ type RenameContainerOptions struct {
//
// See http://goo.gl/L00hoj for more details.
func (c *Client) RenameContainer(opts RenameContainerOptions) error {
_, _, err := c.do("POST", fmt.Sprintf("/containers/"+opts.ID+"/rename?%s", queryString(opts)), nil, false)
_, _, err := c.do("POST", fmt.Sprintf("/containers/"+opts.ID+"/rename?%s", queryString(opts)), doOptions{})
return err
}
@@ -272,7 +273,7 @@ func (c *Client) RenameContainer(opts RenameContainerOptions) error {
// See http://goo.gl/CxVuJ5 for more details.
func (c *Client) InspectContainer(id string) (*Container, error) {
path := "/containers/" + id + "/json"
body, status, err := c.do("GET", path, nil, false)
body, status, err := c.do("GET", path, doOptions{})
if status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: id}
}
@@ -292,7 +293,7 @@ func (c *Client) InspectContainer(id string) (*Container, error) {
// See http://goo.gl/QkW9sH for more details.
func (c *Client) ContainerChanges(id string) ([]Change, error) {
path := "/containers/" + id + "/changes"
body, status, err := c.do("GET", path, nil, false)
body, status, err := c.do("GET", path, doOptions{})
if status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: id}
}
@@ -322,13 +323,19 @@ type CreateContainerOptions struct {
// See http://goo.gl/mErxNp for more details.
func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error) {
path := "/containers/create?" + queryString(opts)
body, status, err := c.do("POST", path, struct {
*Config
HostConfig *HostConfig `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty"`
}{
opts.Config,
opts.HostConfig,
}, false)
body, status, err := c.do(
"POST",
path,
doOptions{
data: struct {
*Config
HostConfig *HostConfig `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty"`
}{
opts.Config,
opts.HostConfig,
},
},
)
if status == http.StatusNotFound {
return nil, ErrNoSuchImage
@@ -417,6 +424,7 @@ type HostConfig struct {
LogConfig LogConfig `json:"LogConfig,omitempty" yaml:"LogConfig,omitempty"`
ReadonlyRootfs bool `json:"ReadonlyRootfs,omitempty" yaml:"ReadonlyRootfs,omitempty"`
SecurityOpt []string `json:"SecurityOpt,omitempty" yaml:"SecurityOpt,omitempty"`
CgroupParent string `json:"CgroupParent,omitempty" yaml:"CgroupParent,omitempty"`
}
// StartContainer starts a container, returning an error in case of failure.
@@ -424,7 +432,7 @@ type HostConfig struct {
// See http://goo.gl/iM5GYs for more details.
func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
path := "/containers/" + id + "/start"
_, status, err := c.do("POST", path, hostConfig, true)
_, status, err := c.do("POST", path, doOptions{data: hostConfig, forceJSON: true})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id, Err: err}
}
@@ -443,7 +451,7 @@ func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
// See http://goo.gl/EbcpXt for more details.
func (c *Client) StopContainer(id string, timeout uint) error {
path := fmt.Sprintf("/containers/%s/stop?t=%d", id, timeout)
_, status, err := c.do("POST", path, nil, false)
_, status, err := c.do("POST", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
@@ -462,7 +470,7 @@ func (c *Client) StopContainer(id string, timeout uint) error {
// See http://goo.gl/VOzR2n for more details.
func (c *Client) RestartContainer(id string, timeout uint) error {
path := fmt.Sprintf("/containers/%s/restart?t=%d", id, timeout)
_, status, err := c.do("POST", path, nil, false)
_, status, err := c.do("POST", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
@@ -477,7 +485,7 @@ func (c *Client) RestartContainer(id string, timeout uint) error {
// See http://goo.gl/AM5t42 for more details.
func (c *Client) PauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/pause", id)
_, status, err := c.do("POST", path, nil, false)
_, status, err := c.do("POST", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
@@ -492,7 +500,7 @@ func (c *Client) PauseContainer(id string) error {
// See http://goo.gl/eBrNSL for more details.
func (c *Client) UnpauseContainer(id string) error {
path := fmt.Sprintf("/containers/%s/unpause", id)
_, status, err := c.do("POST", path, nil, false)
_, status, err := c.do("POST", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: id}
}
@@ -521,7 +529,7 @@ func (c *Client) TopContainer(id string, psArgs string) (TopResult, error) {
args = fmt.Sprintf("?ps_args=%s", psArgs)
}
path := fmt.Sprintf("/containers/%s/top%s", id, args)
body, status, err := c.do("GET", path, nil, false)
body, status, err := c.do("GET", path, doOptions{})
if status == http.StatusNotFound {
return result, &NoSuchContainer{ID: id}
}
@@ -553,7 +561,7 @@ type KillContainerOptions struct {
// See http://goo.gl/TFkECx for more details.
func (c *Client) KillContainer(opts KillContainerOptions) error {
path := "/containers/" + opts.ID + "/kill" + "?" + queryString(opts)
_, status, err := c.do("POST", path, nil, false)
_, status, err := c.do("POST", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.ID}
}
@@ -584,7 +592,7 @@ type RemoveContainerOptions struct {
// See http://goo.gl/ZB83ji for more details.
func (c *Client) RemoveContainer(opts RemoveContainerOptions) error {
path := "/containers/" + opts.ID + "?" + queryString(opts)
_, status, err := c.do("DELETE", path, nil, false)
_, status, err := c.do("DELETE", path, doOptions{})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.ID}
}
@@ -613,7 +621,7 @@ func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error {
return &NoSuchContainer{ID: opts.Container}
}
url := fmt.Sprintf("/containers/%s/copy", opts.Container)
body, status, err := c.do("POST", url, opts, false)
body, status, err := c.do("POST", url, doOptions{data: opts})
if status == http.StatusNotFound {
return &NoSuchContainer{ID: opts.Container}
}
@@ -629,7 +637,7 @@ func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error {
//
// See http://goo.gl/J88DHU for more details.
func (c *Client) WaitContainer(id string) (int, error) {
body, status, err := c.do("POST", "/containers/"+id+"/wait", nil, false)
body, status, err := c.do("POST", "/containers/"+id+"/wait", doOptions{})
if status == http.StatusNotFound {
return 0, &NoSuchContainer{ID: id}
}
@@ -661,7 +669,7 @@ type CommitContainerOptions struct {
// See http://goo.gl/Jn8pe8 for more details.
func (c *Client) CommitContainer(opts CommitContainerOptions) (*Image, error) {
path := "/commit?" + queryString(opts)
body, status, err := c.do("POST", path, opts.Run, false)
body, status, err := c.do("POST", path, doOptions{data: opts.Run})
if status == http.StatusNotFound {
return nil, &NoSuchContainer{ID: opts.Container}
}
@@ -720,7 +728,13 @@ func (c *Client) AttachToContainer(opts AttachToContainerOptions) error {
return &NoSuchContainer{ID: opts.Container}
}
path := "/containers/" + opts.Container + "/attach?" + queryString(opts)
return c.hijack("POST", path, opts.Success, opts.RawTerminal, opts.InputStream, opts.ErrorStream, opts.OutputStream, nil)
return c.hijack("POST", path, hijackOptions{
success: opts.Success,
setRawTerminal: opts.RawTerminal,
in: opts.InputStream,
stdout: opts.OutputStream,
stderr: opts.ErrorStream,
})
}
// LogsOptions represents the set of options used when getting logs from a
@@ -752,7 +766,11 @@ func (c *Client) Logs(opts LogsOptions) error {
opts.Tail = "all"
}
path := "/containers/" + opts.Container + "/logs?" + queryString(opts)
return c.stream("GET", path, opts.RawTerminal, false, nil, nil, opts.OutputStream, opts.ErrorStream)
return c.stream("GET", path, streamOptions{
setRawTerminal: opts.RawTerminal,
stdout: opts.OutputStream,
stderr: opts.ErrorStream,
})
}
// ResizeContainerTTY resizes the terminal to the given height and width.
@@ -760,7 +778,7 @@ func (c *Client) ResizeContainerTTY(id string, height, width int) error {
params := make(url.Values)
params.Set("h", strconv.Itoa(height))
params.Set("w", strconv.Itoa(width))
_, _, err := c.do("POST", "/containers/"+id+"/resize?"+params.Encode(), nil, false)
_, _, err := c.do("POST", "/containers/"+id+"/resize?"+params.Encode(), doOptions{})
return err
}
@@ -782,7 +800,10 @@ func (c *Client) ExportContainer(opts ExportContainerOptions) error {
return &NoSuchContainer{ID: opts.ID}
}
url := fmt.Sprintf("/containers/%s/export", opts.ID)
return c.stream("GET", url, true, false, nil, nil, opts.OutputStream, nil)
return c.stream("GET", url, streamOptions{
setRawTerminal: true,
stdout: opts.OutputStream,
})
}
// NoSuchContainer is the error returned when a given container does not exist.