2015-12-28 06:19:26 -05:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-12-29 09:03:39 -05:00
|
|
|
"strings"
|
2015-12-28 06:19:26 -05:00
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2015-12-28 06:19:26 -05:00
|
|
|
Cli "github.com/docker/docker/cli"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2016-01-04 10:58:20 -05:00
|
|
|
"github.com/docker/docker/runconfig/opts"
|
2016-01-04 19:05:26 -05:00
|
|
|
"github.com/docker/engine-api/types/container"
|
2015-12-28 06:19:26 -05:00
|
|
|
"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")
|
2016-01-21 00:48:53 -05:00
|
|
|
flMemorySwap := cmd.String([]string{"-memory-swap"}, "", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap")
|
2015-12-28 06:19:26 -05:00
|
|
|
flKernelMemory := cmd.String([]string{"-kernel-memory"}, "", "Kernel memory limit")
|
2016-01-04 10:58:20 -05:00
|
|
|
flRestartPolicy := cmd.String([]string{"-restart"}, "", "Restart policy to apply when a container exits")
|
2015-12-28 06:19:26 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 10:58:20 -05:00
|
|
|
var restartPolicy container.RestartPolicy
|
|
|
|
if *flRestartPolicy != "" {
|
|
|
|
restartPolicy, err = opts.ParseRestartPolicy(*flRestartPolicy)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-28 06:19:26 -05:00
|
|
|
resources := container.Resources{
|
|
|
|
BlkioWeight: *flBlkioWeight,
|
|
|
|
CpusetCpus: *flCpusetCpus,
|
|
|
|
CpusetMems: *flCpusetMems,
|
|
|
|
CPUShares: *flCPUShares,
|
|
|
|
Memory: flMemory,
|
|
|
|
MemoryReservation: memoryReservation,
|
|
|
|
MemorySwap: memorySwap,
|
|
|
|
KernelMemory: kernelMemory,
|
|
|
|
CPUPeriod: *flCPUPeriod,
|
|
|
|
CPUQuota: *flCPUQuota,
|
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:12 -05:00
|
|
|
updateConfig := container.UpdateConfig{
|
2016-01-04 10:58:20 -05:00
|
|
|
Resources: resources,
|
|
|
|
RestartPolicy: restartPolicy,
|
2015-12-28 06:19:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
names := cmd.Args()
|
2015-12-29 09:03:39 -05:00
|
|
|
var errs []string
|
2015-12-28 06:19:26 -05:00
|
|
|
for _, name := range names {
|
2016-03-16 15:19:22 -04:00
|
|
|
if err := cli.client.ContainerUpdate(context.Background(), name, updateConfig); err != nil {
|
Remove redundant error message
Currently some commands including `kill`, `pause`, `restart`, `rm`,
`rmi`, `stop`, `unpause`, `udpate`, `wait` will print a lot of error
message on client side, with a lot of redundant messages, this commit is
trying to remove the unuseful and redundant information for user.
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
2016-02-03 01:29:15 -05:00
|
|
|
errs = append(errs, err.Error())
|
2015-12-28 06:19:26 -05:00
|
|
|
} else {
|
|
|
|
fmt.Fprintf(cli.out, "%s\n", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:03:39 -05:00
|
|
|
if len(errs) > 0 {
|
|
|
|
return fmt.Errorf("%s", strings.Join(errs, "\n"))
|
2015-12-28 06:19:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|