next step, write out yaml or json

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 03:50:01 -05:00
parent c9c0abc440
commit 8cab0857fd
4 changed files with 40 additions and 8 deletions

View File

@ -26,9 +26,15 @@ func main() {
log.Fatalln("Failed to parse droplet:", err)
}
log.Println(aCluster)
for i, d := range aCluster.Droplets {
log.Println("\tdrop =", i, d)
// log.Println(aCluster)
// show the droplets to STDOUT
for _, d := range aCluster.Droplets {
log.Println("\tdroplet =", d.Hostname, "preffered host:", d.PreferredHypervisor)
}
// show the hypervisors to STDOUT
for _, h := range aCluster.Hypervisors {
log.Println("\thypervisor =", h.Hostname)
}
}
@ -50,7 +56,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, c *pb.Cluster) {
func TestWriteCluster() {
buf := new(bytes.Buffer)
c := pb.CreateSampleCluster(3)
c := pb.CreateSampleCluster(7)
got := buf.String()
log.Println(got)

View File

@ -14,6 +14,8 @@ message Droplet {
repeated Disk disks = 9;
string comment = 10;
string default_state = 11;
string preferred_hypervisor = 12;
message Network {
string mac = 1;

View File

@ -2,8 +2,10 @@ syntax = "proto3";
package virtbuf;
message Hypervisor {
string hostname = 1;
bool active = 2;
int64 cpus = 3;
int64 memory = 4;
string uuid = 1;
string hostname = 2;
bool active = 3;
int64 cpus = 4;
int64 memory = 5;
string comment = 6;
}

View File

@ -25,6 +25,19 @@ func CreateSampleDroplet(hostname string) *Droplet {
return d
}
func CreateSampleHypervisor(hostname string) *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",
}
return h
}
func CreateSampleCluster(total int) *Cluster {
var c *Cluster
c = new(Cluster)
@ -33,9 +46,18 @@ func CreateSampleCluster(total int) *Cluster {
hostname := fmt.Sprintf("bmath%d.wit.com", i)
d := CreateSampleDroplet(hostname)
d.Comment = fmt.Sprintf("Sample Droplet %d", i)
d.PreferredHypervisor = fmt.Sprintf("farm%d", i)
c.Droplets = append(c.Droplets, d)
}
for i := 0; i < 3; i++ {
hostname := fmt.Sprintf("farm%d", i)
h := CreateSampleHypervisor(hostname)
h.Comment = fmt.Sprintf("Sample hypervisor %d", i)
c.Hypervisors = append(c.Hypervisors, h)
}
return c
}