@@ -18,11 +18,6 @@ func NewVMsCmd(ui boshui.UI, director boshdir.Director) VMsCmd {
1818}
1919
2020func (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