2024-10-21 17:53:36 -05:00
|
|
|
package virtbuf
|
|
|
|
|
2024-10-22 03:04:59 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2024-10-22 03:13:12 -05:00
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2024-10-22 14:40:59 -05:00
|
|
|
// anypb "google.golang.org/protobuf/types/known/anypb"
|
2024-10-22 03:04:59 -05:00
|
|
|
)
|
2024-10-21 17:53:36 -05:00
|
|
|
|
|
|
|
//
|
2024-10-22 03:13:12 -05:00
|
|
|
// This generates some sample data.
|
2024-10-21 17:53:36 -05:00
|
|
|
//
|
|
|
|
|
2024-10-22 03:04:59 -05:00
|
|
|
func CreateSampleDroplet(hostname string) *Droplet {
|
2024-10-21 17:53:36 -05:00
|
|
|
// TODO: flush this out to do all the fields
|
2024-10-22 03:04:59 -05:00
|
|
|
log.Println("CreateSampleDroplet() is generating a new droplet", hostname)
|
2024-10-21 17:53:36 -05:00
|
|
|
|
2024-10-22 03:13:12 -05:00
|
|
|
// Generate a new UUID
|
|
|
|
id := uuid.New()
|
2024-10-22 03:04:59 -05:00
|
|
|
d := &Droplet{
|
2024-10-22 03:13:12 -05:00
|
|
|
Uuid: id.String(),
|
2024-10-22 03:04:59 -05:00
|
|
|
Hostname: hostname,
|
2024-10-21 17:53:36 -05:00
|
|
|
}
|
2024-10-22 03:04:59 -05:00
|
|
|
return d
|
2024-10-21 17:53:36 -05:00
|
|
|
}
|
|
|
|
|
2024-10-22 04:18:40 -05:00
|
|
|
func CreateSampleHypervisor(hostname string, mem int) *Hypervisor {
|
2024-10-22 03:50:01 -05:00
|
|
|
// Generate a new UUID
|
|
|
|
id := uuid.New()
|
|
|
|
h := &Hypervisor{
|
|
|
|
Uuid: id.String(),
|
|
|
|
Hostname: hostname,
|
2024-10-22 04:26:29 -05:00
|
|
|
Cpus: 16,
|
|
|
|
Memory: 256,
|
2024-10-22 03:50:01 -05:00
|
|
|
Comment: "this is a fake hypervisor",
|
|
|
|
}
|
2024-10-22 04:26:29 -05:00
|
|
|
h.SetMemoryGB(mem * 32)
|
2024-10-22 03:50:01 -05:00
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2024-10-24 17:50:50 -05:00
|
|
|
func CreateExperiment(total int) *WhatsThis {
|
|
|
|
var e *WhatsThis
|
|
|
|
e = new(WhatsThis)
|
2024-10-24 17:12:05 -05:00
|
|
|
|
|
|
|
// info := StorageInfo{Capacity: 64}
|
|
|
|
// e.Humantest = &info
|
|
|
|
if e.Humantest == nil {
|
2024-10-24 17:50:50 -05:00
|
|
|
var newInfo WhatInfo
|
|
|
|
newInfo = WhatInfo{Capacity: 64}
|
2024-10-24 17:12:05 -05:00
|
|
|
e.Humantest = &newInfo
|
|
|
|
} else {
|
|
|
|
e.Humantest.Capacity = SetGB(total * 32)
|
|
|
|
}
|
2024-10-24 17:50:50 -05:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateSampleEvents(total int) *Events {
|
|
|
|
var e *Events
|
|
|
|
e = new(Events)
|
2024-10-24 17:12:05 -05:00
|
|
|
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
var newe *Event
|
|
|
|
newe = new(Event)
|
|
|
|
e.Events = append(e.Events, newe)
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2024-10-31 13:07:24 -05:00
|
|
|
func CreateSampleCluster(total int) *NewCluster {
|
2024-10-31 13:21:10 -05:00
|
|
|
c := InitCluster()
|
2024-10-21 17:53:36 -05:00
|
|
|
|
|
|
|
for i := 0; i < total; i++ {
|
2024-10-22 03:04:59 -05:00
|
|
|
hostname := fmt.Sprintf("bmath%d.wit.com", i)
|
|
|
|
d := CreateSampleDroplet(hostname)
|
2024-10-22 03:50:01 -05:00
|
|
|
d.PreferredHypervisor = fmt.Sprintf("farm%d", i)
|
2024-10-22 14:40:59 -05:00
|
|
|
if d.PreferredHypervisor == "farm4" {
|
|
|
|
d.Cpus = 16
|
2024-10-22 16:33:36 -05:00
|
|
|
d.Memory = SetGB(256)
|
2024-10-22 14:40:59 -05:00
|
|
|
}
|
2024-10-21 17:53:36 -05:00
|
|
|
|
2024-10-31 13:07:24 -05:00
|
|
|
c.d.Droplets = append(c.d.Droplets, d)
|
2024-10-21 17:53:36 -05:00
|
|
|
}
|
|
|
|
|
2024-10-22 03:50:01 -05:00
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
hostname := fmt.Sprintf("farm%d", i)
|
2024-10-22 04:26:29 -05:00
|
|
|
h := CreateSampleHypervisor(hostname, i+1)
|
2024-10-22 03:50:01 -05:00
|
|
|
h.Comment = fmt.Sprintf("Sample hypervisor %d", i)
|
|
|
|
|
2024-10-31 13:21:10 -05:00
|
|
|
c.H.Hypervisors = append(c.H.Hypervisors, h)
|
2024-10-22 03:50:01 -05:00
|
|
|
}
|
|
|
|
|
2024-10-22 02:51:45 -05:00
|
|
|
return c
|
2024-10-21 17:53:36 -05:00
|
|
|
}
|