waldur-site-agent-cscs-dwdi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of waldur-site-agent-cscs-dwdi might be problematic. Click here for more details.

@@ -0,0 +1,6 @@
1
+ venv/
2
+ .idea/
3
+ .vscode/
4
+ dist/
5
+ **__pycache__
6
+ .DS_Store
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: waldur-site-agent-cscs-dwdi
3
+ Version: 0.1.0
4
+ Summary: CSCS-DWDI reporting plugin for Waldur Site Agent
5
+ Author-email: OpenNode Team <info@opennodecloud.com>
6
+ Requires-Python: <4,>=3.9
7
+ Requires-Dist: httpx>=0.25.0
8
+ Requires-Dist: waldur-site-agent==0.1.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # CSCS-DWDI Plugin for Waldur Site Agent
12
+
13
+ This plugin provides reporting functionality for Waldur Site Agent by integrating with the CSCS-DWDI
14
+ (Data Warehouse and Data Intelligence) API.
15
+
16
+ ## Overview
17
+
18
+ The CSCS-DWDI plugin is a **reporting-only backend** that fetches compute usage data from the CSCS-DWDI
19
+ service and reports it to Waldur. It supports node-hour usage tracking for multiple accounts and users.
20
+
21
+ ## Features
22
+
23
+ - **Monthly Usage Reporting**: Fetches usage data for the current month
24
+ - **Multi-Account Support**: Reports usage for multiple accounts in a single API call
25
+ - **Per-User Usage**: Breaks down usage by individual users within each account
26
+ - **OIDC Authentication**: Uses OAuth2/OIDC for secure API access
27
+ - **Automatic Aggregation**: Combines usage across different clusters and time periods
28
+
29
+ ## Configuration
30
+
31
+ Add the following configuration to your Waldur Site Agent offering:
32
+
33
+ ```yaml
34
+ offerings:
35
+ - name: "CSCS HPC Offering"
36
+ reporting_backend: "cscs-dwdi"
37
+ backend_settings:
38
+ cscs_dwdi_api_url: "https://dwdi-api.cscs.ch"
39
+ cscs_dwdi_client_id: "your-oidc-client-id"
40
+ cscs_dwdi_client_secret: "your-oidc-client-secret"
41
+ # Optional OIDC configuration (for production use)
42
+ cscs_dwdi_oidc_token_url: "https://identity.cscs.ch/realms/cscs/protocol/openid-connect/token"
43
+ cscs_dwdi_oidc_scope: "cscs-dwdi:read"
44
+
45
+ backend_components:
46
+ nodeHours:
47
+ measured_unit: "node-hours"
48
+ unit_factor: 1
49
+ accounting_type: "usage"
50
+ label: "Node Hours"
51
+ storage:
52
+ measured_unit: "TB"
53
+ unit_factor: 1
54
+ accounting_type: "usage"
55
+ label: "Storage Usage"
56
+ ```
57
+
58
+ ### Configuration Parameters
59
+
60
+ #### Backend Settings
61
+
62
+ | Parameter | Required | Description |
63
+ |-----------|----------|-------------|
64
+ | `cscs_dwdi_api_url` | Yes | Base URL for the CSCS-DWDI API service |
65
+ | `cscs_dwdi_client_id` | Yes | OIDC client ID for authentication |
66
+ | `cscs_dwdi_client_secret` | Yes | OIDC client secret for authentication |
67
+ | `cscs_dwdi_oidc_token_url` | Yes | OIDC token endpoint URL (required for authentication) |
68
+ | `cscs_dwdi_oidc_scope` | No | OIDC scope to request (defaults to "openid") |
69
+
70
+ #### Backend Components
71
+
72
+ Components must match the field names returned by the CSCS-DWDI API. For example:
73
+
74
+ - `nodeHours` - Maps to the `nodeHours` field in API responses
75
+ - `storage` - Maps to the `storage` field in API responses (if available)
76
+ - `gpuHours` - Maps to the `gpuHours` field in API responses (if available)
77
+
78
+ Each component supports:
79
+
80
+ | Parameter | Description |
81
+ |-----------|-------------|
82
+ | `measured_unit` | Unit for display in Waldur (e.g., "node-hours", "TB") |
83
+ | `unit_factor` | Conversion factor from API units to measured units |
84
+ | `accounting_type` | Either "usage" for actual usage or "limit" for quotas |
85
+ | `label` | Display label in Waldur interface |
86
+
87
+ ## Usage Data Format
88
+
89
+ The plugin reports usage for all configured components:
90
+
91
+ - **Component Types**: Configurable (e.g., `nodeHours`, `storage`, `gpuHours`)
92
+ - **Units**: Based on API response and `unit_factor` configuration
93
+ - **Granularity**: Monthly reporting with current month data
94
+ - **User Attribution**: Individual user usage within each account
95
+ - **Aggregation**: Automatically aggregates across clusters and time periods
96
+
97
+ ## API Integration
98
+
99
+ The plugin uses the CSCS-DWDI API endpoints:
100
+
101
+ - `GET /api/v1/compute/usage-month-multiaccount` - Primary endpoint for monthly usage data
102
+ - Authentication via OIDC Bearer tokens
103
+
104
+ ### Authentication
105
+
106
+ The plugin uses OAuth2/OIDC authentication with the following requirements:
107
+
108
+ - Requires `cscs_dwdi_oidc_token_url` in backend settings
109
+ - Uses OAuth2 `client_credentials` grant flow
110
+ - Automatically handles token caching and renewal
111
+ - Includes 5-minute safety margin for token expiry
112
+ - Fails with proper error logging if OIDC configuration is missing
113
+
114
+ ### Data Processing
115
+
116
+ 1. **Account Filtering**: Only reports on accounts that match Waldur resource backend IDs
117
+ 2. **User Aggregation**: Combines usage for the same user across different dates and clusters
118
+ 3. **Time Range**: Automatically queries from the first day of the current month to today
119
+ 4. **Precision**: Rounds node-hours to 2 decimal places
120
+
121
+ ## Installation
122
+
123
+ This plugin is part of the Waldur Site Agent workspace. To install:
124
+
125
+ ```bash
126
+ # Install all workspace packages including cscs-dwdi plugin
127
+ uv sync --all-packages
128
+
129
+ # Install specific plugin for development
130
+ uv sync --extra cscs-dwdi
131
+ ```
132
+
133
+ ## Testing
134
+
135
+ Run the plugin tests:
136
+
137
+ ```bash
138
+ # Run CSCS-DWDI plugin tests
139
+ uv run pytest plugins/cscs-dwdi/tests/
140
+
141
+ # Run with coverage
142
+ uv run pytest plugins/cscs-dwdi/tests/ --cov=waldur_site_agent_cscs_dwdi
143
+ ```
144
+
145
+ ## Limitations
146
+
147
+ This is a **reporting-only backend** that does not support:
148
+
149
+ - Account creation or deletion
150
+ - User management
151
+ - Resource limit management
152
+ - Order processing
153
+ - Membership synchronization
154
+
155
+ For these operations, use a different backend (e.g., SLURM) in combination with the CSCS-DWDI reporting backend:
156
+
157
+ ```yaml
158
+ offerings:
159
+ - name: "Mixed Backend Offering"
160
+ order_processing_backend: "slurm" # Use SLURM for orders
161
+ reporting_backend: "cscs-dwdi" # Use CSCS-DWDI for reporting
162
+ membership_sync_backend: "slurm" # Use SLURM for membership
163
+ ```
164
+
165
+ ## Error Handling
166
+
167
+ The plugin includes comprehensive error handling:
168
+
169
+ - **API Connectivity**: Ping checks verify API availability
170
+ - **Authentication**: Token refresh and error handling
171
+ - **Data Validation**: Validates API responses and filters invalid data
172
+ - **Retry Logic**: Uses the framework's built-in retry mechanisms
173
+
174
+ ## Development
175
+
176
+ ### Project Structure
177
+
178
+ ```text
179
+ plugins/cscs-dwdi/
180
+ ├── pyproject.toml # Plugin configuration
181
+ ├── README.md # This documentation
182
+ ├── waldur_site_agent_cscs_dwdi/
183
+ │ ├── __init__.py # Package init
184
+ │ ├── backend.py # Main backend implementation
185
+ │ └── client.py # CSCS-DWDI API client
186
+ └── tests/
187
+ └── test_cscs_dwdi.py # Plugin tests
188
+ ```
189
+
190
+ ### Key Classes
191
+
192
+ - **`CSCSDWDIBackend`**: Main backend class implementing reporting functionality
193
+ - **`CSCSDWDIClient`**: HTTP client for CSCS-DWDI API communication
194
+
195
+ ### Extension Points
196
+
197
+ To extend the plugin:
198
+
199
+ 1. **Additional Endpoints**: Modify `CSCSDWDIClient` to support more API endpoints
200
+ 2. **Authentication Methods**: Update authentication logic in `client.py`
201
+ 3. **Data Processing**: Enhance `_process_api_response()` for additional data formats
202
+
203
+ ## Troubleshooting
204
+
205
+ ### Common Issues
206
+
207
+ #### Authentication Failures
208
+
209
+ - Verify OIDC client credentials
210
+ - Check API URL configuration
211
+ - Ensure proper token scopes
212
+
213
+ #### Missing Usage Data
214
+
215
+ - Verify account names match between Waldur and CSCS-DWDI
216
+ - Check date ranges and API response format
217
+ - Review API rate limits and quotas
218
+
219
+ #### Network Connectivity
220
+
221
+ - Test API connectivity with ping functionality
222
+ - Verify network access from agent deployment environment
223
+ - Check firewall and proxy settings
224
+
225
+ ### Debugging
226
+
227
+ Enable debug logging for detailed API interactions:
228
+
229
+ ```python
230
+ import logging
231
+ logging.getLogger('waldur_site_agent_cscs_dwdi').setLevel(logging.DEBUG)
232
+ ```
233
+
234
+ ## Support
235
+
236
+ For issues and questions:
237
+
238
+ - Check the [Waldur Site Agent documentation](../../docs/)
239
+ - Review plugin test cases for usage examples
240
+ - Create issues in the project repository
@@ -0,0 +1,230 @@
1
+ # CSCS-DWDI Plugin for Waldur Site Agent
2
+
3
+ This plugin provides reporting functionality for Waldur Site Agent by integrating with the CSCS-DWDI
4
+ (Data Warehouse and Data Intelligence) API.
5
+
6
+ ## Overview
7
+
8
+ The CSCS-DWDI plugin is a **reporting-only backend** that fetches compute usage data from the CSCS-DWDI
9
+ service and reports it to Waldur. It supports node-hour usage tracking for multiple accounts and users.
10
+
11
+ ## Features
12
+
13
+ - **Monthly Usage Reporting**: Fetches usage data for the current month
14
+ - **Multi-Account Support**: Reports usage for multiple accounts in a single API call
15
+ - **Per-User Usage**: Breaks down usage by individual users within each account
16
+ - **OIDC Authentication**: Uses OAuth2/OIDC for secure API access
17
+ - **Automatic Aggregation**: Combines usage across different clusters and time periods
18
+
19
+ ## Configuration
20
+
21
+ Add the following configuration to your Waldur Site Agent offering:
22
+
23
+ ```yaml
24
+ offerings:
25
+ - name: "CSCS HPC Offering"
26
+ reporting_backend: "cscs-dwdi"
27
+ backend_settings:
28
+ cscs_dwdi_api_url: "https://dwdi-api.cscs.ch"
29
+ cscs_dwdi_client_id: "your-oidc-client-id"
30
+ cscs_dwdi_client_secret: "your-oidc-client-secret"
31
+ # Optional OIDC configuration (for production use)
32
+ cscs_dwdi_oidc_token_url: "https://identity.cscs.ch/realms/cscs/protocol/openid-connect/token"
33
+ cscs_dwdi_oidc_scope: "cscs-dwdi:read"
34
+
35
+ backend_components:
36
+ nodeHours:
37
+ measured_unit: "node-hours"
38
+ unit_factor: 1
39
+ accounting_type: "usage"
40
+ label: "Node Hours"
41
+ storage:
42
+ measured_unit: "TB"
43
+ unit_factor: 1
44
+ accounting_type: "usage"
45
+ label: "Storage Usage"
46
+ ```
47
+
48
+ ### Configuration Parameters
49
+
50
+ #### Backend Settings
51
+
52
+ | Parameter | Required | Description |
53
+ |-----------|----------|-------------|
54
+ | `cscs_dwdi_api_url` | Yes | Base URL for the CSCS-DWDI API service |
55
+ | `cscs_dwdi_client_id` | Yes | OIDC client ID for authentication |
56
+ | `cscs_dwdi_client_secret` | Yes | OIDC client secret for authentication |
57
+ | `cscs_dwdi_oidc_token_url` | Yes | OIDC token endpoint URL (required for authentication) |
58
+ | `cscs_dwdi_oidc_scope` | No | OIDC scope to request (defaults to "openid") |
59
+
60
+ #### Backend Components
61
+
62
+ Components must match the field names returned by the CSCS-DWDI API. For example:
63
+
64
+ - `nodeHours` - Maps to the `nodeHours` field in API responses
65
+ - `storage` - Maps to the `storage` field in API responses (if available)
66
+ - `gpuHours` - Maps to the `gpuHours` field in API responses (if available)
67
+
68
+ Each component supports:
69
+
70
+ | Parameter | Description |
71
+ |-----------|-------------|
72
+ | `measured_unit` | Unit for display in Waldur (e.g., "node-hours", "TB") |
73
+ | `unit_factor` | Conversion factor from API units to measured units |
74
+ | `accounting_type` | Either "usage" for actual usage or "limit" for quotas |
75
+ | `label` | Display label in Waldur interface |
76
+
77
+ ## Usage Data Format
78
+
79
+ The plugin reports usage for all configured components:
80
+
81
+ - **Component Types**: Configurable (e.g., `nodeHours`, `storage`, `gpuHours`)
82
+ - **Units**: Based on API response and `unit_factor` configuration
83
+ - **Granularity**: Monthly reporting with current month data
84
+ - **User Attribution**: Individual user usage within each account
85
+ - **Aggregation**: Automatically aggregates across clusters and time periods
86
+
87
+ ## API Integration
88
+
89
+ The plugin uses the CSCS-DWDI API endpoints:
90
+
91
+ - `GET /api/v1/compute/usage-month-multiaccount` - Primary endpoint for monthly usage data
92
+ - Authentication via OIDC Bearer tokens
93
+
94
+ ### Authentication
95
+
96
+ The plugin uses OAuth2/OIDC authentication with the following requirements:
97
+
98
+ - Requires `cscs_dwdi_oidc_token_url` in backend settings
99
+ - Uses OAuth2 `client_credentials` grant flow
100
+ - Automatically handles token caching and renewal
101
+ - Includes 5-minute safety margin for token expiry
102
+ - Fails with proper error logging if OIDC configuration is missing
103
+
104
+ ### Data Processing
105
+
106
+ 1. **Account Filtering**: Only reports on accounts that match Waldur resource backend IDs
107
+ 2. **User Aggregation**: Combines usage for the same user across different dates and clusters
108
+ 3. **Time Range**: Automatically queries from the first day of the current month to today
109
+ 4. **Precision**: Rounds node-hours to 2 decimal places
110
+
111
+ ## Installation
112
+
113
+ This plugin is part of the Waldur Site Agent workspace. To install:
114
+
115
+ ```bash
116
+ # Install all workspace packages including cscs-dwdi plugin
117
+ uv sync --all-packages
118
+
119
+ # Install specific plugin for development
120
+ uv sync --extra cscs-dwdi
121
+ ```
122
+
123
+ ## Testing
124
+
125
+ Run the plugin tests:
126
+
127
+ ```bash
128
+ # Run CSCS-DWDI plugin tests
129
+ uv run pytest plugins/cscs-dwdi/tests/
130
+
131
+ # Run with coverage
132
+ uv run pytest plugins/cscs-dwdi/tests/ --cov=waldur_site_agent_cscs_dwdi
133
+ ```
134
+
135
+ ## Limitations
136
+
137
+ This is a **reporting-only backend** that does not support:
138
+
139
+ - Account creation or deletion
140
+ - User management
141
+ - Resource limit management
142
+ - Order processing
143
+ - Membership synchronization
144
+
145
+ For these operations, use a different backend (e.g., SLURM) in combination with the CSCS-DWDI reporting backend:
146
+
147
+ ```yaml
148
+ offerings:
149
+ - name: "Mixed Backend Offering"
150
+ order_processing_backend: "slurm" # Use SLURM for orders
151
+ reporting_backend: "cscs-dwdi" # Use CSCS-DWDI for reporting
152
+ membership_sync_backend: "slurm" # Use SLURM for membership
153
+ ```
154
+
155
+ ## Error Handling
156
+
157
+ The plugin includes comprehensive error handling:
158
+
159
+ - **API Connectivity**: Ping checks verify API availability
160
+ - **Authentication**: Token refresh and error handling
161
+ - **Data Validation**: Validates API responses and filters invalid data
162
+ - **Retry Logic**: Uses the framework's built-in retry mechanisms
163
+
164
+ ## Development
165
+
166
+ ### Project Structure
167
+
168
+ ```text
169
+ plugins/cscs-dwdi/
170
+ ├── pyproject.toml # Plugin configuration
171
+ ├── README.md # This documentation
172
+ ├── waldur_site_agent_cscs_dwdi/
173
+ │ ├── __init__.py # Package init
174
+ │ ├── backend.py # Main backend implementation
175
+ │ └── client.py # CSCS-DWDI API client
176
+ └── tests/
177
+ └── test_cscs_dwdi.py # Plugin tests
178
+ ```
179
+
180
+ ### Key Classes
181
+
182
+ - **`CSCSDWDIBackend`**: Main backend class implementing reporting functionality
183
+ - **`CSCSDWDIClient`**: HTTP client for CSCS-DWDI API communication
184
+
185
+ ### Extension Points
186
+
187
+ To extend the plugin:
188
+
189
+ 1. **Additional Endpoints**: Modify `CSCSDWDIClient` to support more API endpoints
190
+ 2. **Authentication Methods**: Update authentication logic in `client.py`
191
+ 3. **Data Processing**: Enhance `_process_api_response()` for additional data formats
192
+
193
+ ## Troubleshooting
194
+
195
+ ### Common Issues
196
+
197
+ #### Authentication Failures
198
+
199
+ - Verify OIDC client credentials
200
+ - Check API URL configuration
201
+ - Ensure proper token scopes
202
+
203
+ #### Missing Usage Data
204
+
205
+ - Verify account names match between Waldur and CSCS-DWDI
206
+ - Check date ranges and API response format
207
+ - Review API rate limits and quotas
208
+
209
+ #### Network Connectivity
210
+
211
+ - Test API connectivity with ping functionality
212
+ - Verify network access from agent deployment environment
213
+ - Check firewall and proxy settings
214
+
215
+ ### Debugging
216
+
217
+ Enable debug logging for detailed API interactions:
218
+
219
+ ```python
220
+ import logging
221
+ logging.getLogger('waldur_site_agent_cscs_dwdi').setLevel(logging.DEBUG)
222
+ ```
223
+
224
+ ## Support
225
+
226
+ For issues and questions:
227
+
228
+ - Check the [Waldur Site Agent documentation](../../docs/)
229
+ - Review plugin test cases for usage examples
230
+ - Create issues in the project repository
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "waldur-site-agent-cscs-dwdi"
3
+ version = "0.1.0"
4
+ description = "CSCS-DWDI reporting plugin for Waldur Site Agent"
5
+ readme = "README.md"
6
+ authors = [{ name = "OpenNode Team", email = "info@opennodecloud.com" }]
7
+ requires-python = ">=3.9, <4"
8
+ dependencies = [
9
+ "waldur-site-agent==0.1.0",
10
+ "httpx>=0.25.0",
11
+ ]
12
+
13
+ [build-system]
14
+ requires = ["hatchling"]
15
+ build-backend = "hatchling.build"
16
+
17
+ [tool.uv.sources]
18
+ waldur-site-agent = { workspace = true }
19
+
20
+ # Entry points for exporting backends
21
+ [project.entry-points."waldur_site_agent.backends"]
22
+ cscs-dwdi = "waldur_site_agent_cscs_dwdi.backend:CSCSDWDIBackend"