change sample hostname
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bcc97a550a
commit
aa70a02dd8
|
@ -32,8 +32,8 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) {
|
func marshalWriteToFile(myWriter *bufio.Writer, c *pb.Cluster) {
|
||||||
buf, err := proto.Marshal(e)
|
buf, err := proto.Marshal(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("marshaling error: ", err)
|
log.Fatal("marshaling error: ", err)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) {
|
||||||
myWriter.Flush()
|
myWriter.Flush()
|
||||||
log.Println("bufio.Write() tmp, err = ", tmp, err)
|
log.Println("bufio.Write() tmp, err = ", tmp, err)
|
||||||
|
|
||||||
buf, err = proto.Marshal(e)
|
buf, err = proto.Marshal(c)
|
||||||
tmp2, err := myWriter.Write(buf)
|
tmp2, err := myWriter.Write(buf)
|
||||||
myWriter.Flush()
|
myWriter.Flush()
|
||||||
log.Println("bufio.Write() tmp2, err = ", tmp2, err)
|
log.Println("bufio.Write() tmp2, err = ", tmp2, err)
|
||||||
|
@ -50,26 +50,26 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Cluster) {
|
||||||
func TestWriteDroplet() {
|
func TestWriteDroplet() {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
e := pb.CreateSampleCluster(10)
|
c := pb.CreateSampleCluster(3)
|
||||||
|
|
||||||
got := buf.String()
|
got := buf.String()
|
||||||
log.Println(got)
|
log.Println(got)
|
||||||
|
|
||||||
newfile, _ := os.Create("/tmp/testing4.protobuf")
|
newfile, _ := os.Create("/tmp/testing4.protobuf")
|
||||||
myWriter := bufio.NewWriter(newfile)
|
myWriter := bufio.NewWriter(newfile)
|
||||||
marshalWriteToFile(myWriter, e)
|
marshalWriteToFile(myWriter, c)
|
||||||
|
|
||||||
marshalUnmarshal()
|
marshalUnmarshal()
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalUnmarshal() {
|
func marshalUnmarshal() {
|
||||||
test := pb.CreateSampleCluster(10)
|
test := pb.CreateSampleCluster(7)
|
||||||
data, err := proto.Marshal(test)
|
data, err := proto.Marshal(test)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("marshaling error: ", err)
|
log.Fatal("marshaling error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newTest := &pb.Droplet{}
|
newTest := &pb.Cluster{}
|
||||||
err = proto.Unmarshal(data, newTest)
|
err = proto.Unmarshal(data, newTest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("unmarshaling error: ", err)
|
log.Fatal("unmarshaling error: ", err)
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
package virtbuf
|
package virtbuf
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
// This generates some sample data. It *should* match the .proto file
|
// This generates some sample data. It *should* match the .proto file
|
||||||
//
|
//
|
||||||
|
|
||||||
func CreateSampleDroplet() *Droplet {
|
func CreateSampleDroplet(hostname string) *Droplet {
|
||||||
// TODO: flush this out to do all the fields
|
// TODO: flush this out to do all the fields
|
||||||
log.Println("CreateSampleDroplet() is generating a new droplet")
|
log.Println("CreateSampleDroplet() is generating a new droplet", hostname)
|
||||||
|
|
||||||
e := &Droplet{
|
d := &Droplet{
|
||||||
Uuid: "6a1c571b-1d02-462b-9288-63d205306d76",
|
Uuid: "6a1c571b-1d02-462b-9288-63d205306d76",
|
||||||
Hostname: "bmath.wit.com",
|
Hostname: hostname,
|
||||||
Comment: "this is a droplet for testing",
|
Comment: "this is a droplet for testing",
|
||||||
}
|
}
|
||||||
return e
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateSampleCluster(total int) *Cluster {
|
func CreateSampleCluster(total int) *Cluster {
|
||||||
|
@ -23,10 +26,11 @@ func CreateSampleCluster(total int) *Cluster {
|
||||||
c = new(Cluster)
|
c = new(Cluster)
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
d := CreateSampleDroplet()
|
hostname := fmt.Sprintf("bmath%d.wit.com", i)
|
||||||
|
d := CreateSampleDroplet(hostname)
|
||||||
|
|
||||||
// e.Id += 1000 + int32(i)
|
// e.Id += 1000 + int32(i)
|
||||||
d.Comment = "Sample Droplet " + string(i)
|
d.Comment = fmt.Sprintf("Sample Droplet %d", i)
|
||||||
|
|
||||||
c.Droplets = append(c.Droplets, d)
|
c.Droplets = append(c.Droplets, d)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue