本文整理汇总了Golang中github.com/docker/docker/pkg/parsers.ParseKeyValueOpt函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseKeyValueOpt函数的具体用法?Golang ParseKeyValueOpt怎么用?Golang ParseKeyValueOpt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseKeyValueOpt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestParseLxcConfOpt
func TestParseLxcConfOpt(t *testing.T) {
opts := []string{"lxc.utsname=docker", "lxc.utsname = docker "}
for _, o := range opts {
k, v, err := parsers.ParseKeyValueOpt(o)
if err != nil {
t.FailNow()
}
if k != "lxc.utsname" {
t.Fail()
}
if v != "docker" {
t.Fail()
}
}
// With parseRun too
_, hostconfig, _, err := parseRun([]string{"lxc.utsname=docker", "lxc.utsname = docker ", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
for _, lxcConf := range hostconfig.LxcConf.Slice() {
if lxcConf.Key != "lxc.utsname" || lxcConf.Value != "docker" {
t.Fail()
}
}
}
示例2: Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
var volumeDriver string
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
switch key {
case Layer0VolumeDriver:
volumeDriver = val
default:
return nil, fmt.Errorf("Unknown option %s\n", key)
}
}
log.Infof("Layer0 volume driver: %v", volumeDriver)
volDriver, err := volume.Get(volumeDriver)
if err != nil {
return nil, err
}
ov, err := overlay.Init(home, options, uidMaps, gidMaps)
if err != nil {
volDriver.Shutdown()
return nil, err
}
d := &Layer0{
Driver: ov,
home: home,
volumes: make(map[string]*Layer0Vol),
volDriver: volDriver,
}
return d, nil
}
示例3: NewDriver
// NewDriver returns a new windows driver, called from NewDriver of execdriver.
func NewDriver(root, initPath string, options []string) (*Driver, error) {
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
key = strings.ToLower(key)
switch key {
case "dummy":
switch val {
case "1":
dummyMode = true
logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!")
}
case "forcekill":
switch val {
case "1":
forceKill = true
logrus.Warn("Using force kill mode in Windows exec driver. This is for testing purposes only.")
}
default:
return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
}
}
return &Driver{
root: root,
initPath: initPath,
activeContainers: make(map[string]*activeContainer),
}, nil
}
示例4: NewRbdSet
func NewRbdSet(root string, doInit bool, options []string, uidMaps, gidMaps []idtools.IDMap) (*RbdSet, error) {
conn, _ := rados.NewConn()
devices := &RbdSet{
MetaData: MetaData{Devices: make(map[string]*DevInfo)},
conn: conn,
dataPoolName: "rbd",
imagePrefix: "docker_image",
snapPrefix: "docker_snap",
metaPrefix: "docker_meta",
baseImageName: "base_image",
baseImageSize: DefaultDockerBaseImageSize,
clientId: "admin",
configFile: DefaultRadosConfigFile,
filesystem: "ext4",
uidMaps: uidMaps,
gidMaps: gidMaps,
}
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
key = strings.ToLower(key)
switch key {
case "rbd.basesize":
size, err := units.RAMInBytes(val)
if err != nil {
return nil, err
}
devices.baseImageSize = uint64(size)
case "rbd.datapool":
devices.dataPoolName = val
case "rbd.imageprefix":
devices.imagePrefix = val
case "rbd.client":
devices.clientId = val
case "rbd.configfile":
devices.configFile = val
case "rbd.fs":
if val != "ext4" && val != "xfs" {
return nil, fmt.Errorf("Unsupported filesystem %s\n", val)
}
devices.filesystem = val
case "rbd.mkfsarg":
devices.mkfsArgs = append(devices.mkfsArgs, val)
case "rbd.mountopt":
devices.mountOptions = joinMountOptions(devices.mountOptions, val)
default:
return nil, fmt.Errorf("Unknown option %s\n", key)
}
}
if err := devices.initRbdSet(doInit); err != nil {
return nil, err
}
return devices, nil
}
示例5: setDefaultIsolation
// setDefaultIsolation determine the default isolation mode for the
// daemon to run in. This is only applicable on Windows
func (daemon *Daemon) setDefaultIsolation() error {
daemon.defaultIsolation = containertypes.Isolation("process")
for _, option := range daemon.configStore.ExecOptions {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return err
}
key = strings.ToLower(key)
switch key {
case "isolation":
if !containertypes.Isolation(val).IsValid() {
return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val)
}
if containertypes.Isolation(val).IsHyperV() {
daemon.defaultIsolation = containertypes.Isolation("hyperv")
}
default:
return fmt.Errorf("Unrecognised exec-opt '%s'\n", key)
}
}
logrus.Infof("Windows default isolation mode: %s", daemon.defaultIsolation)
return nil
}
示例6: Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
logrus.Infof("Initializing Fuse Graph driver at home:%s and storage: %v...", home, virtPath)
var volumeDriver string
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
switch key {
case UnionFSVolumeDriver:
volumeDriver = val
default:
return nil, fmt.Errorf("Unknown option %s\n", key)
}
}
if volumeDriver == "" {
logrus.Warnf("Error - no volume driver specified for UnionFS")
return nil, fmt.Errorf("No volume driver specified for UnionFS")
}
logrus.Infof("UnionFS volume driver: %v", volumeDriver)
volDriver, err := volume.Get(volumeDriver)
if err != nil {
logrus.Warnf("Error while loading volume driver: %s", volumeDriver)
return nil, err
}
// In case it is mounted.
syscall.Unmount(virtPath, 0)
err = os.MkdirAll(virtPath, 0744)
if err != nil {
volDriver.Shutdown()
logrus.Warnf("Error while creating FUSE mount path: %v", err)
return nil, err
}
err = os.MkdirAll(physPath, 0744)
if err != nil {
volDriver.Shutdown()
logrus.Warnf("Error while creating FUSE mount path: %v", err)
return nil, err
}
cVirtPath := C.CString(virtPath)
cPhysPath := C.CString(physPath)
go C.start_unionfs(cPhysPath, cVirtPath)
d := &Driver{
volDriver: volDriver,
}
return d, nil
}
示例7: getCD
// getCD gets the raw value of the native.cgroupdriver option, if set.
func getCD(config *Config) string {
for _, option := range config.ExecOptions {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil || !strings.EqualFold(key, "native.cgroupdriver") {
continue
}
return val
}
return ""
}
示例8: parseKeyValueOpts
func parseKeyValueOpts(opts opts.ListOpts) ([]KeyValuePair, error) {
out := make([]KeyValuePair, opts.Len())
for i, o := range opts.GetAll() {
k, v, err := parsers.ParseKeyValueOpt(o)
if err != nil {
return nil, err
}
out[i] = KeyValuePair{Key: k, Value: v}
}
return out, nil
}
示例9: usingSystemd
func usingSystemd(config *Config) bool {
for _, option := range config.ExecOptions {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil || !strings.EqualFold(key, "native.cgroupdriver") {
continue
}
if val == "systemd" {
return true
}
}
return false
}
示例10: NewDriver
// NewDriver returns a new windows driver, called from NewDriver of execdriver.
func NewDriver(root string, options []string) (*Driver, error) {
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
key = strings.ToLower(key)
switch key {
case "dummy":
switch val {
case "1":
dummyMode = true
logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!")
}
case "forcekill":
switch val {
case "1":
forceKill = true
logrus.Warn("Using force kill mode in Windows exec driver. This is for testing purposes only.")
}
case "isolation":
if !container.Isolation(val).IsValid() {
return nil, fmt.Errorf("Unrecognised exec driver option 'isolation':'%s'", val)
}
if container.Isolation(val).IsHyperV() {
DefaultIsolation = "hyperv"
}
logrus.Infof("Windows default isolation: '%s'", val)
default:
return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
}
}
// TODO Windows TP5 timeframe. Remove this next block of code once TP4
// is no longer supported. Also remove the workaround in run.go.
//
// Hack for TP4.
// This overcomes an issue on TP4 which causes CreateComputeSystem to
// intermittently fail. It's predominantly here to make Windows to Windows
// CI more reliable.
TP4RetryHack = hcsshim.IsTP4()
return &Driver{
root: root,
activeContainers: make(map[string]*activeContainer),
}, nil
}
示例11: TestParseLxcConfOpt
func TestParseLxcConfOpt(t *testing.T) {
opts := []string{"lxc.utsname=docker", "lxc.utsname = docker "}
for _, o := range opts {
k, v, err := parsers.ParseKeyValueOpt(o)
if err != nil {
t.FailNow()
}
if k != "lxc.utsname" {
t.Fail()
}
if v != "docker" {
t.Fail()
}
}
}
示例12: getCgroupDriver
func (daemon *Daemon) getCgroupDriver() string {
cgroupDriver := cgroupFsDriver
// No other cgroup drivers are supported at the moment. Warn the
// user if they tried to set one other than cgroupfs
for _, option := range daemon.configStore.ExecOptions {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil || !strings.EqualFold(key, "native.cgroupdriver") {
continue
}
if val != cgroupFsDriver {
logrus.Warnf("cgroupdriver '%s' is not supported", val)
}
}
return cgroupDriver
}
示例13: parseOptions
func parseOptions(opt []string) (zfsOptions, error) {
var options zfsOptions
options.fsName = ""
for _, option := range opt {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return options, err
}
key = strings.ToLower(key)
switch key {
case "zfs.fsname":
options.fsName = val
default:
return options, fmt.Errorf("Unknown option %s", key)
}
}
return options, nil
}
示例14: NewDriver
// NewDriver returns a new windows driver, called from NewDriver of execdriver.
func NewDriver(root, initPath string, options []string) (*Driver, error) {
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
key = strings.ToLower(key)
switch key {
case "dummy":
switch val {
case "1":
dummyMode = true
logrus.Warn("Using dummy mode in Windows exec driver. This is for development use only!")
}
case "forcekill":
switch val {
case "1":
forceKill = true
logrus.Warn("Using force kill mode in Windows exec driver. This is for testing purposes only.")
}
case "isolation":
if !runconfig.IsolationLevel(val).IsValid() {
return nil, fmt.Errorf("Unrecognised exec driver option 'isolation':'%s'", val)
}
if runconfig.IsolationLevel(val).IsHyperV() {
defaultIsolation = "hyperv"
}
logrus.Infof("Windows default isolation level: '%s'", val)
default:
return nil, fmt.Errorf("Unrecognised exec driver option %s\n", key)
}
}
return &Driver{
root: root,
initPath: initPath,
activeContainers: make(map[string]*activeContainer),
}, nil
}
示例15: parseOptions
func parseOptions(options []string) (*overlayOptions, error) {
o := &overlayOptions{}
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
key = strings.ToLower(key)
switch key {
case "overlay2.override_kernel_check":
o.overrideKernelCheck, err = strconv.ParseBool(val)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("overlay2: Unknown option %s\n", key)
}
}
return o, nil
}