MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runNodesList

Function runNodesList

internal/cli/nodes.go:83–127  ·  view source on GitHub ↗
(cmd *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

81}
82
83func runNodesList(cmd *cobra.Command, _ []string) error {
84 session, err := initCLISession(cmd)
85 if err != nil {
86 return printError(err)
87 }
88
89 if session == nil {
90 return nil
91 }
92
93 nodes, err := session.getNodes(context.Background())
94 if err != nil {
95 return printError(fmt.Errorf("failed to fetch nodes: %w", err))
96 }
97
98 out := make([]nodeOutput, 0, len(nodes))
99 for _, n := range nodes {
100 if n != nil {
101 out = append(out, nodeToOutput(n))
102 }
103 }
104
105 if getOutputFormat(cmd) == outputTable {
106 headers := []string{"NAME", "IP", "STATUS", "CPU%", "MEM USED", "MEM TOTAL", "UPTIME"}
107 rows := make([][]string, 0, len(out))
108
109 for _, n := range out {
110 rows = append(rows, []string{
111 n.Name,
112 n.IP,
113 onlineStr(n.Online),
114 fmt.Sprintf("%.1f%%", n.CPUUsage*100),
115 formatBytes(int64(n.MemoryUsed)),
116 formatBytes(int64(n.MemoryTotal)),
117 formatUptime(n.Uptime),
118 })
119 }
120
121 printTable(headers, rows)
122
123 return nil
124 }
125
126 return printJSON(out)
127}
128
129func newNodesShowCmd() *cobra.Command {
130 return &cobra.Command{

Callers

nothing calls this directly

Calls 10

initCLISessionFunction · 0.85
printErrorFunction · 0.85
nodeToOutputFunction · 0.85
getOutputFormatFunction · 0.85
onlineStrFunction · 0.85
formatBytesFunction · 0.85
formatUptimeFunction · 0.85
printTableFunction · 0.85
printJSONFunction · 0.85
getNodesMethod · 0.80

Tested by

no test coverage detected