Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema: Parse column type #28

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
// OvsdbClient is an OVSDB client
type OvsdbClient struct {
rpcClient *rpc2.Client
Schema map[string]DatabaseSchema
Schema map[string]*DatabaseSchema
Copy link

@hzhou8 hzhou8 Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the interface. At least go-ovn will be broken due to this change. Is there a way to avoid interface change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll try to avoid breaking the API in #30

handlers []NotificationHandler
handlersMutex *sync.Mutex
}

func newOvsdbClient(c *rpc2.Client) *OvsdbClient {
ovs := &OvsdbClient{
rpcClient: c,
Schema: make(map[string]DatabaseSchema),
Schema: make(map[string]*DatabaseSchema),
handlersMutex: &sync.Mutex{},
}
return ovs
Expand Down Expand Up @@ -108,7 +108,7 @@ func newRPC2Client(conn net.Conn) (*OvsdbClient, error) {
for _, db := range dbs {
schema, err := ovs.GetSchema(db)
if err == nil {
ovs.Schema[db] = *schema
ovs.Schema[db] = schema
} else {
c.Close()
return nil, err
Expand Down Expand Up @@ -232,7 +232,7 @@ func (ovs OvsdbClient) GetSchema(dbName string) (*DatabaseSchema, error) {
if err != nil {
return nil, err
}
ovs.Schema[dbName] = reply
ovs.Schema[dbName] = &reply
return &reply, err
}

Expand Down
File renamed without changes.
46 changes: 46 additions & 0 deletions example/print_schema/print_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/ebay/libovsdb"
)

func usage() {
fmt.Fprintf(os.Stderr, "Print schema information:\n")
fmt.Fprintf(os.Stderr, "\tprint_schemas OVS_SCHEMA\n")
}

func main() {
log.SetFlags(0)
flag.Usage = usage
flag.Parse()

if len(flag.Args()) != 1 {
flag.Usage()
os.Exit(2)
}

schemaFile, err := os.Open(flag.Args()[0])
if err != nil {
log.Fatal(err)
}
defer schemaFile.Close()

schemaBytes, err := ioutil.ReadAll(schemaFile)
if err != nil {
log.Fatal(err)
}

schema := libovsdb.DatabaseSchema{}
//if err := schema.Unmarshal(schemaBytes); err != nil {
if err := json.Unmarshal(schemaBytes, &schema); err != nil {
log.Fatal(err)
}
schema.Print(os.Stdout)
}
Loading