File size: 1,259 Bytes
2e81e75 dd2f10e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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/post/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
def get_file_structure(self):
api_endpoint = f'{self.base_url}/api/get/file_structure'
try:
headers = {'Content-Type': 'application/json'}
response = requests.get(api_endpoint, 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 file structure: {e}')
return None
|