Softlayer API get load balancer destinationIpAddress

113 views Asked by At

I am wanting to find out the ids of the servers a load balancer is distributing traffic to.

https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress

We've experimented with some of the calls outlined on the following question, but do not seem to be able to find a way to list the servers.

softlayer local Load Balancer manage API

Is it possible to get a list of servers that the load balancer is distributing traffic to? Thanks!

2

There are 2 answers

0
Pedro David Fuentes Antezana On BEST ANSWER

You can obtain the list of servers that a load balancer is distributing traffic to, using the next REST request or you could use this python script as well:

https://$username:[email protected]/rest/v3/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress/$loadBalancerId/getVirtualServers.json?objectMask=mask[serviceGroups[services[ipAddress[virtualGuest]]]]
Method: GET

Python script

"""
Retrieve the servers that a load balancer is distributing traffic to.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress/getVirtualServers

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <[email protected]>
"""

import SoftLayer
import json

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

loadBalancerId = 79945

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
loadBalancerService = client['SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress']
objectMask = 'mask[serviceGroups[id,services[id,ipAddress[virtualGuest]]]]'

try:
    virtualServers = loadBalancerService.getVirtualServers(mask=objectMask, id=loadBalancerId)
    print(json.dumps(virtualServers, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to retrieve Virtual Servers. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    exit(1)
0
Ruber Cuellar Valenzuela On

Try this:

https://$username:[email protected]/rest/v3/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress/$loadBalancerId/getVirtualServers.json?objectMask=mask[id,serviceGroups[id,services[id,ipAddress[id,virtualGuest[id,hostname,domain]]]]]

Method: Get

It will provide the Virtual Guests (id, hostname and domain) which belongs to the Load Balancer.