Skip to content

Commit 813765f

Browse files
authored
Merge pull request #55 from digitalocean/mdl-ovs-cleanup
ovs: cleanup for VSwitchService
2 parents 93b1811 + 1763db3 commit 813765f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

ovs/vswitch.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ func (v *VSwitchService) ListPorts(bridge string) ([]string, error) {
7777
return nil, err
7878
}
7979

80-
if string(output) == "" {
80+
// Do no ports exist?
81+
if len(output) == 0 {
8182
return nil, nil
8283
}
84+
8385
ports := strings.Split(strings.TrimSpace(string(output)), "\n")
84-
return ports, err
86+
return ports, nil
8587
}
8688

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

94-
if string(output) == "" {
96+
// Do no bridges exist?
97+
if len(output) == 0 {
9598
return nil, nil
9699
}
100+
97101
bridges := strings.Split(strings.TrimSpace(string(output)), "\n")
98-
return bridges, err
102+
return bridges, nil
99103
}
100104

101105
// PortToBridge attempts to determine which bridge a port is attached to.
@@ -116,7 +120,8 @@ func (v *VSwitchService) GetFailMode(bridge string) (FailMode, error) {
116120
if err != nil {
117121
return "", err
118122
}
119-
return FailMode(out), err
123+
124+
return FailMode(out), nil
120125
}
121126

122127
// SetFailMode sets the specified FailMode for the specified bridge.
@@ -138,7 +143,8 @@ func (v *VSwitchService) GetController(bridge string) (string, error) {
138143
if err != nil {
139144
return "", err
140145
}
141-
return strings.TrimSpace(string(address)), err
146+
147+
return strings.TrimSpace(string(address)), nil
142148
}
143149

144150
// exec executes an ExecFunc using 'ovs-vsctl'.
@@ -162,12 +168,15 @@ func (v *VSwitchGetService) Bridge(bridge string) (BridgeOptions, error) {
162168
if err != nil {
163169
return BridgeOptions{}, err
164170
}
165-
protocols := []string{}
166-
err = json.Unmarshal(out, &protocols)
167-
if err != nil {
171+
172+
var protocols []string
173+
if err := json.Unmarshal(out, &protocols); err != nil {
168174
return BridgeOptions{}, err
169175
}
170-
return BridgeOptions{Protocols: protocols}, nil
176+
177+
return BridgeOptions{
178+
Protocols: protocols,
179+
}, nil
171180
}
172181

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

0 commit comments

Comments
 (0)