forked from docker/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker#15078 from hqhq/hq_add_set_api_v2
Implement docker update command
- Loading branch information
Showing
22 changed files
with
728 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package lib | ||
|
||
import ( | ||
"github.com/docker/docker/api/types/container" | ||
) | ||
|
||
// ContainerUpdate updates resources of a container | ||
func (cli *Client) ContainerUpdate(containerID string, hostConfig container.HostConfig) error { | ||
resp, err := cli.post("/containers/"+containerID+"/update", nil, hostConfig, nil) | ||
ensureReaderClosed(resp) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/docker/api/types/container" | ||
Cli "github.com/docker/docker/cli" | ||
flag "github.com/docker/docker/pkg/mflag" | ||
"github.com/docker/go-units" | ||
) | ||
|
||
// CmdUpdate updates resources of one or more containers. | ||
// | ||
// Usage: docker update [OPTIONS] CONTAINER [CONTAINER...] | ||
func (cli *DockerCli) CmdUpdate(args ...string) error { | ||
cmd := Cli.Subcmd("update", []string{"CONTAINER [CONTAINER...]"}, Cli.DockerCommands["update"].Description, true) | ||
flBlkioWeight := cmd.Uint16([]string{"-blkio-weight"}, 0, "Block IO (relative weight), between 10 and 1000") | ||
flCPUPeriod := cmd.Int64([]string{"-cpu-period"}, 0, "Limit CPU CFS (Completely Fair Scheduler) period") | ||
flCPUQuota := cmd.Int64([]string{"-cpu-quota"}, 0, "Limit CPU CFS (Completely Fair Scheduler) quota") | ||
flCpusetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)") | ||
flCpusetMems := cmd.String([]string{"-cpuset-mems"}, "", "MEMs in which to allow execution (0-3, 0,1)") | ||
flCPUShares := cmd.Int64([]string{"#c", "-cpu-shares"}, 0, "CPU shares (relative weight)") | ||
flMemoryString := cmd.String([]string{"m", "-memory"}, "", "Memory limit") | ||
flMemoryReservation := cmd.String([]string{"-memory-reservation"}, "", "Memory soft limit") | ||
flMemorySwap := cmd.String([]string{"-memory-swap"}, "", "Total memory (memory + swap), '-1' to disable swap") | ||
flKernelMemory := cmd.String([]string{"-kernel-memory"}, "", "Kernel memory limit") | ||
|
||
cmd.Require(flag.Min, 1) | ||
cmd.ParseFlags(args, true) | ||
if cmd.NFlag() == 0 { | ||
return fmt.Errorf("You must provide one or more flags when using this command.") | ||
} | ||
|
||
var err error | ||
var flMemory int64 | ||
if *flMemoryString != "" { | ||
flMemory, err = units.RAMInBytes(*flMemoryString) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
var memoryReservation int64 | ||
if *flMemoryReservation != "" { | ||
memoryReservation, err = units.RAMInBytes(*flMemoryReservation) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
var memorySwap int64 | ||
if *flMemorySwap != "" { | ||
if *flMemorySwap == "-1" { | ||
memorySwap = -1 | ||
} else { | ||
memorySwap, err = units.RAMInBytes(*flMemorySwap) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
var kernelMemory int64 | ||
if *flKernelMemory != "" { | ||
kernelMemory, err = units.RAMInBytes(*flKernelMemory) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
resources := container.Resources{ | ||
BlkioWeight: *flBlkioWeight, | ||
CpusetCpus: *flCpusetCpus, | ||
CpusetMems: *flCpusetMems, | ||
CPUShares: *flCPUShares, | ||
Memory: flMemory, | ||
MemoryReservation: memoryReservation, | ||
MemorySwap: memorySwap, | ||
KernelMemory: kernelMemory, | ||
CPUPeriod: *flCPUPeriod, | ||
CPUQuota: *flCPUQuota, | ||
} | ||
|
||
hostConfig := container.HostConfig{ | ||
Resources: resources, | ||
} | ||
|
||
names := cmd.Args() | ||
var errNames []string | ||
for _, name := range names { | ||
if err := cli.client.ContainerUpdate(name, hostConfig); err != nil { | ||
fmt.Fprintf(cli.err, "%s\n", err) | ||
errNames = append(errNames, name) | ||
} else { | ||
fmt.Fprintf(cli.out, "%s\n", name) | ||
} | ||
} | ||
|
||
if len(errNames) > 0 { | ||
return fmt.Errorf("Error: failed to update resources of containers: %v", errNames) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build windows | ||
|
||
package windows | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/docker/docker/daemon/execdriver" | ||
) | ||
|
||
// Update updates resource configs for a container. | ||
func (d *Driver) Update(c *execdriver.Command) error { | ||
return fmt.Errorf("Windows: Update not implemented") | ||
} |
Oops, something went wrong.