diff --git a/components/cli/command/service/opts.go b/components/cli/command/service/opts.go index c89d40a767..2199e9f363 100644 --- a/components/cli/command/service/opts.go +++ b/components/cli/command/service/opts.go @@ -2,7 +2,6 @@ package service import ( "fmt" - "math/big" "strconv" "strings" "time" @@ -40,33 +39,6 @@ func (m *memBytes) Value() int64 { return int64(*m) } -type nanoCPUs int64 - -func (c *nanoCPUs) String() string { - return big.NewRat(c.Value(), 1e9).FloatString(3) -} - -func (c *nanoCPUs) Set(value string) error { - cpu, ok := new(big.Rat).SetString(value) - if !ok { - return fmt.Errorf("Failed to parse %v as a rational number", value) - } - nano := cpu.Mul(cpu, big.NewRat(1e9, 1)) - if !nano.IsInt() { - return fmt.Errorf("value is too precise") - } - *c = nanoCPUs(nano.Num().Int64()) - return nil -} - -func (c *nanoCPUs) Type() string { - return "NanoCPUs" -} - -func (c *nanoCPUs) Value() int64 { - return int64(*c) -} - // PositiveDurationOpt is an option type for time.Duration that uses a pointer. // It bahave similarly to DurationOpt but only allows positive duration values. type PositiveDurationOpt struct { @@ -156,9 +128,9 @@ type updateOptions struct { } type resourceOptions struct { - limitCPU nanoCPUs + limitCPU opts.NanoCPUs limitMemBytes memBytes - resCPU nanoCPUs + resCPU opts.NanoCPUs resMemBytes memBytes } diff --git a/components/cli/command/service/opts_test.go b/components/cli/command/service/opts_test.go index 26534cf0f5..aa2d999dcf 100644 --- a/components/cli/command/service/opts_test.go +++ b/components/cli/command/service/opts_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/opts" "github.com/docker/docker/pkg/testutil/assert" ) @@ -21,12 +22,12 @@ func TestMemBytesSetAndValue(t *testing.T) { } func TestNanoCPUsString(t *testing.T) { - var cpus nanoCPUs = 6100000000 + var cpus opts.NanoCPUs = 6100000000 assert.Equal(t, cpus.String(), "6.100") } func TestNanoCPUsSetAndValue(t *testing.T) { - var cpus nanoCPUs + var cpus opts.NanoCPUs assert.NilError(t, cpus.Set("0.35")) assert.Equal(t, cpus.Value(), int64(350000000)) }