-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1349 from stgraber/ovn
Add infrastructure for OVN events
- Loading branch information
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ovn | ||
|
||
import ( | ||
ovsdbModel "github.com/ovn-org/libovsdb/model" | ||
) | ||
|
||
// EventHandler represents an OVN database event handler. | ||
type EventHandler struct { | ||
// Tables contains the list of OVN database tables to watch for events. | ||
Tables []string | ||
|
||
// Hook is the function being called on a matching event. | ||
Hook func(action string, table string, oldObject ovsdbModel.Model, newObject ovsdbModel.Model) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ovn | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
var sbEventHandlers map[string]EventHandler | ||
var sbEventHandlersMu sync.Mutex | ||
|
||
// AddOVNSBHandler registers a new event handler with the OVN Southbound database. | ||
func AddOVNSBHandler(name string, handler EventHandler) error { | ||
sbEventHandlersMu.Lock() | ||
defer sbEventHandlersMu.Unlock() | ||
|
||
if sbEventHandlers == nil { | ||
sbEventHandlers = map[string]EventHandler{} | ||
} | ||
|
||
sbEventHandlers[name] = handler | ||
|
||
return nil | ||
} | ||
|
||
// RemoveOVNSBHandler removes a currently registered event handler. | ||
func RemoveOVNSBHandler(name string) error { | ||
sbEventHandlersMu.Lock() | ||
defer sbEventHandlersMu.Unlock() | ||
|
||
if sbEventHandlers == nil { | ||
return nil | ||
} | ||
|
||
delete(sbEventHandlers, name) | ||
|
||
return nil | ||
} |