import os import logging from server_manager import ServerManager from server_data import ServerData def validate_env_vars(): api_key = os.getenv('API_KEY') host = os.getenv('HOST') if not api_key: raise Exception('API_KEY not found in environment variables') if not host: raise Exception('HOST not found in environment variables') return host, api_key def main(): logging.basicConfig(level=logging.INFO) host, api_key = validate_env_vars() server_data = ServerData() post_data = server_data.create_post_data() server_manager = ServerManager(host, api_key) # Check if the server already exists server_id = server_manager.existing_server_id(post_data) # If the server exists, update it if server_id: logging.info('Server already exists with id: {}, Updating...'.format(server_id)) logging.info(server_manager.update_server(post_data, server_id)) else: logging.info('Server does not exist, Creating...') logging.info(server_manager.create_server(post_data)) if __name__ == '__main__': main()