diff --git a/api/resources.go b/api/resources.go index 11b00befc..8cb2505ba 100644 --- a/api/resources.go +++ b/api/resources.go @@ -22,5 +22,6 @@ type NetworkResource struct { CIDR string ReservedPorts []Port DynamicPorts []Port + IP string MBits int } diff --git a/command/alloc_status.go b/command/alloc_status.go index 7bb1761ae..ecba378f9 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -149,7 +149,7 @@ func (c *AllocStatusCommand) Run(args []string) int { dumpAllocStatus(c.Ui, alloc, length) if !short { - c.Ui.Output("\n==> Resources") + c.Ui.Output("\n==> Task Resources") c.taskResources(alloc) } @@ -264,8 +264,8 @@ func (c *AllocStatusCommand) sortedTaskStateIterator(m map[string]*api.TaskState return output } -// taskResources prints out the tasks current resource usage -func (c *AllocStatusCommand) taskResources(alloc *api.Allocation) { +// allocResources prints out the allocation current resource usage +func (c *AllocStatusCommand) allocResources(alloc *api.Allocation) { resources := make([]string, 2) resources[0] = "CPU|Memory MB|Disk MB|IOPS" resources[1] = fmt.Sprintf("%v|%v|%v|%v", @@ -275,3 +275,39 @@ func (c *AllocStatusCommand) taskResources(alloc *api.Allocation) { alloc.Resources.IOPS) c.Ui.Output(formatList(resources)) } + +// taskResources prints out the tasks current resource usage +func (c *AllocStatusCommand) taskResources(alloc *api.Allocation) { + firstLine := true + for task, resource := range alloc.TaskResources { + header := fmt.Sprintf("\nTask: %q", task) + if firstLine { + header = fmt.Sprintf("Task: %q", task) + firstLine = false + } + c.Ui.Output(header) + var addr []string + for _, nw := range resource.Networks { + ports := append(nw.DynamicPorts, nw.ReservedPorts...) + for _, port := range ports { + addr = append(addr, fmt.Sprintf("%v: %v:%v\n", port.Label, nw.IP, port.Value)) + } + } + var resourcesOutput []string + resourcesOutput = append(resourcesOutput, "CPU|Memory MB|Disk MB|IOPS|Addresses") + firstAddr := "" + if len(addr) > 0 { + firstAddr = addr[0] + } + resourcesOutput = append(resourcesOutput, fmt.Sprintf("%v|%v|%v|%v|%v", + resource.CPU, + resource.MemoryMB, + resource.DiskMB, + resource.IOPS, + firstAddr)) + for i := 1; i < len(addr); i++ { + resourcesOutput = append(resourcesOutput, fmt.Sprintf("||||%v", addr[i])) + } + c.Ui.Output(formatListWithSpaces(resourcesOutput)) + } +} diff --git a/command/helpers.go b/command/helpers.go index c03ba3cbd..e48542f9a 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -24,6 +24,14 @@ func formatList(in []string) string { return columnize.Format(in, columnConf) } +// formatListWithSpaces takes a set of strings and formats them into properly +// aligned output. It should be used sparingly since it doesn't replace empty +// values and hence not awk/sed friendly +func formatListWithSpaces(in []string) string { + columnConf := columnize.DefaultConfig() + return columnize.Format(in, columnConf) +} + // Limits the length of the string. func limit(s string, length int) string { if len(s) < length {