Skip to content

Commit 849b3fc

Browse files
authored
incorporate org quota (#101)
1 parent ebb82fe commit 849b3fc

File tree

12 files changed

+88
-70
lines changed

12 files changed

+88
-70
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ This example is going to be a bit cluttered, so it's recommended using `jq` to p
7171
"summary_report": {
7272
"org_reports": [
7373
{
74+
"org_quota": {
75+
"name": "voyager",
76+
"total_services": -1,
77+
"total_routes": -1,
78+
"total_private_domains": -1,
79+
"memory_limit": 83968,
80+
"instance_memory_limit": -1,
81+
"app_instance_limit": 38,
82+
"app_task_limit": -1,
83+
"total_service_keys": -1,
84+
"total_reserved_route_ports": -1
85+
},
7486
"app_instances_count": 37,
7587
"apps_count": 28,
7688
"billable_app_instances_count": 40,
@@ -121,6 +133,18 @@ This example is going to be a bit cluttered, so it's recommended using `jq` to p
121133
]
122134
},
123135
{
136+
"org_quota": {
137+
"name": "tenzing",
138+
"total_services": -1,
139+
"total_routes": -1,
140+
"total_private_domains": -1,
141+
"memory_limit": 83968,
142+
"instance_memory_limit": -1,
143+
"app_instance_limit": 0,
144+
"app_task_limit": -1,
145+
"total_service_keys": -1,
146+
"total_reserved_route_ports": -1
147+
},
124148
"app_instances_count": 0,
125149
"apps_count": 21,
126150
"billable_app_instances_count": 5,
@@ -212,13 +236,13 @@ If you want to try it out, install it directly from [the github releases tab as
212236

213237
```sh
214238
# osx 64bit
215-
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.0.0/cf-report-usage-plugin-darwin
239+
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.1.0/cf-report-usage-plugin-darwin
216240

217241
# linux 64bit (32bit and ARM6 also available)
218-
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.0.0/cf-report-usage-plugin-linux-amd64
242+
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.1.0/cf-report-usage-plugin-linux-amd64
219243

220244
# windows 64bit (32bit also available)
221-
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.0.0/cf-report-usage-plugin-windows-amd64.exe
245+
cf install-plugin -f https://github.com/aegershman/cf-report-usage-plugin/releases/download/3.1.0/cf-report-usage-plugin-windows-amd64.exe
222246
```
223247

224248
## backwards compatibility

Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ tasks:
2323
- cf report-usage -o voyager -o tenzing --format string
2424
- cf report-usage -o voyager -o tenzing --format table
2525
- cf report-usage -o voyager -o tenzing --format json
26+
# TODO will remove this last line, shouldn't be displayed in README
27+
- cf report-usage -o voyager -o tenzing --format table-org-quota
2628
- task: uninstall

cmd/reportusage/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func (cmd *reportUsageCmd) GetMetadata() plugin.PluginMetadata {
7575
Name: "cf-report-usage-plugin",
7676
Version: plugin.VersionType{
7777
Major: 3,
78-
Minor: 0,
79-
Build: 1,
78+
Minor: 1,
79+
Build: 0,
8080
},
8181
Commands: []plugin.Command{
8282
{

internal/presentation/presenter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ func NewPresenter(r report.SummaryReport, format string) Presenter {
2121
// Render -
2222
func (p *Presenter) Render() {
2323
switch p.Format {
24+
case "json":
25+
p.asJSON()
2426
case "string":
2527
p.asString()
28+
case "table-org-quota": // again, TODO, bleh
29+
p.asTableOrgQuota()
2630
case "table":
2731
p.asTable()
28-
case "json":
29-
p.asJSON()
3032
default:
3133
// TODO
3234
// yeah this is kind of awful I know, I'm sorry, I'm still learning,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package presentation
2+
3+
import (
4+
"os"
5+
"strconv"
6+
7+
"github.com/olekukonko/tablewriter"
8+
)
9+
10+
// TODO this is ugly as sin, I know, it's temporary
11+
// I just need to get this out for working on a project
12+
func (p *Presenter) asTableOrgQuota() {
13+
table := tablewriter.NewWriter(os.Stdout)
14+
table.SetAlignment(tablewriter.ALIGN_CENTER)
15+
table.SetHeader([]string{
16+
"Org",
17+
"AI Quota",
18+
"Deployed AIs",
19+
"Running AIs",
20+
"Stopped AIs",
21+
})
22+
23+
for _, orgReport := range p.SummaryReport.OrgReports {
24+
table.Append([]string{
25+
orgReport.Name,
26+
strconv.Itoa(orgReport.OrgQuota.AppInstanceLimit),
27+
strconv.Itoa(orgReport.AppInstancesCount),
28+
strconv.Itoa(orgReport.RunningAppInstancesCount),
29+
strconv.Itoa(orgReport.StoppedAppInstancesCount),
30+
})
31+
}
32+
33+
table.SetFooter([]string{
34+
"Total",
35+
"-",
36+
strconv.Itoa(p.SummaryReport.AppInstancesCount),
37+
strconv.Itoa(p.SummaryReport.RunningAppInstancesCount),
38+
strconv.Itoa(p.SummaryReport.StoppedAppInstancesCount),
39+
})
40+
41+
table.Render()
42+
43+
}

internal/report/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func (r *Client) GetSummaryReportByOrgNames(orgNames []string) (*SummaryReport,
2727
var orgReports []OrgReport
2828
for _, org := range populatedOrgs {
2929
spaceReports := r.getSpaceReportsByOrg(org)
30-
orgReport := *NewOrgReport(org, spaceReports)
30+
orgQuota, _ := r.client.OrgQuotas.GetOrgQuota(org.QuotaURL)
31+
orgReport := *NewOrgReport(orgQuota, org, spaceReports)
3132
orgReports = append(orgReports, orgReport)
3233
}
3334

@@ -92,10 +93,13 @@ func (r *Client) getOrgDetails(o v2client.Org) (v2client.Org, error) {
9293
}
9394

9495
return v2client.Org{
95-
Name: o.Name,
9696
MemoryQuota: quota.MemoryLimit,
9797
MemoryUsage: int(usage),
98+
Name: o.Name,
99+
QuotaURL: o.QuotaURL,
98100
Spaces: spaces,
101+
SpacesURL: o.SpacesURL,
102+
URL: o.URL,
99103
}, nil
100104
}
101105

internal/report/fixtures/result.csv

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)