Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion internal/carrel/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
// share. A tenant is named only when its slug is already public: it is
// active and serves at least one ready *.<slug>.winlab.tw domain. Every
// other tenant with machines is summed into "others" without a name.
// Machine names, addresses, keys and domains are never listed.
// Machine names, addresses, keys and domains are never listed. "quota" is
// the default budget: every member gets one, and every project group gets
// another of its own on top of its members' budgets.
func (e *Execution) PublicStatus() D {
c := e.Capacity(nil, true)
physical := obj(c["physical"])
Expand Down Expand Up @@ -55,11 +57,22 @@ func (e *Execution) PublicStatus() D {
"disk_gib": D{"total": disk["total"], "used": disk["used"]},
},
"allocated": c["allocatable"],
"quota": D{"member": budget(DefaultQuota), "project": budget(DefaultQuota)},
"tenants": tenants,
"others": others,
}
}

// budget is the part of a quota the status page shows.
func budget(q D) D {
return D{
"machines": num(q["machines"]),
"vcpu": num(q["vcpu"]),
"memory_gib": num(q["memory_mb"]) / 1024,
"disk_gib": num(q["disk_gb"]),
}
}

// publicSlug reports whether a tenant's slug is already published by one of
// its domains.
func publicSlug(domains []D) bool {
Expand Down
4 changes: 4 additions & 0 deletions internal/carrel/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestPublicStatusNamesOnlyTenantsWithAPublicDomain(t *testing.T) {
if num(others["tenants"]) != 2 || num(others["machines"]) != 2 || num(others["vcpu"]) != 4 {
t.Fatalf("unexpected others: %s", raw)
}
member := obj(obj(body["quota"])["member"])
if num(member["machines"]) != 8 || num(member["vcpu"]) != 8 || num(member["memory_gib"]) != 16 || num(member["disk_gib"]) != 100 || obj(obj(body["quota"])["project"])["vcpu"] == nil {
t.Fatalf("unexpected quota: %s", raw)
}
node := obj(body["node"])
if num(obj(node["cpu"])["logical_cpus"]) != 32 || num(obj(node["memory_gib"])["total"]) != 192 {
t.Fatalf("unexpected node: %s", raw)
Expand Down
Loading