Selaa lähdekoodia

removed only_ids and trunc_cmd from the api

Victor Vieux 12 vuotta sitten
vanhempi
commit
1990c49a62
6 muutettua tiedostoa jossa 48 lisäystä ja 74 poistoa
  1. 2 5
      api.go
  2. 6 6
      api_params.go
  3. 7 11
      api_test.go
  4. 17 11
      commands.go
  5. 2 5
      docs/sources/remote-api/api.rst
  6. 14 36
      server.go

+ 2 - 5
api.go

@@ -129,9 +129,8 @@ func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map
 
 	all := r.Form.Get("all") == "1"
 	filter := r.Form.Get("filter")
-	only_ids := r.Form.Get("only_ids") == "1"
 
-	outs, err := srv.Images(all, only_ids, filter)
+	outs, err := srv.Images(all, filter)
 	if err != nil {
 		return err
 	}
@@ -199,8 +198,6 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m
 		return err
 	}
 	all := r.Form.Get("all") == "1"
-	trunc_cmd := r.Form.Get("trunc_cmd") != "0"
-	only_ids := r.Form.Get("only_ids") == "1"
 	since := r.Form.Get("since")
 	before := r.Form.Get("before")
 	n, err := strconv.Atoi(r.Form.Get("limit"))
@@ -208,7 +205,7 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m
 		n = -1
 	}
 
