constraints

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2017 License: BSD-2-Clause Imports: 6 Imported by: 6

Documentation

Overview

package constraints contains methods for decoding a compact CPU and Memory constraints format. We specify the "constraints" format as the following:

<cpushare>:<memory limit>

CPUShare can be any number between 2 and 1024. For more details on how the --cpu-shares flag works in Docker/cgroups, see https://docs.docker.com/reference/run/#cpu-share-constraint

Memory limit can contain a number and optionally the units. The following are all equivalent:

6GB
6144MB
6291456KB

Index

Constants

View Source
const ConstraintsSeparator = ":"

ConstraintsSeparator separates the individual resource constraints

Variables

View Source
var (
	ErrInvalidCPUShare   = errors.New("CPUShare must be a value between 2 and 1024")
	ErrInvalidMemory     = errors.New("invalid memory format")
	ErrInvalidConstraint = errors.New("invalid constraints format")
)

Functions

This section is empty.

Types

type CPUShare

type CPUShare int

CPUShare represents a CPUShare.

func NewCPUShare

func NewCPUShare(i int) (CPUShare, error)

NewCPUShare casts i to a CPUShare and ensures its validity.

func ParseCPUShare

func ParseCPUShare(s string) (CPUShare, error)

type Constraints

type Constraints struct {
	CPUShare
	Memory
	Nproc
}

Constraints is a composition of CPUShares, Memory and Nproc constraints.

func Parse

func Parse(s string) (Constraints, error)

type Memory

type Memory uint

Memory represents a memory limit.

func ParseMemory

func ParseMemory(s string) (Memory, error)

ParseMemory parses a string in memory format and returns the amount of memory in bytes.

func (Memory) String

func (m Memory) String() string

String returns the string representation of Memory, using the following algorithm:

* If the memory is less than 1 KB, it will return "x". * If the memory is less than 1 MB, it will return "xKB". * If the memory is less than 1 GB, it will return "xMB". * etc

type Nproc added in v0.10.1

type Nproc uint

func ParseNproc added in v0.10.1

func ParseNproc(s string) (Nproc, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL