Add swarmkit fields to stack service.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-10-28 17:30:20 -04:00 committed by Vincent Demeester
parent 9d3c317c95
commit 18ad4598a8
1 changed files with 16 additions and 10 deletions

View File

@ -331,16 +331,9 @@ func (c *NanoCPUs) String() string {
// Set sets the value of the NanoCPU by passing a string // Set sets the value of the NanoCPU by passing a string
func (c *NanoCPUs) Set(value string) error { func (c *NanoCPUs) Set(value string) error {
cpu, ok := new(big.Rat).SetString(value) cpus, err := ParseCPUs(value)
if !ok { *c = NanoCPUs(cpus)
return fmt.Errorf("Failed to parse %v as a rational number", value) return err
}
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
} }
// Type returns the type // Type returns the type
@ -352,3 +345,16 @@ func (c *NanoCPUs) Type() string {
func (c *NanoCPUs) Value() int64 { func (c *NanoCPUs) Value() int64 {
return int64(*c) return int64(*c)
} }
// ParseCPUs takes a string ratio and returns an integer value of nano cpus
func ParseCPUs(value string) (int64, error) {
cpu, ok := new(big.Rat).SetString(value)
if !ok {
return 0, fmt.Errorf("failed to parse %v as a rational number", value)
}
nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
if !nano.IsInt() {
return 0, fmt.Errorf("value is too precise")
}
return nano.Num().Int64(), nil
}