virtbuf/sampleData.go

72 lines
1.5 KiB
Go

package virtbuf
import (
"fmt"
"log"
"github.com/google/uuid"
// anypb "google.golang.org/protobuf/types/known/anypb"
)
//
// This generates some sample data.
//
func CreateSampleDroplet(hostname string) *Droplet {
// TODO: flush this out to do all the fields
log.Println("CreateSampleDroplet() is generating a new droplet", hostname)
// Generate a new UUID
id := uuid.New()
d := &Droplet{
Uuid: id.String(),
Hostname: hostname,
Notes: "this is a droplet for testing",
}
return d
}
func CreateSampleHypervisor(hostname string, mem int) *Hypervisor {
// Generate a new UUID
id := uuid.New()
h := &Hypervisor{
Uuid: id.String(),
Hostname: hostname,
Cpus: 16,
Memory: 256,
Comment: "this is a fake hypervisor",
}
h.SetMemoryGB(mem * 32)
return h
}
func CreateSampleCluster(total int) *Cluster {
var c *Cluster
c = new(Cluster)
for i := 0; i < total; i++ {
hostname := fmt.Sprintf("bmath%d.wit.com", i)
d := CreateSampleDroplet(hostname)
d.Notes = fmt.Sprintf("Sample Droplet %d", i)
d.PreferredHypervisor = fmt.Sprintf("farm%d", i)
if d.PreferredHypervisor == "farm4" {
d.Cpus = 16
d.Memory = SetGB(256)
}
info := StorageInfo{Capacity: 64}
d.Humantest = &info
c.Droplets = append(c.Droplets, d)
}
for i := 0; i < 3; i++ {
hostname := fmt.Sprintf("farm%d", i)
h := CreateSampleHypervisor(hostname, i+1)
h.Comment = fmt.Sprintf("Sample hypervisor %d", i)
c.Hypervisors = append(c.Hypervisors, h)
}
return c
}