mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
cli: display group ports and address in alloc status command output (#6189)
* cli: display group ports and address in alloc status command output * add assertions for port.To = -1 case and convert assertions to testify
This commit is contained in:
@@ -191,6 +191,11 @@ func (c *AllocStatusCommand) Run(args []string) int {
|
||||
}
|
||||
c.Ui.Output(output)
|
||||
|
||||
if len(alloc.AllocatedResources.Shared.Networks) > 0 && alloc.AllocatedResources.Shared.Networks[0].HasPorts() {
|
||||
c.Ui.Output("")
|
||||
c.Ui.Output(formatAllocNetworkInfo(alloc))
|
||||
}
|
||||
|
||||
if short {
|
||||
c.shortTaskStatus(alloc)
|
||||
} else {
|
||||
@@ -299,6 +304,32 @@ func formatAllocBasicInfo(alloc *api.Allocation, client *api.Client, uuidLength
|
||||
return formatKV(basic), nil
|
||||
}
|
||||
|
||||
func formatAllocNetworkInfo(alloc *api.Allocation) string {
|
||||
nw := alloc.AllocatedResources.Shared.Networks[0]
|
||||
addrs := make([]string, len(nw.DynamicPorts)+len(nw.ReservedPorts)+1)
|
||||
addrs[0] = "Label|Dynamic|Address"
|
||||
portFmt := func(port *api.Port, dyn string) string {
|
||||
s := fmt.Sprintf("%s|%s|%s:%d", port.Label, dyn, nw.IP, port.Value)
|
||||
if port.To > 0 {
|
||||
s += fmt.Sprintf(" -> %d", port.To)
|
||||
}
|
||||
return s
|
||||
}
|
||||
for idx, port := range nw.DynamicPorts {
|
||||
addrs[idx+1] = portFmt(&port, "yes")
|
||||
}
|
||||
for idx, port := range nw.ReservedPorts {
|
||||
addrs[idx+1+len(nw.DynamicPorts)] = portFmt(&port, "yes")
|
||||
}
|
||||
|
||||
var mode string
|
||||
if nw.Mode != "" {
|
||||
mode = fmt.Sprintf(" (mode = %q)", nw.Mode)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Allocation Addresses%s\n%s", mode, formatList(addrs))
|
||||
}
|
||||
|
||||
// futureEvalTimePretty returns when the eval is eligible to reschedule
|
||||
// relative to current time, based on the WaitUntil field
|
||||
func futureEvalTimePretty(evalID string, client *api.Client) string {
|
||||
|
||||
Reference in New Issue
Block a user