当前位置: 首页>>代码示例>>Golang>>正文


Golang Env.SetList方法代码示例

本文整理汇总了Golang中github.com/docker/docker/engine.Env.SetList方法的典型用法代码示例。如果您正苦于以下问题:Golang Env.SetList方法的具体用法?Golang Env.SetList怎么用?Golang Env.SetList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/docker/docker/engine.Env的用法示例。


在下文中一共展示了Env.SetList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: postContainersCreate

func postContainersCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	if err := parseForm(r); err != nil {
		return nil
	}
	var (
		out          engine.Env
		job          = eng.Job("create", r.Form.Get("name"))
		outWarnings  []string
		stdoutBuffer = bytes.NewBuffer(nil)
		warnings     = bytes.NewBuffer(nil)
	)
	if err := job.DecodeEnv(r.Body); err != nil {
		return err
	}
	// Read container ID from the first line of stdout
	job.Stdout.Add(stdoutBuffer)
	// Read warnings from stderr
	job.Stderr.Add(warnings)
	if err := job.Run(); err != nil {
		return err
	}
	// Parse warnings from stderr
	scanner := bufio.NewScanner(warnings)
	for scanner.Scan() {
		outWarnings = append(outWarnings, scanner.Text())
	}
	out.Set("Id", engine.Tail(stdoutBuffer, 1))
	out.SetList("Warnings", outWarnings)
	return writeJSON(w, http.StatusCreated, out)
}
开发者ID:houbl,项目名称:docker,代码行数:30,代码来源:server.go

示例2: TestPostContainersCgroup

func TestPostContainersCgroup(t *testing.T) {
	eng := NewTestEngine(t)
	defer mkDaemonFromEngine(eng, t).Nuke()

	memory := int64(4194304)
	containerID := createTestContainer(eng,
		&runconfig.Config{
			Memory:    memory,
			Image:     unitTestImageID,
			Cmd:       []string{"/bin/cat"},
			OpenStdin: true,
		},
		t,
	)

	defer func() {
		// Make sure the process dies before destroying runtime
		containerKill(eng, containerID, t)
		containerWait(eng, containerID, t)
	}()

	startContainer(eng, containerID, t)

	// Give some time to the process to start
	containerWaitTimeout(eng, containerID, t)

	if !containerRunning(eng, containerID, t) {
		t.Errorf("Container should be running")
	}

	var (
		cgroupData     engine.Env
		readSubsystem  []string
		writeSubsystem []struct {
			Key   string
			Value string
		}
	)
	readSubsystem = append(readSubsystem, "memory.limit_in_bytes")
	writeSubsystem = append(writeSubsystem, struct {
		Key   string
		Value string
	}{Key: "cpu.shares", Value: "2048"})
	cgroupData.SetList("ReadSubsystem", readSubsystem)
	cgroupData.SetJson("WriteSubsystem", writeSubsystem)

	jsonData := bytes.NewBuffer(nil)
	if err := cgroupData.Encode(jsonData); err != nil {
		t.Fatal(err)
	}

	r := httptest.NewRecorder()
	req, err := http.NewRequest("POST", "/containers/"+containerID+"/cgroup?w=1", jsonData)
	req.Header.Add("Content-Type", "application/json")
	if err != nil {
		t.Fatal(err)
	}
	if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
		t.Fatal(err)
	}
	assertHttpNotError(r, t)

	if r.Code != http.StatusOK {
		t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
	}
	var cgroupResponses []struct {
		Subsystem string
		Out       string
		Err       string
		Status    int
	}

	if err := json.Unmarshal(r.Body.Bytes(), &cgroupResponses); err != nil {
		t.Fatal(err)
	}

	for _, cgroupResponse := range cgroupResponses {
		if cgroupResponse.Status != 0 {
			t.Fatalf("The status of cgroup response is not zero, subsystem: %s, out: %s, err: %s, status: %s",
				cgroupResponse.Subsystem, cgroupResponse.Out, cgroupResponse.Err, cgroupResponse.Status)
		}
	}
}
开发者ID:bigclouds,项目名称:docker-1.3.2,代码行数:83,代码来源:api_test.go


注:本文中的github.com/docker/docker/engine.Env.SetList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。