Spaces:
Paused
Paused
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 | |