Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6adbd72

Browse files
committed
Merge pull request #491 from rgbkrk/find-node-by-ip-and-port
Method for finding a node by IP and Port
2 parents b7d9172 + 73e2759 commit 6adbd72

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

rackspace/lb/v1/nodes/requests.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,38 @@ func ListEvents(client *gophercloud.ServiceClient, loadBalancerID int, opts List
249249
return NodeEventPage{pagination.SinglePageBase(r)}
250250
})
251251
}
252+
253+
// GetByIPPort locates a load balancer node by IP and port.
254+
func GetByIPPort(
255+
client *gophercloud.ServiceClient,
256+
loadBalancerID int,
257+
address string,
258+
port int,
259+
) (*Node, error) {
260+
261+
// nil until found
262+
var found *Node
263+
264+
List(client, loadBalancerID, nil).EachPage(func(page pagination.Page) (bool, error) {
265+
lbNodes, err := ExtractNodes(page)
266+
if err != nil {
267+
return false, err
268+
}
269+
270+
for _, trialNode := range lbNodes {
271+
if trialNode.Address == address && trialNode.Port == port {
272+
found = &trialNode
273+
return false, nil
274+
}
275+
276+
}
277+
278+
return true, nil
279+
})
280+
281+
if found == nil {
282+
return nil, errors.New("Unable to get node by IP and Port")
283+
}
284+
285+
return found, nil
286+
}

0 commit comments

Comments
 (0)