コード例 #1
0
ファイル: bridge.go プロジェクト: mirmali/ovs
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)
}
コード例 #2
0
ファイル: ovsdb_transact_test.go プロジェクト: mirmali/ovs
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()
}