2015-02-11 19:21:38 +00:00
|
|
|
package opts
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|