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