|
1 | 1 | import os |
2 | 2 | from datacrunch import DataCrunchClient |
3 | | -from typing import List |
4 | | -from datacrunch.containers.containers import ComputeResource |
5 | 3 |
|
6 | 4 | # Get client secret and id from environment variables |
7 | 5 | DATACRUNCH_CLIENT_ID = os.environ.get('DATACRUNCH_CLIENT_ID') |
8 | 6 | DATACRUNCH_CLIENT_SECRET = os.environ.get('DATACRUNCH_CLIENT_SECRET') |
9 | 7 |
|
10 | | - |
11 | | -def list_all_compute_resources(client: DataCrunchClient) -> List[ComputeResource]: |
12 | | - """List all available compute resources. |
13 | | -
|
14 | | - Args: |
15 | | - client (DataCrunchClient): The DataCrunch API client. |
16 | | -
|
17 | | - Returns: |
18 | | - List[ComputeResource]: List of all compute resources. |
19 | | - """ |
20 | | - return client.containers.get_compute_resources() |
21 | | - |
22 | | - |
23 | | -def list_available_compute_resources(client: DataCrunchClient) -> List[ComputeResource]: |
24 | | - """List only the available compute resources. |
25 | | -
|
26 | | - Args: |
27 | | - client (DataCrunchClient): The DataCrunch API client. |
28 | | -
|
29 | | - Returns: |
30 | | - List[ComputeResource]: List of available compute resources. |
31 | | - """ |
32 | | - all_resources = client.containers.get_compute_resources() |
33 | | - return [r for r in all_resources if r.is_available] |
34 | | - |
35 | | - |
36 | | -def list_compute_resources_by_size(client: DataCrunchClient, size: int) -> List[ComputeResource]: |
37 | | - """List compute resources filtered by size. |
38 | | -
|
39 | | - Args: |
40 | | - client (DataCrunchClient): The DataCrunch API client. |
41 | | - size (int): The size to filter by. |
42 | | -
|
43 | | - Returns: |
44 | | - List[ComputeResource]: List of compute resources with the specified size. |
45 | | - """ |
46 | | - all_resources = client.containers.get_compute_resources() |
47 | | - return [r for r in all_resources if r.size == size] |
48 | | - |
49 | | - |
50 | | -def main(): |
51 | | - # Initialize the client with your credentials |
52 | | - datacrunch = DataCrunchClient( |
53 | | - DATACRUNCH_CLIENT_ID, DATACRUNCH_CLIENT_SECRET) |
54 | | - |
55 | | - # Example 1: List all compute resources |
56 | | - print("All compute resources:") |
57 | | - all_resources = list_all_compute_resources(datacrunch) |
58 | | - for resource in all_resources: |
59 | | - print( |
60 | | - f"Name: {resource.name}, Size: {resource.size}, Available: {resource.is_available}") |
61 | | - |
62 | | - # Example 2: List available compute resources |
63 | | - print("Available compute resources:") |
64 | | - available_resources = list_available_compute_resources(datacrunch) |
65 | | - for resource in available_resources: |
66 | | - print(f"Name: {resource.name}, Size: {resource.size}") |
67 | | - |
68 | | - # Example 3: List compute resources of size 8 |
69 | | - print("Compute resources with size 8:") |
70 | | - size_8_resources = list_compute_resources_by_size(datacrunch, 8) |
71 | | - for resource in size_8_resources: |
72 | | - print(f"Name: {resource.name}, Available: {resource.is_available}") |
73 | | - |
74 | | - |
75 | | -if __name__ == "__main__": |
76 | | - main() |
| 8 | +# Initialize the client with your credentials |
| 9 | +datacrunch = DataCrunchClient(DATACRUNCH_CLIENT_ID, DATACRUNCH_CLIENT_SECRET) |
| 10 | + |
| 11 | +# Example 1: List all compute resources |
| 12 | +print("All compute resources:") |
| 13 | +all_resources = datacrunch.containers.get_compute_resources() |
| 14 | +for resource in all_resources: |
| 15 | + print( |
| 16 | + f"Name: {resource.name}, Size: {resource.size}, Available: {resource.is_available}") |
| 17 | + |
| 18 | +# Example 2: List available compute resources |
| 19 | +print("\nAvailable compute resources:") |
| 20 | +available_resources = datacrunch.containers.get_compute_resources( |
| 21 | + is_available=True) |
| 22 | +for resource in available_resources: |
| 23 | + print(f"Name: {resource.name}, Size: {resource.size}") |
| 24 | + |
| 25 | +# Example 3: List compute resources of size 8 |
| 26 | +print("\nCompute resources with size 8:") |
| 27 | +size_8_resources = datacrunch.containers.get_compute_resources(size=8) |
| 28 | +for resource in size_8_resources: |
| 29 | + print(f"Name: {resource.name}, Available: {resource.is_available}") |
0 commit comments