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
|
|
|
Comment: "this is a droplet for testing",
|
|
|
|
}
|
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-22 02:51:45 -05:00
|
|
|
func CreateSampleCluster(total int) *Cluster {
|
|
|
|
var c *Cluster
|
|
|
|
c = new(Cluster)
|
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)
|
|
|
|
d.Comment = fmt.Sprintf("Sample Droplet %d", i)
|
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
|
|
|
|
d.Memory = "256 MB"
|
|
|
|
// d.Memory = "258 MB"
|
|
|
|
}
|
2024-10-21 17:53:36 -05:00
|
|
|
|
2024-10-22 02:51:45 -05:00
|
|
|
c.Droplets = append(c.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)
|
|
|
|
|
|
|
|
c.Hypervisors = append(c.Hypervisors, h)
|
|
|
|
}
|
|
|
|
|
2024-10-22 02:51:45 -05:00
|
|
|
return c
|
2024-10-21 17:53:36 -05:00
|
|
|
}
|