DumpDroplet()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-01 04:09:41 -05:00
parent 20e958559e
commit c2e30a373a
1 changed files with 29 additions and 1 deletions

View File

@ -8,9 +8,13 @@ package virtbuf
// are in text columns and rows that can be easily read in a terminal // are in text columns and rows that can be easily read in a terminal
import ( import (
"errors"
"fmt" "fmt"
"net/http"
"strings" "strings"
"time" "time"
"go.wit.com/log"
) )
func oldGetDurationStamp(t time.Time) string { func oldGetDurationStamp(t time.Time) string {
@ -105,7 +109,6 @@ func FormatDuration(d time.Duration) string {
return result return result
} }
func (d *Droplet) SprintHeader() string { func (d *Droplet) SprintHeader() string {
header := fmt.Sprintf("%-3.3s %-9.9s %-20.20s", d.Current.State, d.Current.Hypervisor, d.Hostname) header := fmt.Sprintf("%-3.3s %-9.9s %-20.20s", d.Current.State, d.Current.Hypervisor, d.Hostname)
@ -175,3 +178,28 @@ func (d *Droplet) SprintDumpHeader() string {
} }
return header return header
} }
func (d *Droplet) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
if d == nil {
reason := "DumpDroplet() got d == nil"
log.Warn(reason)
fmt.Fprintln(w, reason)
return "", errors.New(reason)
}
t := d.FormatTEXT()
log.Info(t)
fmt.Fprintln(w, t)
return t, nil
}
func (c *NewCluster) DumpDroplet(w http.ResponseWriter, r *http.Request) (string, error) {
hostname := r.URL.Query().Get("hostname")
d := c.FindDropletByName(hostname)
if d == nil {
result := "can not find droplet hostname=" + hostname
log.Info(result)
fmt.Fprintln(w, result)
return result, errors.New(result)
}
return d.DumpDroplet(w, r)
}