當前位置: 首頁>>代碼示例>>Golang>>正文


Golang label.GenLabels函數代碼示例

本文整理匯總了Golang中github.com/dotcloud/docker/pkg/label.GenLabels函數的典型用法代碼示例。如果您正苦於以下問題:Golang GenLabels函數的具體用法?Golang GenLabels怎麽用?Golang GenLabels使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GenLabels函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: newContainer

func (daemon *Daemon) newContainer(name string, config *runconfig.Config, img *image.Image) (*Container, error) {
	var (
		id  string
		err error
	)
	id, name, err = daemon.generateIdAndName(name)
	if err != nil {
		return nil, err
	}

	daemon.generateHostname(id, config)
	entrypoint, args := daemon.getEntrypointAndArgs(config)

	container := &Container{
		// FIXME: we should generate the ID here instead of receiving it as an argument
		ID:              id,
		Created:         time.Now().UTC(),
		Path:            entrypoint,
		Args:            args, //FIXME: de-duplicate from config
		Config:          config,
		hostConfig:      &runconfig.HostConfig{},
		Image:           img.ID, // Always use the resolved image id
		NetworkSettings: &NetworkSettings{},
		Name:            name,
		Driver:          daemon.driver.String(),
		ExecDriver:      daemon.execDriver.Name(),
	}
	container.root = daemon.containerRoot(container.ID)

	if container.ProcessLabel, container.MountLabel, err = label.GenLabels(""); err != nil {
		return nil, err
	}
	return container, nil
}
開發者ID:rissem,項目名稱:docker,代碼行數:34,代碼來源:daemon.go

示例2: generateLXCConfig

func (d *driver) generateLXCConfig(c *execdriver.Command) (string, error) {
	var (
		process, mount string
		root           = path.Join(d.root, "containers", c.ID, "config.lxc")
		labels         = c.Config["label"]
	)
	fo, err := os.Create(root)
	if err != nil {
		return "", err
	}
	defer fo.Close()

	if len(labels) > 0 {
		process, mount, err = label.GenLabels(labels[0])
		if err != nil {
			return "", err
		}
	}

	if err := LxcTemplateCompiled.Execute(fo, struct {
		*execdriver.Command
		AppArmor     bool
		ProcessLabel string
		MountLabel   string
	}{
		Command:      c,
		AppArmor:     d.apparmor,
		ProcessLabel: process,
		MountLabel:   mount,
	}); err != nil {
		return "", err
	}
	return root, nil
}
開發者ID:vettery,項目名稱:docker,代碼行數:34,代碼來源:driver.go

示例3: setupLabels

func (d *driver) setupLabels(container *libcontainer.Container, c *execdriver.Command) error {
	labels := c.Config["label"]
	if len(labels) > 0 {
		process, mount, err := label.GenLabels(labels[0])
		if err != nil {
			return err
		}
		container.Context["mount_label"] = mount
		container.Context["process_label"] = process
	}
	return nil
}
開發者ID:JackDanger,項目名稱:docker,代碼行數:12,代碼來源:create.go

示例4: parseRun


//.........這裏部分代碼省略.........
	var binds []string
	// add any bind targets to the list of container volumes
	for bind := range flVolumes.GetMap() {
		if arr := strings.Split(bind, ":"); len(arr) > 1 {
			if arr[0] == "/" {
				return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
			}
			dstDir := arr[1]
			flVolumes.Set(dstDir)
			binds = append(binds, bind)
			flVolumes.Delete(bind)
		} else if bind == "/" {
			return nil, nil, cmd, fmt.Errorf("Invalid volume: path can't be '/'")
		}
	}

	var (
		parsedArgs = cmd.Args()
		runCmd     []string
		entrypoint []string
		image      string
	)
	if len(parsedArgs) >= 1 {
		image = cmd.Arg(0)
	}
	if len(parsedArgs) > 1 {
		runCmd = parsedArgs[1:]
	}
	if *flEntrypoint != "" {
		entrypoint = []string{*flEntrypoint}
	}

	if !*flPrivileged {
		pLabel, mLabel, e := label.GenLabels(*flLabelOptions)
		if e != nil {
			return nil, nil, cmd, fmt.Errorf("Invalid security labels : %s", e)
		}
		processLabel = pLabel
		mountLabel = mLabel
	}

	lxcConf, err := parseLxcConfOpts(flLxcOpts)
	if err != nil {
		return nil, nil, cmd, err
	}

	var (
		domainname string
		hostname   = *flHostname
		parts      = strings.SplitN(hostname, ".", 2)
	)
	if len(parts) > 1 {
		hostname = parts[0]
		domainname = parts[1]
	}

	ports, portBindings, err := nat.ParsePortSpecs(flPublish.GetAll())
	if err != nil {
		return nil, nil, cmd, err
	}

	// Merge in exposed ports to the map of published ports
	for _, e := range flExpose.GetAll() {
		if strings.Contains(e, ":") {
			return nil, nil, cmd, fmt.Errorf("Invalid port format for --expose: %s", e)
		}
開發者ID:rws-github,項目名稱:docker,代碼行數:67,代碼來源:parse.go


注:本文中的github.com/dotcloud/docker/pkg/label.GenLabels函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。