95 lines
1.8 KiB
Go
95 lines
1.8 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,
|
|
}
|
|
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 {
|
|
c := InitCluster()
|
|
|
|
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
|
|
}
|