virtbuf/example/main.go

92 lines
1.7 KiB
Go
Raw Normal View History

2024-10-18 20:58:15 -05:00
package main
import (
"fmt"
"os"
2024-10-18 20:58:15 -05:00
pb "go.wit.com/lib/protobuf/virtbuf"
)
2024-10-18 20:58:15 -05:00
//
// saves entries in a config file
//
func main() {
TestWriteCluster()
2024-10-18 20:58:15 -05:00
var c *pb.NewCluster
c = pb.InitCluster()
2024-10-18 20:58:15 -05:00
// log.Println(aCluster.String())
// show the droplets to STDOUT
loop := c.DropletsAll() // get the list of droplets
for loop.Scan() {
d := loop.Droplet()
fmt.Println("\tdroplet =", d.Hostname, "preffered host:", d.PreferredHypervisor)
}
/*
// show the hypervisors to STDOUT
for _, h := range aCluster.Hypervisors {
fmt.Println("\thypervisor =", h.Hostname, h.GetMemoryPrintable())
}
*/
/*
json := aCluster.FormatJSON()
fmt.Println(json)
data, _ := aCluster.MarshalJSON()
fmt.Println(string(data))
text := aCluster.FormatTEXT()
fmt.Println(text)
*/
2024-10-18 20:58:15 -05:00
}
/*
func marshalWriteToFile(myWriter *bufio.Writer, c *pb.NewCluster) {
buf, err := proto.Marshal(c)
2024-10-18 20:58:15 -05:00
if err != nil {
log.Fatal("marshaling error: ", err)
}
tmp, err := myWriter.Write(buf)
myWriter.Flush()
log.Println("bufio.Write() tmp, err = ", tmp, err)
buf, err = proto.Marshal(c)
2024-10-18 20:58:15 -05:00
tmp2, err := myWriter.Write(buf)
myWriter.Flush()
log.Println("bufio.Write() tmp2, err = ", tmp2, err)
}
*/
2024-10-18 20:58:15 -05:00
func TestWriteCluster() {
c := pb.CreateSampleCluster(7)
os.Setenv("VIRTIGO_HOME", "/tmp/virtigo/")
2024-10-18 20:58:15 -05:00
if err := c.ConfigSave(); err != nil {
fmt.Println("configsave error", err)
os.Exit(-1)
}
// marshalUnmarshal()
2024-10-18 20:58:15 -05:00
}
/*
2024-10-18 20:58:15 -05:00
func marshalUnmarshal() {
test := pb.CreateSampleCluster(7)
2024-10-18 20:58:15 -05:00
data, err := proto.Marshal(test)
if err != nil {
log.Fatal("marshaling error: ", err)
}
newTest := &pb.Cluster{}
2024-10-18 20:58:15 -05:00
err = proto.Unmarshal(data, newTest)
if err != nil {
log.Fatal("unmarshaling error: ", err)
} else {
log.Println("proto.Marshal() and proto.Unmarshal() worked")
}
}
*/