forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disks.go
57 lines (47 loc) · 1.25 KB
/
disks.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
package cmd
import (
"errors"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type DisksCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewDisksCmd(ui boshui.UI, director boshdir.Director) DisksCmd {
return DisksCmd{ui: ui, director: director}
}
func (c DisksCmd) Run(opts DisksOpts) error {
if !opts.Orphaned {
return errors.New("Only --orphaned is supported")
}
disks, err := c.director.OrphanDisks()
if err != nil {
return err
}
table := boshtbl.Table{
Content: "disks",
Header: []boshtbl.Header{
boshtbl.NewHeader("Disk CID"),
boshtbl.NewHeader("Size"),
boshtbl.NewHeader("Deployment"),
boshtbl.NewHeader("Instance"),
boshtbl.NewHeader("AZ"),
boshtbl.NewHeader("Orphaned At"),
},
SortBy: []boshtbl.ColumnSort{{Column: 5}},
}
for _, d := range disks {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString(d.CID()),
boshtbl.NewValueMegaBytes(d.Size()),
boshtbl.NewValueString(d.Deployment().Name()),
boshtbl.NewValueString(d.InstanceName()),
boshtbl.NewValueString(d.AZName()),
boshtbl.NewValueTime(d.OrphanedAt()),
})
}
c.ui.PrintTable(table)
return nil
}