forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect_release.go
88 lines (72 loc) · 2.13 KB
/
inspect_release.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
86
87
88
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 InspectReleaseCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewInspectReleaseCmd(ui boshui.UI, director boshdir.Director) InspectReleaseCmd {
return InspectReleaseCmd{ui: ui, director: director}
}
func (c InspectReleaseCmd) Run(opts InspectReleaseOpts) error {
release, err := c.director.FindRelease(opts.Args.Slug)
if err != nil {
return err
}
jobsTable := boshtbl.Table{
Content: "jobs",
Header: []string{"Job", "Blobstore ID", "Digest", "Links Consumed", "Links Provided"},
SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}},
}
jobs, err := release.Jobs()
if err != nil {
return err
}
for _, j := range jobs {
jobsTable.Rows = append(jobsTable.Rows, []boshtbl.Value{
boshtbl.NewValueString(fmt.Sprintf("%s/%s", j.Name, j.Fingerprint)),
boshtbl.NewValueString(j.BlobstoreID),
boshtbl.NewValueString(j.SHA1),
boshtbl.NewValueInterface(j.LinksConsumed),
boshtbl.NewValueInterface(j.LinksProvided),
})
}
pkgsTable := boshtbl.Table{
Content: "packages",
Header: []string{"Package", "Compiled for", "Blobstore ID", "Digest"},
SortBy: []boshtbl.ColumnSort{{Column: 0, Asc: true}},
}
pkgs, err := release.Packages()
if err != nil {
return err
}
for _, p := range pkgs {
section := boshtbl.Section{
FirstColumn: boshtbl.NewValueString(fmt.Sprintf("%s/%s", p.Name, p.Fingerprint)),
Rows: [][]boshtbl.Value{
{
boshtbl.NewValueString(""),
boshtbl.NewValueString("(source)"),
boshtbl.NewValueString(p.BlobstoreID),
boshtbl.NewValueString(p.SHA1),
},
},
}
for _, cp := range p.CompiledPackages {
section.Rows = append(section.Rows, []boshtbl.Value{
boshtbl.NewValueString(""),
boshtbl.NewValueString(cp.StemcellSlug.String()),
boshtbl.NewValueString(cp.BlobstoreID),
boshtbl.NewValueString(cp.SHA1),
})
}
pkgsTable.Sections = append(pkgsTable.Sections, section)
}
c.ui.PrintTable(jobsTable)
c.ui.PrintTable(pkgsTable)
return nil
}