Skip to content

Commit

Permalink
Merge pull request #55 from digitalocean/mdl-ovs-cleanup
Browse files Browse the repository at this point in the history
ovs: cleanup for VSwitchService
  • Loading branch information
mdlayher authored Jun 4, 2018
2 parents 93b1811 + 1763db3 commit 813765f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ovs/vswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ func (v *VSwitchService) ListPorts(bridge string) ([]string, error) {
return nil, err
}

if string(output) == "" {
// Do no ports exist?
if len(output) == 0 {
return nil, nil
}

ports := strings.Split(strings.TrimSpace(string(output)), "\n")
return ports, err
return ports, nil
}

// ListBridges lists the bridges in Open vSwitch.
Expand All @@ -91,11 +93,13 @@ func (v *VSwitchService) ListBridges() ([]string, error) {
return nil, err
}

if string(output) == "" {
// Do no bridges exist?
if len(output) == 0 {
return nil, nil
}

bridges := strings.Split(strings.TrimSpace(string(output)), "\n")
return bridges, err
return bridges, nil
}

// PortToBridge attempts to determine which bridge a port is attached to.
Expand All @@ -116,7 +120,8 @@ func (v *VSwitchService) GetFailMode(bridge string) (FailMode, error) {
if err != nil {
return "", err
}
return FailMode(out), err

return FailMode(out), nil
}

// SetFailMode sets the specified FailMode for the specified bridge.
Expand All @@ -138,7 +143,8 @@ func (v *VSwitchService) GetController(bridge string) (string, error) {
if err != nil {
return "", err
}
return strings.TrimSpace(string(address)), err

return strings.TrimSpace(string(address)), nil
}

// exec executes an ExecFunc using 'ovs-vsctl'.
Expand All @@ -162,12 +168,15 @@ func (v *VSwitchGetService) Bridge(bridge string) (BridgeOptions, error) {
if err != nil {
return BridgeOptions{}, err
}
protocols := []string{}
err = json.Unmarshal(out, &protocols)
if err != nil {

var protocols []string
if err := json.Unmarshal(out, &protocols); err != nil {
return BridgeOptions{}, err
}
return BridgeOptions{Protocols: protocols}, nil

return BridgeOptions{
Protocols: protocols,
}, nil
}

// A VSwitchSetService is used in a VSwitchService to execute 'ovs-vsctl set'
Expand Down

0 comments on commit 813765f

Please sign in to comment.