|
@@ -5,11 +5,7 @@ import (
|
|
|
"net"
|
|
|
"os"
|
|
|
"regexp"
|
|
|
- "strconv"
|
|
|
"strings"
|
|
|
-
|
|
|
- "github.com/docker/docker/api/types/blkiodev"
|
|
|
- "github.com/docker/go-units"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -153,12 +149,6 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
|
|
|
// ValidatorFctType defines a validator function that returns a validated string and/or an error.
|
|
|
type ValidatorFctType func(val string) (string, error)
|
|
|
|
|
|
-// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
|
|
|
-type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
|
|
|
-
|
|
|
-// ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error.
|
|
|
-type ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error)
|
|
|
-
|
|
|
// ValidatorFctListType defines a validator function that returns a validated list of string and/or an error
|
|
|
type ValidatorFctListType func(val string) ([]string, error)
|
|
|
|
|
@@ -173,75 +163,6 @@ func ValidateAttach(val string) (string, error) {
|
|
|
return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR")
|
|
|
}
|
|
|
|
|
|
-// ValidateWeightDevice validates that the specified string has a valid device-weight format.
|
|
|
-func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) {
|
|
|
- split := strings.SplitN(val, ":", 2)
|
|
|
- if len(split) != 2 {
|
|
|
- return nil, fmt.Errorf("bad format: %s", val)
|
|
|
- }
|
|
|
- if !strings.HasPrefix(split[0], "/dev/") {
|
|
|
- return nil, fmt.Errorf("bad format for device path: %s", val)
|
|
|
- }
|
|
|
- weight, err := strconv.ParseUint(split[1], 10, 0)
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("invalid weight for device: %s", val)
|
|
|
- }
|
|
|
- if weight > 0 && (weight < 10 || weight > 1000) {
|
|
|
- return nil, fmt.Errorf("invalid weight for device: %s", val)
|
|
|
- }
|
|
|
-
|
|
|
- return &blkiodev.WeightDevice{
|
|
|
- Path: split[0],
|
|
|
- Weight: uint16(weight),
|
|
|
- }, nil
|
|
|
-}
|
|
|
-
|
|
|
-// ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format.
|
|
|
-func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error) {
|
|
|
- split := strings.SplitN(val, ":", 2)
|
|
|
- if len(split) != 2 {
|
|
|
- return nil, fmt.Errorf("bad format: %s", val)
|
|
|
- }
|
|
|
- if !strings.HasPrefix(split[0], "/dev/") {
|
|
|
- return nil, fmt.Errorf("bad format for device path: %s", val)
|
|
|
- }
|
|
|
- rate, err := units.RAMInBytes(split[1])
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
|
|
|
- }
|
|
|
- if rate < 0 {
|
|
|
- return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
|
|
|
- }
|
|
|
-
|
|
|
- return &blkiodev.ThrottleDevice{
|
|
|
- Path: split[0],
|
|
|
- Rate: uint64(rate),
|
|
|
- }, nil
|
|
|
-}
|
|
|
-
|
|
|
-// ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format.
|
|
|
-func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) {
|
|
|
- split := strings.SplitN(val, ":", 2)
|
|
|
- if len(split) != 2 {
|
|
|
- return nil, fmt.Errorf("bad format: %s", val)
|
|
|
- }
|
|
|
- if !strings.HasPrefix(split[0], "/dev/") {
|
|
|
- return nil, fmt.Errorf("bad format for device path: %s", val)
|
|
|
- }
|
|
|
- rate, err := strconv.ParseUint(split[1], 10, 64)
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
|
|
|
- }
|
|
|
- if rate < 0 {
|
|
|
- return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
|
|
|
- }
|
|
|
-
|
|
|
- return &blkiodev.ThrottleDevice{
|
|
|
- Path: split[0],
|
|
|
- Rate: uint64(rate),
|
|
|
- }, nil
|
|
|
-}
|
|
|
-
|
|
|
// ValidateEnv validates an environment variable and returns it.
|
|
|
// If no value is specified, it returns the current value using os.Getenv.
|
|
|
//
|