|
| 1 | +import os |
1 | 2 | from datacrunch import DataCrunchClient |
2 | 3 | from typing import List |
3 | 4 | from datacrunch.containers.containers import ComputeResource |
4 | 5 |
|
| 6 | +# Get client secret and id from environment variables |
| 7 | +DATACRUNCH_CLIENT_ID = os.environ.get('DATACRUNCH_CLIENT_ID') |
| 8 | +DATACRUNCH_CLIENT_SECRET = os.environ.get('DATACRUNCH_CLIENT_SECRET') |
| 9 | + |
5 | 10 |
|
6 | 11 | def list_all_compute_resources(client: DataCrunchClient) -> List[ComputeResource]: |
7 | 12 | """List all available compute resources. |
@@ -44,27 +49,25 @@ def list_compute_resources_by_size(client: DataCrunchClient, size: int) -> List[ |
44 | 49 |
|
45 | 50 | def main(): |
46 | 51 | # Initialize the client with your credentials |
47 | | - client = DataCrunchClient( |
48 | | - client_id="your_client_id", |
49 | | - client_secret="your_client_secret" |
50 | | - ) |
| 52 | + datacrunch = DataCrunchClient( |
| 53 | + DATACRUNCH_CLIENT_ID, DATACRUNCH_CLIENT_SECRET) |
51 | 54 |
|
52 | 55 | # Example 1: List all compute resources |
53 | | - print("\nAll compute resources:") |
54 | | - all_resources = list_all_compute_resources(client) |
| 56 | + print("All compute resources:") |
| 57 | + all_resources = list_all_compute_resources(datacrunch) |
55 | 58 | for resource in all_resources: |
56 | 59 | print( |
57 | 60 | f"Name: {resource.name}, Size: {resource.size}, Available: {resource.is_available}") |
58 | 61 |
|
59 | 62 | # Example 2: List available compute resources |
60 | | - print("\nAvailable compute resources:") |
61 | | - available_resources = list_available_compute_resources(client) |
| 63 | + print("Available compute resources:") |
| 64 | + available_resources = list_available_compute_resources(datacrunch) |
62 | 65 | for resource in available_resources: |
63 | 66 | print(f"Name: {resource.name}, Size: {resource.size}") |
64 | 67 |
|
65 | 68 | # Example 3: List compute resources of size 8 |
66 | | - print("\nCompute resources with size 8:") |
67 | | - size_8_resources = list_compute_resources_by_size(client, 8) |
| 69 | + print("Compute resources with size 8:") |
| 70 | + size_8_resources = list_compute_resources_by_size(datacrunch, 8) |
68 | 71 | for resource in size_8_resources: |
69 | 72 | print(f"Name: {resource.name}, Available: {resource.is_available}") |
70 | 73 |
|
|
0 commit comments