instance1 / api.py
ChandimaPrabath's picture
init
dd2f10e
raw
history blame
1.26 kB
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