witProtobuf/guipb/sampleData.go

172 lines
4.0 KiB
Go
Raw Normal View History

package guipb
import "log"
//
// This generates some sample data. It *should* match the .proto file
//
func CreateSampleEvent() *Event {
// TODO: flush this out to do all the fields
log.Println("CreateSampleEvent() is generating a example protobuf Event")
e := &Event{
Id: 1234,
Comment: "this is a sample event",
Type: Event_MIGRATE,
Results: []*Event_Response{
{Name: "fooadd", Type: Event_ADD},
{Name: "foodelete", Type: Event_DELETE},
{
Name: "foopoweron",
Type: Event_POWERON,
Error: "No error happened",
Id: 54321,
},
},
}
return e
}
func CreateSampleEvents(total int) []Event {
// TODO: flush this out to do all the fields
log.Println("CreateSampleEvent() is generating %d protobuf Events", total)
var all []Event
for i := 0; i < total; i++ {
e := CreateSampleEvent()
e.Id += 1000 + int32(i)
e.Comment = "Sample Event " + string(i)
all = append(all, *e)
}
return all
}
func DumpEventData(myevent *Event) {
log.Println("Received Event name=", myevent)
log.Println("Displaying the Event_Results:")
msgItems := myevent.GetResults()
for _, item := range msgItems {
log.Println("\t", item)
}
}
func MakeGetEvent() *Event {
e := &Event{
Id: 1234,
Comment: "List all user VMs",
Type: Event_GET,
}
e.Comment ="this should return a protobuf with all the VM's"
return e
}
func MakeLoginEvent() *Event {
e := &Event{
Id: 1234,
Comment: "Login to get a Token",
Type: Event_LOGIN,
}
e.Comment ="this should return a protobuf with the token"
return e
}
func MakeOkResponse() *Event {
log.Println("CreateSampleEvent() is generating a example protobuf Event")
e := &Event{
Id: 1234,
Comment: "everything is OK",
Type: Event_OK,
Results: []*Event_Response{
{Name: "fooadd", Type: Event_OK},
{Name: "foodelete", Type: Event_DELETE},
{
Name: "foopoweron",
Type: Event_POWERON,
Error: "No error happened",
Id: 54321,
},
},
}
return e
}
func MakeFailResponse() *Event {
log.Println("CreateSampleEvent() is generating a example protobuf Event")
e := &Event{
Id: 1234,
Comment: "something failed",
Type: Event_FAIL,
Results: []*Event_Response{
{Name: "fooadd", Type: Event_FAIL},
{Name: "foodelete", Type: Event_DELETE},
{
Name: "foopoweron",
Type: Event_POWERON,
Error: "No error happened",
Id: 54321,
},
},
}
return e
}
func MakeAddVmEvent() *Event {
log.Println("MakeAddVmEvent() is generating a example 'create' virtual machine event")
e := &Event{
Id: 1234,
Comment: "A Test Create VM Event",
Type: Event_ADD,
Vms: []*Event_VM{
{
Hostname: "test323.lab.wit.com",
Memory: 2048,
Disk: 20,
Cpus: 4,
},
},
}
return e
}
func MakeDefaultConfig() *Config {
log.Println("MakeDefaultConfig() makes a default config")
c := &Config{
USER: "jcarr",
Width: 700,
Height: 500,
Accounts: []*Account{
{
Nick: "jcarr",
Username: "jcarr@wit.com",
Token: "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e",
Domain: "test.wit.com",
Hostname: "hosttest.wit.com",
},
{
Nick: "jcarr2",
Username: "jcarr@wit.com",
Token: "brokenToken",
Domain: "test.wit.com",
Hostname: "hosttest.wit.com",
},
{
Nick: "bmath",
Username: "bmath@wit.com",
Token: "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI",
Domain: "test.wit.com",
Hostname: "hosttest.wit.com",
},
},
}
return c
}