Spaces:
Paused
Paused
File size: 765 Bytes
5cf4c09 ff78474 5cf4c09 ff78474 5cf4c09 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import requests
import logging
import json
class LoadBalancerAPI:
def __init__(self, base_url):
self.base_url = base_url
def register_instance(self, instance_id, instance_url):
data = {
"url": instance_url
}
api_endpoint = f'{self.base_url}/api/register'
try:
headers = {'Content-Type': 'application/json'}
response = requests.post(api_endpoint, data=json.dumps(data), headers=headers)
response.raise_for_status()
return response.json() # Assuming the API returns JSON
except requests.exceptions.RequestException as e:
logging.error(f'Failed to register instance {instance_id} to load balancer: {e}')
return None
|