forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instances.go
74 lines (56 loc) · 1.48 KB
/
instances.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cmd
import (
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type InstancesCmd struct {
ui boshui.UI
deployment boshdir.Deployment
}
func NewInstancesCmd(ui boshui.UI, deployment boshdir.Deployment) InstancesCmd {
return InstancesCmd{ui: ui, deployment: deployment}
}
func (c InstancesCmd) Run(opts InstancesOpts) error {
instanceInfos, err := c.deployment.InstanceInfos()
if err != nil {
return err
}
instTable := InstanceTable{
Processes: opts.Processes,
Details: opts.Details,
DNS: opts.DNS,
Vitals: opts.Vitals,
}
table := boshtbl.Table{
Content: "instances",
HeaderVals: instTable.AsValues(instTable.Header()),
SortBy: []boshtbl.ColumnSort{
{Column: 0, Asc: true},
{Column: 1, Asc: true}, // sort by process so that VM row is first
},
Notes: []string{""},
}
for _, info := range instanceInfos {
if opts.Failing && info.IsRunning() {
continue
}
row := instTable.AsValues(instTable.ForVMInfo(info))
section := boshtbl.Section{
FirstColumn: row[0],
Rows: [][]boshtbl.Value{row},
}
if opts.Processes {
for _, p := range info.Processes {
if opts.Failing && p.IsRunning() {
continue
}
row := instTable.AsValues(instTable.ForProcess(p))
section.Rows = append(section.Rows, row)
}
}
table.Sections = append(table.Sections, section)
}
c.ui.PrintTable(table)
return nil
}