-
Notifications
You must be signed in to change notification settings - Fork 162
/
vms.go
85 lines (63 loc) · 1.59 KB
/
vms.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
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
"fmt"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type VMsCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewVMsCmd(ui boshui.UI, director boshdir.Director) VMsCmd {
return VMsCmd{ui: ui, director: director}
}
func (c VMsCmd) Run(opts VMsOpts) error {
instTable := InstanceTable{
// VMs command should always show VM specifics
VMDetails: true,
Details: false,
DNS: opts.DNS,
Vitals: opts.Vitals,
}
if len(opts.Deployment) > 0 {
dep, err := c.director.FindDeployment(opts.Deployment)
if err != nil {
return err
}
return c.printDeployment(dep, instTable)
}
return c.printDeployments(instTable)
}
func (c VMsCmd) printDeployments(instTable InstanceTable) error {
deployments, err := c.director.Deployments()
if err != nil {
return err
}
for _, dep := range deployments {
err := c.printDeployment(dep, instTable)
if err != nil {
return err
}
}
return nil
}
func (c VMsCmd) printDeployment(dep boshdir.Deployment, instTable InstanceTable) error {
vmInfos, err := dep.VMInfos()
if err != nil {
return err
}
table := boshtbl.Table{
Title: fmt.Sprintf("Deployment '%s'", dep.Name()),
Content: "vms",
HeaderVals: instTable.AsValues(instTable.Header()),
SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}},
Notes: []string{""},
}
for _, info := range vmInfos {
row := instTable.AsValues(instTable.ForVMInfo(info))
table.Rows = append(table.Rows, row)
}
c.ui.PrintTable(table)
return nil
}