mirror of https://github.com/docker/docs.git
Merge pull request #1721 from nishanttotla/1625-RemoveInfoBackspaces
Removing backspaces in /info output for new API version
This commit is contained in:
commit
336a4ff9ae
|
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
versionpkg "github.com/docker/docker/pkg/version"
|
||||
apitypes "github.com/docker/engine-api/types"
|
||||
dockerfilters "github.com/docker/engine-api/types/filters"
|
||||
"github.com/docker/swarm/cluster"
|
||||
|
|
@ -31,7 +32,6 @@ const APIVERSION = "1.21"
|
|||
func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
info := apitypes.Info{
|
||||
Images: len(c.cluster.Images().Filter(cluster.ImageFilterOptions{})),
|
||||
DriverStatus: c.statusHandler.Status(),
|
||||
NEventsListener: c.eventsHandler.Size(),
|
||||
Debug: c.debug,
|
||||
MemoryLimit: true,
|
||||
|
|
@ -55,6 +55,21 @@ func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
ExperimentalBuild: experimental.ENABLED,
|
||||
}
|
||||
|
||||
// API versions older than 1.22 use DriverStatus and return \b characters in the output
|
||||
status := c.statusHandler.Status()
|
||||
if c.apiVersion != "" && versionpkg.Version(c.apiVersion).LessThan("1.22") {
|
||||
for i := range status {
|
||||
if status[i][0][:1] == " " {
|
||||
status[i][0] = status[i][0][1:]
|
||||
} else {
|
||||
status[i][0] = "\b" + status[i][0]
|
||||
}
|
||||
}
|
||||
info.DriverStatus = status
|
||||
} else {
|
||||
info.SystemStatus = status
|
||||
}
|
||||
|
||||
if kernelVersion, err := kernel.GetKernelVersion(); err == nil {
|
||||
info.KernelVersion = kernelVersion.String()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ func setupPrimaryRouter(r *mux.Router, context *context, enableCors bool) {
|
|||
if enableCors {
|
||||
writeCorsHeaders(w, r)
|
||||
}
|
||||
context.apiVersion = mux.Vars(r)["version"]
|
||||
localFct(context, w, r)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,9 @@ func TestRequest(t *testing.T) {
|
|||
func TestCorsRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
context := &context{}
|
||||
primary := mux.NewRouter()
|
||||
setupPrimaryRouter(primary, nil, true)
|
||||
setupPrimaryRouter(primary, context, true)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
r, e := http.NewRequest("OPTIONS", "/version", nil)
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@ func (h *statusHandler) Status() [][2]string {
|
|||
|
||||
if h.candidate != nil && !h.candidate.IsLeader() {
|
||||
status = [][2]string{
|
||||
{"\bRole", "replica"},
|
||||
{"\bPrimary", h.follower.Leader()},
|
||||
{"Role", "replica"},
|
||||
{"Primary", h.follower.Leader()},
|
||||
}
|
||||
} else {
|
||||
status = [][2]string{
|
||||
{"\bRole", "primary"},
|
||||
{"Role", "primary"},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -408,17 +408,17 @@ func (c *Cluster) TotalCpus() int64 {
|
|||
func (c *Cluster) Info() [][2]string {
|
||||
offers := c.listOffers()
|
||||
info := [][2]string{
|
||||
{"\bStrategy", c.scheduler.Strategy()},
|
||||
{"\bFilters", c.scheduler.Filters()},
|
||||
{"\bOffers", fmt.Sprintf("%d", len(offers))},
|
||||
{"Strategy", c.scheduler.Strategy()},
|
||||
{"Filters", c.scheduler.Filters()},
|
||||
{"Offers", fmt.Sprintf("%d", len(offers))},
|
||||
}
|
||||
|
||||
sort.Sort(offerSorter(offers))
|
||||
|
||||
for _, offer := range offers {
|
||||
info = append(info, [2]string{" Offer", offer.Id.GetValue()})
|
||||
info = append(info, [2]string{" Offer", offer.Id.GetValue()})
|
||||
for _, resource := range offer.Resources {
|
||||
info = append(info, [2]string{" └ " + resource.GetName(), formatResource(resource)})
|
||||
info = append(info, [2]string{" └ " + resource.GetName(), formatResource(resource)})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -828,32 +828,32 @@ func (c *Cluster) TotalCpus() int64 {
|
|||
// Info returns some info about the cluster, like nb or containers / images
|
||||
func (c *Cluster) Info() [][2]string {
|
||||
info := [][2]string{
|
||||
{"\bStrategy", c.scheduler.Strategy()},
|
||||
{"\bFilters", c.scheduler.Filters()},
|
||||
{"\bNodes", fmt.Sprintf("%d", len(c.engines)+len(c.pendingEngines))},
|
||||
{"Strategy", c.scheduler.Strategy()},
|
||||
{"Filters", c.scheduler.Filters()},
|
||||
{"Nodes", fmt.Sprintf("%d", len(c.engines)+len(c.pendingEngines))},
|
||||
}
|
||||
|
||||
engines := c.listEngines()
|
||||
sort.Sort(cluster.EngineSorter(engines))
|
||||
|
||||
for _, engine := range engines {
|
||||
info = append(info, [2]string{engine.Name, engine.Addr})
|
||||
info = append(info, [2]string{" └ Status", engine.Status()})
|
||||
info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))})
|
||||
info = append(info, [2]string{" └ Reserved CPUs", fmt.Sprintf("%d / %d", engine.UsedCpus(), engine.TotalCpus())})
|
||||
info = append(info, [2]string{" └ Reserved Memory", fmt.Sprintf("%s / %s", units.BytesSize(float64(engine.UsedMemory())), units.BytesSize(float64(engine.TotalMemory())))})
|
||||
info = append(info, [2]string{" " + engine.Name, engine.Addr})
|
||||
info = append(info, [2]string{" └ Status", engine.Status()})
|
||||
info = append(info, [2]string{" └ Containers", fmt.Sprintf("%d", len(engine.Containers()))})
|
||||
info = append(info, [2]string{" └ Reserved CPUs", fmt.Sprintf("%d / %d", engine.UsedCpus(), engine.TotalCpus())})
|
||||
info = append(info, [2]string{" └ Reserved Memory", fmt.Sprintf("%s / %s", units.BytesSize(float64(engine.UsedMemory())), units.BytesSize(float64(engine.TotalMemory())))})
|
||||
labels := make([]string, 0, len(engine.Labels))
|
||||
for k, v := range engine.Labels {
|
||||
labels = append(labels, k+"="+v)
|
||||
}
|
||||
sort.Strings(labels)
|
||||
info = append(info, [2]string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))})
|
||||
info = append(info, [2]string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))})
|
||||
errMsg := engine.ErrMsg()
|
||||
if len(errMsg) == 0 {
|
||||
errMsg = "(none)"
|
||||
}
|
||||
info = append(info, [2]string{" └ Error", errMsg})
|
||||
info = append(info, [2]string{" └ UpdatedAt", engine.UpdatedAt().UTC().Format(time.RFC3339)})
|
||||
info = append(info, [2]string{" └ Error", errMsg})
|
||||
info = append(info, [2]string{" └ UpdatedAt", engine.UpdatedAt().UTC().Format(time.RFC3339)})
|
||||
}
|
||||
|
||||
return info
|
||||
|
|
|
|||
Loading…
Reference in New Issue