Skip to content

Commit

Permalink
lxd/network/openvswitch/shared: Add the vsctl function
Browse files Browse the repository at this point in the history
vsctl is a simple wrapper to call ovs-vsctl with args but conditionally adding
the '--db=unix:/...' arg if a bootstrapped MicroOVN deployment has been detected.

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Oct 29, 2024
1 parent 843728d commit e51d63c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lxd/network/openvswitch/shared.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package openvswitch

import (
"os"
"regexp"
"strconv"
"strings"
)

var MicroovnTargetChassisPath = regexp.MustCompile(`^/var/snap/lxd/[0-9]+/microovn/chassis/switch`)

// vsctl either returns the "ovs-vsctl" command if OVN is built in with LXD
// or if MicroOVN is installed and the 'ovn-chassis' content interface is connected,
// it returns "ovs-vsctl" with its southbound db unix socket.
func vsctl(args ...string) (string, []string) {
targetPath, _ := os.Readlink("/run/openvswitch")
if !MicroovnTargetChassisPath.MatchString(targetPath) {
return "ovs-vsctl", args
}

return "ovs-vsctl", append([]string{fmt.Sprintf("--db=unix:%s/db.sock", targetPath)}, args...)
}

// unquote passes s through strconv.Unquote if the first character is a ", otherwise returns s unmodified.
// This is useful as openvswitch's tools can sometimes return values double quoted if they start with a number.
func unquote(s string) (string, error) {
Expand Down

0 comments on commit e51d63c

Please sign in to comment.