Skip to content

Commit de8a341

Browse files
committed
allows vms command to filter by deployment via -d
1 parent 35caccf commit de8a341

File tree

5 files changed

+430
-308
lines changed

5 files changed

+430
-308
lines changed

cmd/factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func (f Factory) New(args []string) (Cmd, error) {
4747
opts.Deployment = boshOpts.DeploymentOpt
4848
}
4949

50+
if opts, ok := command.(*VMsOpts); ok {
51+
opts.Deployment = boshOpts.DeploymentOpt
52+
}
53+
5054
if opts, ok := command.(*TasksOpts); ok {
5155
opts.Deployment = boshOpts.DeploymentOpt
5256
}

cmd/factory_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ var _ = Describe("Factory", func() {
186186
})
187187
})
188188

189+
Describe("vms command", func() {
190+
It("is passed the deployment flag", func() {
191+
cmd, err := factory.New([]string{"vms", "--deployment", "deployment"})
192+
Expect(err).ToNot(HaveOccurred())
193+
194+
opts := cmd.Opts.(*VMsOpts)
195+
Expect(opts.Deployment).To(Equal("deployment"))
196+
})
197+
})
198+
189199
Describe("tasks command", func() {
190200
It("is passed the deployment flag", func() {
191201
cmd, err := factory.New([]string{"tasks", "--deployment", "deployment"})

cmd/opts.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,10 @@ type InstancesOpts struct {
510510
}
511511

512512
type VMsOpts struct {
513-
Details bool `long:"details" short:"i" description:"Show details including VM CID, persistent disk CID, etc."`
514-
DNS bool `long:"dns" description:"Show DNS A records"`
515-
Vitals bool `long:"vitals" description:"Show vitals"`
513+
Details bool `long:"details" short:"i" description:"Show details including VM CID, persistent disk CID, etc."`
514+
DNS bool `long:"dns" description:"Show DNS A records"`
515+
Vitals bool `long:"vitals" description:"Show vitals"`
516+
Deployment string
516517
cmd
517518
}
518519

cmd/vms.go

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ func NewVMsCmd(ui boshui.UI, director boshdir.Director) VMsCmd {
1818
}
1919

2020
func (c VMsCmd) Run(opts VMsOpts) error {
21-
deployments, err := c.director.Deployments()
22-
if err != nil {
23-
return err
24-
}
25-
2621
instTable := InstanceTable{
2722
// VMs command should always show VM specifics
2823
VMDetails: true,
@@ -32,32 +27,59 @@ func (c VMsCmd) Run(opts VMsOpts) error {
3227
Vitals: opts.Vitals,
3328
}
3429

30+
if len(opts.Deployment) > 0 {
31+
dep, err := c.director.FindDeployment(opts.Deployment)
32+
if err != nil {
33+
return err
34+
}
35+
36+
return c.printDeployment(dep, instTable)
37+
}
38+
39+
return c.printDeployments(instTable)
40+
}
41+
42+
func (c VMsCmd) printDeployments(instTable InstanceTable) error {
43+
deployments, err := c.director.Deployments()
44+
if err != nil {
45+
return err
46+
}
47+
3548
for _, dep := range deployments {
36-
vmInfos, err := dep.VMInfos()
49+
err := c.printDeployment(dep, instTable)
3750
if err != nil {
3851
return err
3952
}
53+
}
54+
55+
return nil
56+
}
4057

41-
table := boshtbl.Table{
42-
Title: fmt.Sprintf("Deployment '%s'", dep.Name()),
58+
func (c VMsCmd) printDeployment(dep boshdir.Deployment, instTable InstanceTable) error {
59+
vmInfos, err := dep.VMInfos()
60+
if err != nil {
61+
return err
62+
}
4363

44-
Content: "vms",
64+
table := boshtbl.Table{
65+
Title: fmt.Sprintf("Deployment '%s'", dep.Name()),
4566

46-
HeaderVals: instTable.AsValues(instTable.Header()),
67+
Content: "vms",
4768

48-
SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}},
69+
HeaderVals: instTable.AsValues(instTable.Header()),
4970

50-
Notes: []string{"(*) Bootstrap node"},
51-
}
71+
SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}},
5272

53-
for _, info := range vmInfos {
54-
row := instTable.AsValues(instTable.ForVMInfo(info))
73+
Notes: []string{"(*) Bootstrap node"},
74+
}
5575

56-
table.Rows = append(table.Rows, row)
57-
}
76+
for _, info := range vmInfos {
77+
row := instTable.AsValues(instTable.ForVMInfo(info))
5878

59-
c.ui.PrintTable(table)
79+
table.Rows = append(table.Rows, row)
6080
}
6181

82+
c.ui.PrintTable(table)
83+
6284
return nil
6385
}

0 commit comments

Comments
 (0)