Skip to content

Commit

Permalink
Fix service inspect --pretty.
Browse files Browse the repository at this point in the history
Signed-off-by: Dong Chen <[email protected]>
(cherry picked from commit 08ae4e5)
Signed-off-by: Tibor Vass <[email protected]>
  • Loading branch information
dongluochen authored and Tibor Vass committed Jul 26, 2016
1 parent a89bd71 commit a769e22
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions api/client/service/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func printService(out io.Writer, service swarm.Service) {
}
}
fmt.Fprintln(out, "Placement:")
fmt.Fprintln(out, " Strategy:\tSpread")
if service.Spec.TaskTemplate.Placement != nil && len(service.Spec.TaskTemplate.Placement.Constraints) > 0 {
ioutils.FprintfIfNotEmpty(out, " Constraints\t: %s\n", strings.Join(service.Spec.TaskTemplate.Placement.Constraints, ", "))
}
Expand All @@ -114,24 +113,23 @@ func printService(out io.Writer, service swarm.Service) {
fmt.Fprintf(out, "ContainerSpec:\n")
printContainerSpec(out, service.Spec.TaskTemplate.ContainerSpec)

if service.Spec.TaskTemplate.Resources != nil {
resources := service.Spec.TaskTemplate.Resources
if resources != nil {
fmt.Fprintln(out, "Resources:")
printResources := func(out io.Writer, r *swarm.Resources) {
printResources := func(out io.Writer, requirement string, r *swarm.Resources) {
if r == nil || (r.MemoryBytes == 0 && r.NanoCPUs == 0) {
return
}
fmt.Fprintf(out, " %s:\n", requirement)
if r.NanoCPUs != 0 {
fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9)
fmt.Fprintf(out, " CPU:\t\t%g\n", float64(r.NanoCPUs)/1e9)
}
if r.MemoryBytes != 0 {
fmt.Fprintf(out, " Memory:\t\t%s\n", units.BytesSize(float64(r.MemoryBytes)))
fmt.Fprintf(out, " Memory:\t%s\n", units.BytesSize(float64(r.MemoryBytes)))
}
}
if service.Spec.TaskTemplate.Resources.Reservations != nil {
fmt.Fprintln(out, "Reservations:")
printResources(out, service.Spec.TaskTemplate.Resources.Reservations)
}
if service.Spec.TaskTemplate.Resources.Limits != nil {
fmt.Fprintln(out, "Limits:")
printResources(out, service.Spec.TaskTemplate.Resources.Limits)
}
printResources(out, "Reservations", resources.Reservations)
printResources(out, "Limits", resources.Limits)
}
if len(service.Spec.Networks) > 0 {
fmt.Fprintf(out, "Networks:")
Expand Down

0 comments on commit a769e22

Please sign in to comment.