2018-02-05 21:05:59 +00:00
|
|
|
package opts // import "github.com/docker/docker/opts"
|
2015-02-11 19:21:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2015-12-21 20:06:46 +00:00
|
|
|
"github.com/docker/go-units"
|
2015-02-11 19:21:38 +00:00
|
|
|
)
|
|
|
|
|
2015-07-21 16:15:36 +00:00
|
|
|
// UlimitOpt defines a map of Ulimits
|
2015-02-11 19:21:38 +00:00
|
|
|
type UlimitOpt struct {
|
2015-12-21 20:06:46 +00:00
|
|
|
values *map[string]*units.Ulimit
|
2015-02-11 19:21:38 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 16:15:36 +00:00
|
|
|
// NewUlimitOpt creates a new UlimitOpt
|
2015-12-21 20:06:46 +00:00
|
|
|
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
|
2015-05-05 04:18:28 +00:00
|
|
|
if ref == nil {
|
2015-12-21 20:06:46 +00:00
|
|
|
ref = &map[string]*units.Ulimit{}
|
2015-05-05 04:18:28 +00:00
|
|
|
}
|
2015-02-11 19:21:38 +00:00
|
|
|
return &UlimitOpt{ref}
|
|
|
|
}
|
|
|
|
|
2015-07-21 16:15:36 +00:00
|
|
|
// Set validates a Ulimit and sets its name as a key in UlimitOpt
|
2015-02-11 19:21:38 +00:00
|
|
|
func (o *UlimitOpt) Set(val string) error {
|
2015-12-21 20:06:46 +00:00
|
|
|
l, err := units.ParseUlimit(val)
|
2015-02-11 19:21:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-05 04:18:28 +00:00
|
|
|
(*o.values)[l.Name] = l
|
2015-02-11 19:21:38 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-21 16:15:36 +00:00
|
|
|
// String returns Ulimit values as a string.
|
2015-02-11 19:21:38 +00:00
|
|
|
func (o *UlimitOpt) String() string {
|
|
|
|
var out []string
|
2015-05-05 04:18:28 +00:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 19:21:38 +00:00
|
|
|
out = append(out, v.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%v", out)
|
|
|
|
}
|
|
|
|
|
2015-07-21 16:15:36 +00:00
|
|
|
// GetList returns a slice of pointers to Ulimits.
|
2015-12-21 20:06:46 +00:00
|
|
|
func (o *UlimitOpt) GetList() []*units.Ulimit {
|
|
|
|
var ulimits []*units.Ulimit
|
2015-05-05 04:18:28 +00:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 19:21:38 +00:00
|
|
|
ulimits = append(ulimits, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ulimits
|
|
|
|
}
|
2016-05-31 23:49:32 +00:00
|
|
|
|
|
|
|
// Type returns the option type
|
|
|
|
func (o *UlimitOpt) Type() string {
|
|
|
|
return "ulimit"
|
|
|
|
}
|
2017-04-12 07:26:42 +00:00
|
|
|
|
|
|
|
// NamedUlimitOpt defines a named map of Ulimits
|
|
|
|
type NamedUlimitOpt struct {
|
|
|
|
name string
|
|
|
|
UlimitOpt
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ NamedOption = &NamedUlimitOpt{}
|
|
|
|
|
|
|
|
// NewNamedUlimitOpt creates a new NamedUlimitOpt
|
|
|
|
func NewNamedUlimitOpt(name string, ref *map[string]*units.Ulimit) *NamedUlimitOpt {
|
|
|
|
if ref == nil {
|
|
|
|
ref = &map[string]*units.Ulimit{}
|
|
|
|
}
|
|
|
|
return &NamedUlimitOpt{
|
|
|
|
name: name,
|
|
|
|
UlimitOpt: *NewUlimitOpt(ref),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the option name
|
|
|
|
func (o *NamedUlimitOpt) Name() string {
|
|
|
|
return o.name
|
|
|
|
}
|