first go at it
This commit is contained in:
commit
be5548cd4e
|
@ -0,0 +1,5 @@
|
|||
go.*
|
||||
|
||||
*.pb.go
|
||||
|
||||
configfile/configfile
|
|
@ -0,0 +1,48 @@
|
|||
all:
|
||||
# You must use the current protoc-gen-go
|
||||
# protoc --version 3.6++ does not mean that protoc will generate version3 .go files
|
||||
#
|
||||
# apt remove golang-goprotobuf-dev
|
||||
# apt install protobuf-compiler
|
||||
#
|
||||
# Then:
|
||||
# go get -u github.com/golang/protobuf/protoc-gen-go
|
||||
# cd ~/go/src/github.com/golang/protobuf/protoc-gen-go
|
||||
# go install
|
||||
#
|
||||
# Then:
|
||||
protoc --version
|
||||
make droplet.pb.go
|
||||
|
||||
redomod:
|
||||
rm -f go.*
|
||||
GO111MODULE= go mod init
|
||||
GO111MODULE= go mod tidy
|
||||
|
||||
clean:
|
||||
rm -f *.pb.go
|
||||
|
||||
droplet.pb.go: droplet.proto
|
||||
protoc --go_out=. droplet.proto
|
||||
|
||||
events.pb.go: events.proto
|
||||
protoc --go_out=. events.proto
|
||||
|
||||
account.pb.go: account.proto
|
||||
protoc --go_out=. account.proto
|
||||
|
||||
config.pb.go: config.proto
|
||||
protoc --go_out=. config.proto
|
||||
|
||||
compile:
|
||||
protoc --go_out=. *.proto
|
||||
|
||||
deps:
|
||||
apt install golang-goprotobuf-dev
|
||||
apt install protobuf-compiler
|
||||
|
||||
push:
|
||||
git pull
|
||||
git add --all
|
||||
git commit -a -s
|
||||
git push
|
|
@ -0,0 +1,6 @@
|
|||
the libvirt xml files are just a bit much at this point
|
||||
|
||||
They are what to use for starting droplets with virsh,
|
||||
but for making a cluster or "home cloud" or something
|
||||
like virtigo, I think it's going to be better to do
|
||||
something simple. Anyway, this is that attmept.
|
|
@ -0,0 +1,8 @@
|
|||
build:
|
||||
go build
|
||||
|
||||
prep:
|
||||
go get -v -t -u
|
||||
|
||||
run:
|
||||
go run *.go
|
|
@ -0,0 +1,77 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
import "bytes"
|
||||
import "os"
|
||||
import "bufio"
|
||||
import "io/ioutil"
|
||||
|
||||
import "github.com/golang/protobuf/proto"
|
||||
import pb "git.wit.com/wit/virtbuf"
|
||||
|
||||
//
|
||||
// saves entries in a config file
|
||||
//
|
||||
|
||||
func main() {
|
||||
TestWriteEvent()
|
||||
|
||||
in, err := ioutil.ReadFile("/tmp/testing4.protobuf")
|
||||
if err != nil {
|
||||
log.Fatalln("Error reading file:", err)
|
||||
}
|
||||
allEvents := &pb.Event{}
|
||||
if err := proto.Unmarshal(in, allEvents); err != nil {
|
||||
log.Fatalln("Failed to parse events:", err)
|
||||
}
|
||||
|
||||
// listPeople(os.Stdout, allEvents)
|
||||
// got := in.String()
|
||||
log.Println(in)
|
||||
}
|
||||
|
||||
func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) {
|
||||
buf, err := proto.Marshal(e)
|
||||
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(e)
|
||||
tmp2, err := myWriter.Write(buf)
|
||||
myWriter.Flush()
|
||||
log.Println("bufio.Write() tmp2, err = ", tmp2, err)
|
||||
}
|
||||
|
||||
func TestWriteEvent() {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
e := pb.CreateSampleEvent()
|
||||
|
||||
got := buf.String()
|
||||
log.Println(got)
|
||||
|
||||
newfile, _ := os.Create("/tmp/testing4.protobuf")
|
||||
myWriter := bufio.NewWriter(newfile)
|
||||
marshalWriteToFile(myWriter, e)
|
||||
|
||||
marshalUnmarshal()
|
||||
}
|
||||
|
||||
func marshalUnmarshal() {
|
||||
test := pb.CreateSampleEvent()
|
||||
data, err := proto.Marshal(test)
|
||||
if err != nil {
|
||||
log.Fatal("marshaling error: ", err)
|
||||
}
|
||||
|
||||
newTest := &pb.Event{}
|
||||
err = proto.Unmarshal(data, newTest)
|
||||
if err != nil {
|
||||
log.Fatal("unmarshaling error: ", err)
|
||||
} else {
|
||||
log.Println("proto.Marshal() and proto.Unmarshal() worked")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
syntax = "proto3";
|
||||
package virtbuf;
|
||||
|
||||
message Droplet {
|
||||
string uuid = 1;
|
||||
string name = 2;
|
||||
|
||||
repeated Response results = 3;
|
||||
repeated Network networks = 4;
|
||||
repeated VM vms = 5;
|
||||
|
||||
enum EventType {
|
||||
ADD = 0;
|
||||
DELETE = 1;
|
||||
POWERON = 2;
|
||||
POWEROFF = 3;
|
||||
HIBERNATE = 4;
|
||||
MIGRATE = 5;
|
||||
DEMO = 6;
|
||||
GET = 7; // request something
|
||||
LOGIN = 8; // attempt to login
|
||||
OK = 9; // everything is ok
|
||||
FAIL = 10; // everything failed
|
||||
}
|
||||
|
||||
message Response {
|
||||
EventType type = 1;
|
||||
int32 id = 2;
|
||||
string name = 3;
|
||||
string error = 4;
|
||||
repeated string snippets = 5;
|
||||
}
|
||||
|
||||
message Network {
|
||||
string mac = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message VM {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
string hostname = 3;
|
||||
int64 cpus = 4;
|
||||
int64 memory = 5;
|
||||
int64 disk = 6;
|
||||
string IPv6 = 7;
|
||||
string role = 8;
|
||||
string baseImage = 9;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue