Automated Retrieval and Analysis of Available Servers on the Marketplace
Objective: This example demonstrates how to use Clore's marketplace
API endpoint to automate the retrieval of available servers. It includes filtering server options based on user-defined specifications, such as GPU type, minimum RAM, and price range, making it ideal for users who want to dynamically select suitable servers from the marketplace.
Step 1: Fetch the List of Available Servers
The code below demonstrates how to retrieve and filter the list of available servers based on certain parameters, such as GPU model, minimum RAM, and a maximum price in USD.
import requests
# Set user-defined filter parameters
min_ram = 16 # Minimum RAM in GB
max_price_usd = 0.005 # Maximum price per day in USD
gpu_model = 'GeForce GTX 1080 Ti' # Desired GPU model
# API endpoint for the marketplace
url = 'https://api.clore.ai/v1/marketplace'
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
# Retrieve list of servers on the marketplace
response = requests.get(url, headers=headers)
if response.status_code == 200:
servers = response.json().get('servers', [])
# Filter servers by user-defined criteria
filtered_servers = [
server for server in servers
if server['specs']['ram'] >= min_ram and
server['price']['on_demand']['usd'] <= max_price_usd and
gpu_model in server['specs']['gpu']
]
else:
print(f"Error {response.status_code}: {response.text}")
filtered_servers = []
print(f"Found {len(filtered_servers)} servers that match the filters.")
Step 2: Analyze the Filtered Servers
With the filtered list, we can analyze specific attributes, such as server pricing and specifications, to help users make informed decisions.
# Display the filtered servers with relevant information
for server in filtered_servers:
print(f"Server Name: {server['specs']['name']}")
print(f"RAM: {server['specs']['ram']} GB")
print(f"GPU: {server['specs']['gpu']}")
print(f"Price per Day: {server['price']['on_demand']['usd']} USD")
print(f"Maximum Rental Duration: {server['mrl']} hours\n")
Step 3: Automate Server Selection
Using the filtered list, select the most suitable server based on additional criteria, such as availability for immediate rental, and proceed with the rental request. If the first server is not available, the script will attempt to select the next server.
def select_server_for_rental(servers):
# Example logic to select the best server for rental
for server in servers:
if server['availability']:
return server
return None
selected_server = select_server_for_rental(filtered_servers)
if selected_server:
print(f"Selected server for rental: {selected_server['specs']['name']}")
else:
print("No available servers meet the criteria.")
Summary
This example showcases a structured approach to:
Retrieve and filter available servers from the Clore marketplace based on user-defined criteria.
Analyze and select a suitable server for rental.
Prepare for automated execution by looping through available servers if the preferred server is not immediately rentable.
This example lays the groundwork for more complex automated server selection and rental processes, making it useful for users who rely on Clore's marketplace for dynamic and consistent computing resources.
Last updated