summaryrefslogtreecommitdiff
path: root/example/main.go
blob: 4554af36c16e71f18b378087cb697b949152948f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"

	pb "go.wit.com/lib/protobuf/virtbuf"
)

//
// saves entries in a config file
//

func main() {
	TestWriteCluster()

	_, err := ioutil.ReadFile("/tmp/testing4.protobuf")
	if err != nil {
		log.Fatalln("Error reading file:", err)
	}

	var c *pb.NewCluster
	c = pb.InitCluster()

	// 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)
	*/
}

/*
func marshalWriteToFile(myWriter *bufio.Writer, c *pb.NewCluster) {
	buf, err := proto.Marshal(c)
	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)
	tmp2, err := myWriter.Write(buf)
	myWriter.Flush()
	log.Println("bufio.Write() tmp2, err = ", tmp2, err)
}
*/

func TestWriteCluster() {
	c := pb.CreateSampleCluster(7)
	os.Setenv("VIRTIGO_HOME", "/tmp/virtigo/")

	if err := c.ConfigSave(); err != nil {
		fmt.Println("configsave error", err)
		os.Exit(-1)
	}
	// marshalUnmarshal()
}

/*
func marshalUnmarshal() {
	test := pb.CreateSampleCluster(7)
	data, err := proto.Marshal(test)
	if err != nil {
		log.Fatal("marshaling error: ", err)
	}

	newTest := &pb.Cluster{}
	err = proto.Unmarshal(data, newTest)
	if err != nil {
		log.Fatal("unmarshaling error: ", err)
	} else {
		log.Println("proto.Marshal() and proto.Unmarshal() worked")
	}
}
*/