| ... | ... |
@@ -129,9 +129,8 @@ func getImagesJson(srv *Server, w http.ResponseWriter, r *http.Request, vars map |
| 129 | 129 |
|
| 130 | 130 |
all := r.Form.Get("all") == "1"
|
| 131 | 131 |
filter := r.Form.Get("filter")
|
| 132 |
- only_ids := r.Form.Get("only_ids") == "1"
|
|
| 133 | 132 |
|
| 134 |
- outs, err := srv.Images(all, only_ids, filter) |
|
| 133 |
+ outs, err := srv.Images(all, filter) |
|
| 135 | 134 |
if err != nil {
|
| 136 | 135 |
return err |
| 137 | 136 |
} |
| ... | ... |
@@ -199,8 +198,6 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m |
| 199 | 199 |
return err |
| 200 | 200 |
} |
| 201 | 201 |
all := r.Form.Get("all") == "1"
|
| 202 |
- trunc_cmd := r.Form.Get("trunc_cmd") != "0"
|
|
| 203 |
- only_ids := r.Form.Get("only_ids") == "1"
|
|
| 204 | 202 |
since := r.Form.Get("since")
|
| 205 | 203 |
before := r.Form.Get("before")
|
| 206 | 204 |
n, err := strconv.Atoi(r.Form.Get("limit"))
|
| ... | ... |
@@ -208,7 +205,7 @@ func getContainersPs(srv *Server, w http.ResponseWriter, r *http.Request, vars m |
| 208 | 208 |
n = -1 |
| 209 | 209 |
} |
| 210 | 210 |
|
| 211 |
- outs := srv.Containers(all, trunc_cmd, only_ids, n, since, before) |
|
| 211 |
+ outs := srv.Containers(all, n, since, before) |
|
| 212 | 212 |
b, err := json.Marshal(outs) |
| 213 | 213 |
if err != nil {
|
| 214 | 214 |
return err |
| ... | ... |
@@ -10,7 +10,7 @@ type ApiImages struct {
|
| 10 | 10 |
Repository string `json:",omitempty"` |
| 11 | 11 |
Tag string `json:",omitempty"` |
| 12 | 12 |
Id string |
| 13 |
- Created int64 `json:",omitempty"` |
|
| 13 |
+ Created int64 |
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 | 16 |
type ApiInfo struct {
|
| ... | ... |
@@ -25,11 +25,11 @@ type ApiInfo struct {
|
| 25 | 25 |
|
| 26 | 26 |
type ApiContainers struct {
|
| 27 | 27 |
Id string |
| 28 |
- Image string `json:",omitempty"` |
|
| 29 |
- Command string `json:",omitempty"` |
|
| 30 |
- Created int64 `json:",omitempty"` |
|
| 31 |
- Status string `json:",omitempty"` |
|
| 32 |
- Ports string `json:",omitempty"` |
|
| 28 |
+ Image string |
|
| 29 |
+ Command string |
|
| 30 |
+ Created int64 |
|
| 31 |
+ Status string |
|
| 32 |
+ Ports string |
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
type ApiSearch struct {
|
| ... | ... |
@@ -115,8 +115,8 @@ func TestGetImagesJson(t *testing.T) {
|
| 115 | 115 |
|
| 116 | 116 |
srv := &Server{runtime: runtime}
|
| 117 | 117 |
|
| 118 |
- // only_ids=0&all=0 |
|
| 119 |
- req, err := http.NewRequest("GET", "/images/json?only_ids=0&all=0", nil)
|
|
| 118 |
+ // all=0 |
|
| 119 |
+ req, err := http.NewRequest("GET", "/images/json?all=0", nil)
|
|
| 120 | 120 |
if err != nil {
|
| 121 | 121 |
t.Fatal(err) |
| 122 | 122 |
} |
| ... | ... |
@@ -142,8 +142,8 @@ func TestGetImagesJson(t *testing.T) {
|
| 142 | 142 |
|
| 143 | 143 |
r2 := httptest.NewRecorder() |
| 144 | 144 |
|
| 145 |
- // only_ids=1&all=1 |
|
| 146 |
- req2, err := http.NewRequest("GET", "/images/json?only_ids=1&all=1", nil)
|
|
| 145 |
+ // all=1 |
|
| 146 |
+ req2, err := http.NewRequest("GET", "/images/json?all=1", nil)
|
|
| 147 | 147 |
if err != nil {
|
| 148 | 148 |
t.Fatal(err) |
| 149 | 149 |
} |
| ... | ... |
@@ -161,10 +161,6 @@ func TestGetImagesJson(t *testing.T) {
|
| 161 | 161 |
t.Errorf("Excepted 1 image, %d found", len(images2))
|
| 162 | 162 |
} |
| 163 | 163 |
|
| 164 |
- if images2[0].Repository != "" {
|
|
| 165 |
- t.Errorf("Excepted no image Repository, %s found", images2[0].Repository)
|
|
| 166 |
- } |
|
| 167 |
- |
|
| 168 | 164 |
if images2[0].Id != GetTestImage(runtime).ShortId() {
|
| 169 | 165 |
t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ShortId(), images2[0].Id)
|
| 170 | 166 |
} |
| ... | ... |
@@ -329,8 +325,8 @@ func TestGetContainersPs(t *testing.T) {
|
| 329 | 329 |
if len(containers) != 1 {
|
| 330 | 330 |
t.Fatalf("Excepted %d container, %d found", 1, len(containers))
|
| 331 | 331 |
} |
| 332 |
- if containers[0].Id != container.ShortId() {
|
|
| 333 |
- t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ShortId(), containers[0].Id)
|
|
| 332 |
+ if containers[0].Id != container.Id {
|
|
| 333 |
+ t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.Id, containers[0].Id)
|
|
| 334 | 334 |
} |
| 335 | 335 |
} |
| 336 | 336 |
|
| ... | ... |
@@ -1194,7 +1190,7 @@ func TestDeleteContainers(t *testing.T) {
|
| 1194 | 1194 |
|
| 1195 | 1195 |
func TestDeleteImages(t *testing.T) {
|
| 1196 | 1196 |
//FIXME: Implement this test |
| 1197 |
- t.Skip("Test not implemented")
|
|
| 1197 |
+ t.Log("Test not implemented")
|
|
| 1198 | 1198 |
} |
| 1199 | 1199 |
|
| 1200 | 1200 |
// Mocked types for tests |
| ... | ... |
@@ -708,9 +708,6 @@ func CmdImages(args ...string) error {
|
| 708 | 708 |
if cmd.NArg() == 1 {
|
| 709 | 709 |
v.Set("filter", cmd.Arg(0))
|
| 710 | 710 |
} |
| 711 |
- if *quiet {
|
|
| 712 |
- v.Set("only_ids", "1")
|
|
| 713 |
- } |
|
| 714 | 711 |
if *all {
|
| 715 | 712 |
v.Set("all", "1")
|
| 716 | 713 |
} |
| ... | ... |
@@ -732,6 +729,13 @@ func CmdImages(args ...string) error {
|
| 732 | 732 |
} |
| 733 | 733 |
|
| 734 | 734 |
for _, out := range outs {
|
| 735 |
+ if out.Repository == "" {
|
|
| 736 |
+ out.Repository = "<none>" |
|
| 737 |
+ } |
|
| 738 |
+ if out.Tag == "" {
|
|
| 739 |
+ out.Tag = "<none>" |
|
| 740 |
+ } |
|
| 741 |
+ |
|
| 735 | 742 |
if !*quiet {
|
| 736 | 743 |
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)))) |
| 737 | 744 |
} else {
|
| ... | ... |
@@ -763,15 +767,9 @@ func CmdPs(args ...string) error {
|
| 763 | 763 |
if *last == -1 && *nLatest {
|
| 764 | 764 |
*last = 1 |
| 765 | 765 |
} |
| 766 |
- if *quiet {
|
|
| 767 |
- v.Set("only_ids", "1")
|
|
| 768 |
- } |
|
| 769 | 766 |
if *all {
|
| 770 | 767 |
v.Set("all", "1")
|
| 771 | 768 |
} |
| 772 |
- if *noTrunc {
|
|
| 773 |
- v.Set("trunc_cmd", "0")
|
|
| 774 |
- } |
|
| 775 | 769 |
if *last != -1 {
|
| 776 | 770 |
v.Set("limit", strconv.Itoa(*last))
|
| 777 | 771 |
} |
| ... | ... |
@@ -799,9 +797,17 @@ func CmdPs(args ...string) error {
|
| 799 | 799 |
|
| 800 | 800 |
for _, out := range outs {
|
| 801 | 801 |
if !*quiet {
|
| 802 |
- 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) |
|
| 802 |
+ if *noTrunc {
|
|
| 803 |
+ 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) |
|
| 804 |
+ } else {
|
|
| 805 |
+ 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) |
|
| 806 |
+ } |
|
| 803 | 807 |
} else {
|
| 804 |
- fmt.Fprintln(w, out.Id) |
|
| 808 |
+ if *noTrunc {
|
|
| 809 |
+ fmt.Fprintln(w, out.Id) |
|
| 810 |
+ } else {
|
|
| 811 |
+ fmt.Fprintln(w, TruncateId(out.Id)) |
|
| 812 |
+ } |
|
| 805 | 813 |
} |
| 806 | 814 |
} |
| 807 | 815 |
|
| ... | ... |
@@ -28,7 +28,7 @@ List containers |
| 28 | 28 |
|
| 29 | 29 |
.. sourcecode:: http |
| 30 | 30 |
|
| 31 |
- GET /containers/ps?trunc_cmd=0&all=1&only_ids=0&before=8dfafdbc3a40 HTTP/1.1 |
|
| 31 |
+ GET /containers/ps?trunc_cmd=0&all=1&before=8dfafdbc3a40 HTTP/1.1 |
|
| 32 | 32 |
|
| 33 | 33 |
**Example response**: |
| 34 | 34 |
|
| ... | ... |
@@ -68,9 +68,7 @@ List containers |
| 68 | 68 |
} |
| 69 | 69 |
] |
| 70 | 70 |
|
| 71 |
- :query only_ids: 1 or 0, Only display numeric IDs. Default 0 |
|
| 72 | 71 |
:query all: 1 or 0, Show all containers. Only running containers are shown by default |
| 73 |
- :query trunc_cmd: 1 or 0, Truncate output. Output is truncated by default |
|
| 74 | 72 |
:query limit: Show ``limit`` last created containers, include non-running ones. |
| 75 | 73 |
:query since: Show only containers created since Id, include non-running ones. |
| 76 | 74 |
:query before: Show only containers created before Id, include non-running ones. |
| ... | ... |
@@ -467,7 +465,7 @@ List Images |
| 467 | 467 |
|
| 468 | 468 |
.. sourcecode:: http |
| 469 | 469 |
|
| 470 |
- GET /images/json?all=0&only_ids=0 HTTP/1.1 |
|
| 470 |
+ GET /images/json?all=0 HTTP/1.1 |
|
| 471 | 471 |
|
| 472 | 472 |
**Example response**: |
| 473 | 473 |
|
| ... | ... |
@@ -523,7 +521,6 @@ List Images |
| 523 | 523 |
base [style=invisible] |
| 524 | 524 |
} |
| 525 | 525 |
|
| 526 |
- :query only_ids: 1 or 0, Only display numeric IDs. Default 0 |
|
| 527 | 526 |
:query all: 1 or 0, Show all containers. Only running containers are shown by default |
| 528 | 527 |
:statuscode 200: no error |
| 529 | 528 |
:statuscode 500: server error |
| ... | ... |
@@ -135,7 +135,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
| 135 | 135 |
return nil |
| 136 | 136 |
} |
| 137 | 137 |
|
| 138 |
-func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error) {
|
|
| 138 |
+func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
| 139 | 139 |
var allImages map[string]*Image |
| 140 | 140 |
var err error |
| 141 | 141 |
if all {
|
| ... | ... |
@@ -159,29 +159,19 @@ func (srv *Server) Images(all, only_ids bool, filter string) ([]ApiImages, error |
| 159 | 159 |
continue |
| 160 | 160 |
} |
| 161 | 161 |
delete(allImages, id) |
| 162 |
- if !only_ids {
|
|
| 163 |
- out.Repository = name |
|
| 164 |
- out.Tag = tag |
|
| 165 |
- out.Id = TruncateId(id) |
|
| 166 |
- out.Created = image.Created.Unix() |
|
| 167 |
- } else {
|
|
| 168 |
- out.Id = image.ShortId() |
|
| 169 |
- } |
|
| 162 |
+ out.Repository = name |
|
| 163 |
+ out.Tag = tag |
|
| 164 |
+ out.Id = image.ShortId() |
|
| 165 |
+ out.Created = image.Created.Unix() |
|
| 170 | 166 |
outs = append(outs, out) |
| 171 | 167 |
} |
| 172 | 168 |
} |
| 173 | 169 |
// Display images which aren't part of a |
| 174 | 170 |
if filter == "" {
|
| 175 |
- for id, image := range allImages {
|
|
| 171 |
+ for _, image := range allImages {
|
|
| 176 | 172 |
var out ApiImages |
| 177 |
- if !only_ids {
|
|
| 178 |
- out.Repository = "<none>" |
|
| 179 |
- out.Tag = "<none>" |
|
| 180 |
- out.Id = TruncateId(id) |
|
| 181 |
- out.Created = image.Created.Unix() |
|
| 182 |
- } else {
|
|
| 183 |
- out.Id = image.ShortId() |
|
| 184 |
- } |
|
| 173 |
+ out.Id = image.ShortId() |
|
| 174 |
+ out.Created = image.Created.Unix() |
|
| 185 | 175 |
outs = append(outs, out) |
| 186 | 176 |
} |
| 187 | 177 |
} |
| ... | ... |
@@ -235,7 +225,7 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
| 235 | 235 |
return nil, fmt.Errorf("No such container: %s", name)
|
| 236 | 236 |
} |
| 237 | 237 |
|
| 238 |
-func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, before string) []ApiContainers {
|
|
| 238 |
+func (srv *Server) Containers(all bool, n int, since, before string) []ApiContainers {
|
|
| 239 | 239 |
var foundBefore bool |
| 240 | 240 |
var displayed int |
| 241 | 241 |
retContainers := []ApiContainers{}
|
| ... | ... |
@@ -264,23 +254,11 @@ func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, befor |
| 264 | 264 |
c := ApiContainers{
|
| 265 | 265 |
Id: container.Id, |
| 266 | 266 |
} |
| 267 |
- if trunc_cmd {
|
|
| 268 |
- c = ApiContainers{
|
|
| 269 |
- Id: container.ShortId(), |
|
| 270 |
- } |
|
| 271 |
- } |
|
| 272 |
- |
|
| 273 |
- if !only_ids {
|
|
| 274 |
- command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
|
| 275 |
- if trunc_cmd {
|
|
| 276 |
- command = Trunc(command, 20) |
|
| 277 |
- } |
|
| 278 |
- c.Image = srv.runtime.repositories.ImageName(container.Image) |
|
| 279 |
- c.Command = command |
|
| 280 |
- c.Created = container.Created.Unix() |
|
| 281 |
- c.Status = container.State.String() |
|
| 282 |
- c.Ports = container.NetworkSettings.PortMappingHuman() |
|
| 283 |
- } |
|
| 267 |
+ c.Image = srv.runtime.repositories.ImageName(container.Image) |
|
| 268 |
+ c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
|
| 269 |
+ c.Created = container.Created.Unix() |
|
| 270 |
+ c.Status = container.State.String() |
|
| 271 |
+ c.Ports = container.NetworkSettings.PortMappingHuman() |
|
| 284 | 272 |
retContainers = append(retContainers, c) |
| 285 | 273 |
} |
| 286 | 274 |
return retContainers |