-	outs := srv.Containers(all, trunc_cmd, only_ids, n, since, before)
+	outs := srv.Containers(all, n, since, before)
 	b, err := json.Marshal(outs)
 	if err != nil {
 		return err

+ 6 - 6
api_params.go

@@ -10,7 +10,7 @@ type ApiImages struct {
 	Repository string `json:",omitempty"`
 	Tag        string `json:",omitempty"`
 	Id         string
-	Created    int64 `json:",omitempty"`
+	Created    int64
 }
 
 type ApiInfo struct {
@@ -25,11 +25,11 @@ type ApiInfo struct {
 
 type ApiContainers struct {
 	Id      string
-	Image   string `json:",omitempty"`
-	Command string `json:",omitempty"`
-	Created int64  `json:",omitempty"`
-	Status  string `json:",omitempty"`
-	Ports   string `json:",omitempty"`
+	Image   string
+	Command string
+	Created int64
+	Status  string
+	Ports   string
 }
 
 type ApiSearch struct {

+ 7 - 11
api_test.go

@@ -115,8 +115,8 @@ func TestGetImagesJson(t *testing.T) {
 
 	srv := &Server{runtime: runtime}
 
-	// only_ids=0&all=0
-	req, err := http.NewRequest("GET", "/images/json?only_ids=0&all=0", nil)
+	// all=0
+	req, err := http.NewRequest("GET", "/images/json?all=0", nil)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -142,8 +142,8 @@ func TestGetImagesJson(t *testing.T) {
 
 	r2 := httptest.NewRecorder()
 
-	// only_ids=1&all=1
-	req2, err := http.NewRequest("GET", "/images/json?only_ids=1&all=1", nil)
+	// all=1
+	req2, err := http.NewRequest("GET", "/images/json?all=1", nil)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -161,10 +161,6 @@ func TestGetImagesJson(t *testing.T) {
 		t.Errorf("Excepted 1 image, %d found", len(images2))
 	}
 
-	if images2[0].Repository != "" {
-		t.Errorf("Excepted no image Repository, %s found", images2[0].Repository)
-	}
-
 	if images2[0].Id != GetTestImage(runtime).ShortId() {
 		t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ShortId(), images2[0].Id)
 	}
@@ -329,8 +325,8 @@ func TestGetContainersPs(t *testing.T) {
 	if len(containers) != 1 {
 		t.Fatalf("Excepted %d container, %d found", 1, len(containers))
 	}
-	if containers[0].Id != container.ShortId() {
-		t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ShortId(), containers[0].Id)
+	if containers[0].Id != container.Id {
+		t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.Id, containers[0].Id)
 	}
 }
 
@@ -1194,7 +1190,7 @@ func TestDeleteContainers(t *testing.T) {
 
 func TestDeleteImages(t *testing.T) {
 	//FIXME: Implement this test
-	t.Skip("Test not implemented")
+	t.Log("Test not implemented")
 }
 
 // Mocked types for tests

+ 17 - 11
commands.go

@@ -708,9 +708,6 @@ func CmdImages(args ...string) error {
 		if cmd.NArg() == 1 {
 			v.Set("filter", cmd.Arg(0))
 		}
-		if *quiet {
-			v.Set("only_ids", "1")
-		}
 		if *all {
 			v.Set("all", "1")
 		}
@@ -732,6 +729,13 @@ func CmdImages(args ...string) error {
 		}
 
 		for _, out := range outs {
+			if out.Repository == "" {
+				out.Repository = "<none>"
+			}
+			if out.Tag == "" {
+				out.Tag = "<none>"
+			}
+
 			if !*quiet {
 				fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\n", out.Repository, out.Tag, out.Id, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
 			} else {
@@ -763,15 +767,9 @@ func CmdPs(args ...string) error {
 	if *last == -1 && *nLatest {
 		*last = 1
 	}
-	if *quiet {
-		v.Set("only_ids", "1")
-	}
 	if *all {
 		v.Set("all", "1")
 	}
-	if *noTrunc {
-		v.Set("trunc_cmd", "0")
-	}
 	if *last != -1 {
 		v.Set("limit", strconv.Itoa(*last))
 	}
@@ -799,9 +797,17 @@ func CmdPs(args ...string) error {
 
 	for _, out := range outs {
 		if !*quiet {
-			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
+			if *noTrunc {
+				fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", out.Id, out.Image, out.Command, out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
+			} else {
+				fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s ago\t%s\n", TruncateId(out.Id), out.Image, Trunc(out.Command, 20), out.Status, HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Ports)
+			}
 		} else {
-			fmt.Fprintln(w, out.Id)
+			if *noTrunc {
+				fmt.Fprintln(w, out.Id)
+			} else {
+				fmt.Fprintln(w, TruncateId(out.Id))
+			}
 		}
 	}
 

+ 2 - 5
docs/sources/remote-api/api.rst

@@ -28,7 +28,7 @@ List containers
 
 	.. sourcecode:: http
 
-	   GET /containers/ps?trunc_cmd=0&all=1&only_ids=0&before=8dfafdbc3a40 HTTP/1.1
+	   GET /containers/ps?trunc_cmd=0&all=1&before=8dfafdbc3a40 HTTP/1.1
 	   
 	**Example response**:
 
@@ -68,9 +68,7 @@ List containers
 		}
 	   ]
  
-	:query only_ids: 1 or 0, Only display numeric IDs. Default 0
 	:query all: 1 or 0, Show all containers. Only running containers are shown by default
-	:query trunc_cmd: 1 or 0, Truncate output. Output is truncated by default  
 	:query limit: Show ``limit`` last created containers, include non-running ones.
 	:query since: Show only containers created since Id, include non-running ones.
 	:query before: Show only containers created before Id, include non-running ones.
@@ -467,7 +465,7 @@ List Images
 
 	.. sourcecode:: http
 
-	   GET /images/json?all=0&only_ids=0 HTTP/1.1
+	   GET /images/json?all=0 HTTP/1.1
 
 	**Example response**:
 
@@ -523,7 +521,6 @@ List Images
 	   base [style=invisible]
 	   }
  
-	:query only_ids: 1 or 0, Only display numeric IDs. Default 0
 	:query all: 1 or 0, Show all containers. Only running containers are shown by default
 	:statuscode 200: no error
 	:statuscode 500: server error

+ 14 - 36
server.go

@@ -135,7 +135,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
 	return nil
 }
 
-func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error) {
+func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
 	var allImages map[string]*Image
 	var err error
 	if all {
@@ -159,29 +159,19 @@ func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error
 				continue
 			}
 			delete(allImages, id)
-			if !only_ids {
-				out.Repository = name
-				out.Tag = tag
-				out.Id = TruncateId(id)
-				out.Created = image.Created.Unix()
-			} else {
-				out.Id = image.ShortId()
-			}
+			out.Repository = name
+			out.Tag = tag
+			out.Id = image.ShortId()
+			out.Created = image.Created.Unix()
 			outs = append(outs, out)
 		}
 	}
 	// Display images which aren't part of a
 	if filter == "" {
-		for id, image := range allImages {
+		for _, image := range allImages {
 			var out ApiImages
-			if !only_ids {
-				out.Repository = "<none>"
-				out.Tag = "<none>"
-				out.Id = TruncateId(id)
-				out.Created = image.Created.Unix()
-			} else {
-				out.Id = image.ShortId()
-			}
+			out.Id = image.ShortId()
+			out.Created = image.Created.Unix()
 			outs = append(outs, out)
 		}
 	}
@@ -235,7 +225,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
 	return nil, fmt.Errorf("No such container: %s", name)
 }
 
-func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, before string) []ApiContainers {
+func (srv *Server) Containers(all bool, n int, since, before string) []ApiContainers {
 	var foundBefore bool
 	var displayed int
 	retContainers := []ApiContainers{}
@@ -264,23 +254,11 @@ func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, befor
 		c := ApiContainers{
 			Id: container.Id,
 		}
-		if trunc_cmd {
-			c = ApiContainers{
-				Id: container.ShortId(),
-			}
-		}
-
-		if !only_ids {
-			command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
-			if trunc_cmd {
-				command = Trunc(command, 20)
-			}
-			c.Image = srv.runtime.repositories.ImageName(container.Image)
-			c.Command = command
-			c.Created = container.Created.Unix()
-			c.Status = container.State.String()
-			c.Ports = container.NetworkSettings.PortMappingHuman()
-		}
+		c.Image = srv.runtime.repositories.ImageName(container.Image)
+		c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
+		c.Created = container.Created.Unix()
+		c.Status = container.State.String()
+		c.Ports = container.NetworkSettings.PortMappingHuman()
 		retContainers = append(retContainers, c)
 	}
 	return retContainers