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 30, 2024
1 parent cc37bfd commit c32bed9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lxd/network/openvswitch/shared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package openvswitch

import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
Expand All @@ -9,6 +11,18 @@ import (
// MicroovnTargetChassisPath matches the path of the "ovn-chassis" content interface target with MicroOVN.
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 c32bed9

Please sign in to comment.