virtbuf/sampleData.go

99 lines
1.9 KiB
Go
Raw Normal View History

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,
}
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 CreateExperiment(total int) *WhatsThis {
var e *WhatsThis
e = new(WhatsThis)
// info := StorageInfo{Capacity: 64}
// e.Humantest = &info
if e.Humantest == nil {
var newInfo WhatInfo
newInfo = WhatInfo{Capacity: 64}
e.Humantest = &newInfo
} else {
e.Humantest.Capacity = SetGB(total * 32)
}
return e
}
func CreateSampleEvents(total int) *Events {
var e *Events
e = new(Events)
for i := 0; i < total; i++ {
var newe *Event
newe = new(Event)
e.Events = append(e.Events, newe)
}
return e
}
func CreateSampleCluster(total int) *NewCluster {
var c *NewCluster
c = new(NewCluster)
c.d = new(Droplets)
c.h = new(Hypervisors)
c.e = new(Events)
for i := 0; i < total; i++ {
hostname := fmt.Sprintf("bmath%d.wit.com", i)
d := CreateSampleDroplet(hostname)
d.PreferredHypervisor = fmt.Sprintf("farm%d", i)
if d.PreferredHypervisor == "farm4" {
d.Cpus = 16
d.Memory = SetGB(256)
}
c.d.Droplets = append(c.d.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.h.Hypervisors = append(c.h.Hypervisors, h)
}
return c
}