Skip to content

Commit

Permalink
Implement PrettyPrint on brain.Disc
Browse files Browse the repository at this point in the history
  • Loading branch information
telyn committed Jan 26, 2017
1 parent fef61ab commit effbfd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/brain/disc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package brain

import (
"github.com/BytemarkHosting/bytemark-client/lib/prettyprint"
"io"
)

// Disc is a representation of a VM's disc.
type Disc struct {
Label string `json:"label"`
Expand All @@ -11,6 +16,13 @@ type Disc struct {
StoragePool string `json:"storage_pool,omitempty"`
}

func (d Disc) PrettyPrint(wr io.Writer, detail prettyprint.DetailLevel) error {
tmpl := `{{ define "disc_sgl" }}{{ .Label }} - {{ gibtib .Size }}, {{ .StorageGrade }} grade{{ end }}
{{ define "disc_medium" }}{{ template "_sgl" . }}{{ end }}
{{ define "disc_full" }}{{ template "_medium" . }}{{ end }}`
return prettyprint.Run(wr, tmpl, "disc"+string(detail), d)
}

// Validate makes sure the disc has a storage grade. Doesn't modify the origin disc.
func (disc Disc) Validate() (*Disc, error) {
if disc.StorageGrade == "" {
Expand Down
4 changes: 2 additions & 2 deletions lib/brain/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func (vm VirtualMachine) PrettyPrint(wr io.Writer, detail prettyprint.DetailLeve
const template = `{{ define "server_sgl" }} ▸ {{.ShortName }} ({{ if .Deleted }}deleted{{ else if .PowerOn }}powered on{{else}}powered off{{end}}) in {{capitalize .ZoneName}}{{ end }}
{{ define "server_spec" }} {{ .PrimaryIP }} - {{ pluralize "core" "cores" .Cores }}, {{ mibgib .Memory }}, {{ if .Discs}}{{.TotalDiscSize "" | gibtib }} on {{ len .Discs | pluralize "disc" "discs" }}{{ else }}no discs{{ end }}{{ end }}
{{ define "server_discs" -}}
{{ define "server_discs" }}
{{- if .Discs }} discs:
{{- range .Discs }}
• {{ .Label }} - {{ gibtib .Size }}, {{ .StorageGrade }} grade
• {{ prettysprint . "_sgl" -}}
{{- end }}
{{ end -}}
Expand Down

0 comments on commit effbfd6

Please sign in to comment.