我想找出负载均衡器正在分配流量的服务器的ID。
我们已经尝试了以下问题中列出的一些调用,但似乎无法找到列出服务器的方法。
softlayer local Load Balancer manage API
是否可以获取负载均衡器正在向其分配流量的服务器列表?谢谢!
答案 0 :(得分:0)
您可以使用下一个REST请求获取负载均衡器正在向其分配流量的服务器列表,或者也可以使用此python脚本:
https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress/$loadBalancerId/getVirtualServers.json?objectMask=mask[serviceGroups[services[ipAddress[virtualGuest]]]]
Method: GET
Python脚本
"""
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. <sldn@softlayer.com>
"""
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)
答案 1 :(得分:0)
试试这个:
https://$username:$apiKey@api.softlayer.com/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
它将提供属于Load Balancer的虚拟访客(id,主机名和域)。