Allow setting ulimits for containers

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-02-11 14:21:38 -05:00 committed by Vincent Demeester
parent 196bc32878
commit 473eb9a2c5
2 changed files with 49 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/ulimit"
"github.com/docker/docker/utils" "github.com/docker/docker/utils"
) )
@ -43,6 +44,10 @@ func LabelListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateLabel), names, usage) flag.Var(newListOptsRef(values, ValidateLabel), names, usage)
} }
func UlimitMapVar(values map[string]*ulimit.Ulimit, names []string, usage string) {
flag.Var(NewUlimitOpt(values), names, usage)
}
// ListOpts type // ListOpts type
type ListOpts struct { type ListOpts struct {
values *[]string values *[]string

44
opts/ulimit.go Normal file
View File

@ -0,0 +1,44 @@
package opts
import (
"fmt"
"github.com/docker/docker/pkg/ulimit"
)
type UlimitOpt struct {
values map[string]*ulimit.Ulimit
}
func NewUlimitOpt(ref map[string]*ulimit.Ulimit) *UlimitOpt {
return &UlimitOpt{ref}
}
func (o *UlimitOpt) Set(val string) error {
l, err := ulimit.Parse(val)
if err != nil {
return err
}
o.values[l.Name] = l
return nil
}
func (o *UlimitOpt) String() string {
var out []string
for _, v := range o.values {
out = append(out, v.String())
}
return fmt.Sprintf("%v", out)
}
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
var ulimits []*ulimit.Ulimit
for _, v := range o.values {
ulimits = append(ulimits, v)
}
return ulimits
}