Exemple #1
0
func main() {
	ovs, err := ovsdbgo.Connect("127.0.0.1", 6640)
	if err != nil {
		fmt.Println("unable to connect ", err)
		panic(err)
	}
	database := "OpenSwitch"
	db := ovsdbgo.LoadAll(ovs, database)

	// add a new bridge named new_bridge
	transaction := ovsdbgo.Transaction{ovs, db}
	new_bridge := transaction.InsertRow("Bridge")
	new_bridge.Set("name", "bridge02")
	new_bridge_uuid := libovsdb.UUID{ovsdbgo.UuidToUuidName(new_bridge.UUID)}

	// add reference of new created bridge to "bridges" column in System table
	for _, sysRow := range db.Tables["System"].Rows {

		bridges := (sysRow.Data.Fields["bridges"]).(libovsdb.OvsSet)
		new_bridges := make([]interface{}, len(bridges.GoSet)+1)

		for ok, uuid := range bridges.GoSet {
			new_bridges[ok] = uuid
		}
		new_bridges[len(new_bridges)-1] = new_bridge_uuid
		new_bridges_set, _ := libovsdb.NewOvsSet(new_bridges)
		sysRow.Set("bridges", new_bridges_set)
	}
	res, err := transaction.Commit()
	fmt.Println(res, err)
}
Exemple #2
0
func TestListDbs(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	ovs, err := ovsdbgo.Connect("127.0.0.1", 6640)
	if err != nil {
		panic(err)
	}
	reply, err := ovs.ListDbs()

	if err != nil {
		log.Fatal("ListDbs error:", err)
	}

	found := false
	for _, name := range reply {
		if name == "OpenSwitch" {
			found = true
			break
		}
	}

	if !found {
		t.Error("OpenSwitch database not found")
	}
	ovs.Disconnect()
}
Exemple #3
0
func TestConnect(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	timeoutChan := make(chan bool)
	connected := make(chan bool)
	go func() {
		time.Sleep(10 * time.Second)
		timeoutChan <- true
	}()

	go func() {
		// Use Convenience params. Ignore failure even if any
		_, err := ovsdbgo.Connect("", 0)
		if err != nil {
			log.Println("Couldnt establish OVSDB connection with Defult params. No big deal")
		}
	}()

	go func() {
		ovs, err := ovsdbgo.Connect("127.0.0.1", 6640)
		if err != nil {
			connected <- false
		} else {
			connected <- true
			ovs.Disconnect()
		}
	}()

	select {
	case <-timeoutChan:
		t.Error("Connection Timed Out")
	case b := <-connected:
		if !b {
			t.Error("Couldnt connect to OVSDB Server")
		}
	}
}
Exemple #4
0
func TestListPopulateCache(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	ovs, err := ovsdbgo.Connect("127.0.0.1", 6640)
	if err != nil {
		panic(err)
	}

	db := ovsdbgo.LoadAll(ovs, "OpenSwitch")
	tables := [...]string{"Bridge", "Interface", "Port"}
	for _, table := range tables {
		if _, ok := db.Tables[table]; !ok {
			t.Error("Table ", table, " is missing")
		}
	}
	ovs.Disconnect()
}