Example #1
0
// Info returns system-wide information, like the number of running containers.
//
// See http://goo.gl/LOmySw for more details.
func (c *Client) Info() (*engine.Env, error) {
	body, _, err := c.do("GET", "/info", nil)
	if err != nil {
		return nil, err
	}
	var info engine.Env
	err = info.Decode(bytes.NewReader(body))
	if err != nil {
		return nil, err
	}
	return &info, nil
}
Example #2
0
func GetConnection(dockerSocket string) (*DockerClient, error) {
	var (
		client          *gdocker.Client
		err             error
		info            *engine.Env
		executionDriver string
	)

	client, err = gdocker.NewClient(dockerSocket)
	if err != nil {
		fmt.Println("Unable to connect to docker server:", err.Error())
		return nil, err
	}

	if info, err = client.Info(); err != nil {
		return nil, err
	}
	executionDriver = info.Get("ExecutionDriver")

	return &DockerClient{client, executionDriver}, nil
}
Example #3
0
func TestInfo(t *testing.T) {
	body := `{
     "Containers":11,
     "Images":16,
     "Debug":0,
     "NFd":11,
     "NGoroutines":21,
     "MemoryLimit":1,
     "SwapLimit":0
}`
	fakeRT := FakeRoundTripper{message: body, status: http.StatusOK}
	client := newTestClient(&fakeRT)
	expected := engine.Env{}
	expected.SetInt("Containers", 11)
	expected.SetInt("Images", 16)
	expected.SetBool("Debug", false)
	expected.SetInt("NFd", 11)
	expected.SetInt("NGoroutines", 21)
	expected.SetBool("MemoryLimit", true)
	expected.SetBool("SwapLimit", false)
	info, err := client.Info()
	if err != nil {
		t.Fatal(err)
	}
	infoSlice := []string(*info)
	expectedSlice := []string(expected)
	sort.Strings(infoSlice)
	sort.Strings(expectedSlice)
	if !reflect.DeepEqual(expectedSlice, infoSlice) {
		t.Errorf("Info(): Wrong result.\nWant %#v.\nGot %#v.", expected, *info)
	}
	req := fakeRT.requests[0]
	if req.Method != "GET" {
		t.Errorf("Info(): Wrong HTTP method. Want GET. Got %s.", req.Method)
	}
	u, _ := url.Parse(client.getURL("/info"))
	if req.URL.Path != u.Path {
		t.Errorf("Info(): Wrong request path. Want %q. Got %q.", u.Path, req.URL.Path)
	}
}