waldur-site-agent-cscs-dwdi 0.8.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.
- waldur_site_agent_cscs_dwdi-0.8.0/.gitignore +6 -0
- waldur_site_agent_cscs_dwdi-0.8.0/PKG-INFO +404 -0
- waldur_site_agent_cscs_dwdi-0.8.0/README.md +394 -0
- waldur_site_agent_cscs_dwdi-0.8.0/pyproject.toml +23 -0
- waldur_site_agent_cscs_dwdi-0.8.0/tests/test_cscs_dwdi.py +562 -0
- waldur_site_agent_cscs_dwdi-0.8.0/waldur_site_agent_cscs_dwdi/__init__.py +1 -0
- waldur_site_agent_cscs_dwdi-0.8.0/waldur_site_agent_cscs_dwdi/backend.py +747 -0
- waldur_site_agent_cscs_dwdi-0.8.0/waldur_site_agent_cscs_dwdi/client.py +436 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: waldur-site-agent-cscs-dwdi
|
|
3
|
+
Version: 0.8.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.7.0
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# CSCS-DWDI Plugin for Waldur Site Agent
|
|
12
|
+
|
|
13
|
+
This plugin provides integration with the CSCS Data Warehouse Data Intelligence (DWDI) system to report both
|
|
14
|
+
computational and storage usage data to Waldur. The plugin supports secure OIDC authentication and optional
|
|
15
|
+
SOCKS proxy connectivity for accessing DWDI API endpoints from restricted networks.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **Dual Backend Support**: Separate backends for compute and storage resource usage reporting
|
|
20
|
+
- **OIDC Authentication**: Secure client credentials flow with automatic token refresh
|
|
21
|
+
- **Proxy Support**: SOCKS and HTTP proxy support for network-restricted environments
|
|
22
|
+
- **Flexible Configuration**: Configurable unit conversions and component mappings
|
|
23
|
+
- **Production Ready**: Comprehensive error handling and logging
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
The plugin implements two separate backends to handle different types of accounting data:
|
|
28
|
+
|
|
29
|
+
- **Compute Backend** (`cscs-dwdi-compute`): Reports CPU and node hour usage from HPC clusters
|
|
30
|
+
- **Storage Backend** (`cscs-dwdi-storage`): Reports storage space and inode usage from filesystems
|
|
31
|
+
|
|
32
|
+
## Backend Types
|
|
33
|
+
|
|
34
|
+
### Compute Backend
|
|
35
|
+
|
|
36
|
+
The compute backend queries the DWDI API for computational resource usage and reports:
|
|
37
|
+
|
|
38
|
+
- Node hours consumed by accounts and users
|
|
39
|
+
- CPU hours consumed by accounts and users
|
|
40
|
+
- Account-level and user-level usage aggregation
|
|
41
|
+
|
|
42
|
+
**API Endpoints Used:**
|
|
43
|
+
|
|
44
|
+
- `/api/v1/compute/usage-month/account` - Monthly usage data
|
|
45
|
+
- `/api/v1/compute/usage-day/account` - Daily usage data
|
|
46
|
+
|
|
47
|
+
### Storage Backend
|
|
48
|
+
|
|
49
|
+
The storage backend queries the DWDI API for storage resource usage and reports:
|
|
50
|
+
|
|
51
|
+
- Storage space used (converted from bytes to configured units)
|
|
52
|
+
- Inode (file count) usage
|
|
53
|
+
- Path-based resource identification
|
|
54
|
+
|
|
55
|
+
**API Endpoints Used:**
|
|
56
|
+
|
|
57
|
+
- `/api/v1/storage/usage-month/filesystem_name/data_type` - Monthly storage usage
|
|
58
|
+
- `/api/v1/storage/usage-day/filesystem_name/data_type` - Daily storage usage
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
### Compute Backend Configuration
|
|
63
|
+
|
|
64
|
+
```yaml
|
|
65
|
+
backend_type: "cscs-dwdi-compute"
|
|
66
|
+
|
|
67
|
+
backend_settings:
|
|
68
|
+
cscs_dwdi_api_url: "https://dwdi.cscs.ch"
|
|
69
|
+
cscs_dwdi_client_id: "your_oidc_client_id"
|
|
70
|
+
cscs_dwdi_client_secret: "your_oidc_client_secret"
|
|
71
|
+
cscs_dwdi_oidc_token_url: "https://auth.cscs.ch/realms/cscs/protocol/openid-connect/token"
|
|
72
|
+
cscs_dwdi_oidc_scope: "openid" # Optional
|
|
73
|
+
|
|
74
|
+
backend_components:
|
|
75
|
+
nodeHours:
|
|
76
|
+
measured_unit: "node-hours"
|
|
77
|
+
unit_factor: 1
|
|
78
|
+
accounting_type: "usage"
|
|
79
|
+
label: "Node Hours"
|
|
80
|
+
|
|
81
|
+
cpuHours:
|
|
82
|
+
measured_unit: "cpu-hours"
|
|
83
|
+
unit_factor: 1
|
|
84
|
+
accounting_type: "usage"
|
|
85
|
+
label: "CPU Hours"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Storage Backend Configuration
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
backend_type: "cscs-dwdi-storage"
|
|
92
|
+
|
|
93
|
+
backend_settings:
|
|
94
|
+
cscs_dwdi_api_url: "https://dwdi.cscs.ch"
|
|
95
|
+
cscs_dwdi_client_id: "your_oidc_client_id"
|
|
96
|
+
cscs_dwdi_client_secret: "your_oidc_client_secret"
|
|
97
|
+
cscs_dwdi_oidc_token_url: "https://auth.cscs.ch/realms/cscs/protocol/openid-connect/token"
|
|
98
|
+
|
|
99
|
+
# Storage-specific settings
|
|
100
|
+
storage_filesystem: "lustre"
|
|
101
|
+
storage_data_type: "projects"
|
|
102
|
+
storage_tenant: "cscs" # Optional
|
|
103
|
+
|
|
104
|
+
# Map Waldur resource IDs to storage paths
|
|
105
|
+
storage_path_mapping:
|
|
106
|
+
"project_123": "/store/projects/proj123"
|
|
107
|
+
"project_456": "/store/projects/proj456"
|
|
108
|
+
|
|
109
|
+
backend_components:
|
|
110
|
+
storage_space:
|
|
111
|
+
measured_unit: "GB"
|
|
112
|
+
unit_factor: 0.000000001 # Convert bytes to GB
|
|
113
|
+
accounting_type: "usage"
|
|
114
|
+
label: "Storage Space (GB)"
|
|
115
|
+
|
|
116
|
+
storage_inodes:
|
|
117
|
+
measured_unit: "count"
|
|
118
|
+
unit_factor: 1
|
|
119
|
+
accounting_type: "usage"
|
|
120
|
+
label: "File Count"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Authentication
|
|
124
|
+
|
|
125
|
+
Both backends use OIDC client credentials flow for authentication with the DWDI API. The authentication tokens are
|
|
126
|
+
automatically managed with refresh capabilities.
|
|
127
|
+
|
|
128
|
+
### Required Settings
|
|
129
|
+
|
|
130
|
+
- `cscs_dwdi_client_id`: OIDC client identifier
|
|
131
|
+
- `cscs_dwdi_client_secret`: OIDC client secret
|
|
132
|
+
- `cscs_dwdi_oidc_token_url`: OIDC token endpoint URL
|
|
133
|
+
|
|
134
|
+
### Optional Settings
|
|
135
|
+
|
|
136
|
+
- `cscs_dwdi_oidc_scope`: OIDC scope (defaults to "openid")
|
|
137
|
+
|
|
138
|
+
### Token Management
|
|
139
|
+
|
|
140
|
+
- Tokens are automatically acquired and cached
|
|
141
|
+
- Automatic token refresh before expiration
|
|
142
|
+
- Error handling for authentication failures
|
|
143
|
+
|
|
144
|
+
## SOCKS Proxy Support
|
|
145
|
+
|
|
146
|
+
Both backends support SOCKS proxy for network connectivity. This is useful when the DWDI API is only accessible
|
|
147
|
+
through a proxy or jump host.
|
|
148
|
+
|
|
149
|
+
### SOCKS Proxy Configuration
|
|
150
|
+
|
|
151
|
+
Add the SOCKS proxy setting to your backend configuration:
|
|
152
|
+
|
|
153
|
+
```yaml
|
|
154
|
+
backend_settings:
|
|
155
|
+
# ... other settings ...
|
|
156
|
+
socks_proxy: "socks5://localhost:12345" # SOCKS5 proxy URL
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Supported Proxy Types
|
|
160
|
+
|
|
161
|
+
- **SOCKS5**: `socks5://hostname:port`
|
|
162
|
+
- **SOCKS4**: `socks4://hostname:port`
|
|
163
|
+
- **HTTP**: `http://hostname:port`
|
|
164
|
+
|
|
165
|
+
### Usage Examples
|
|
166
|
+
|
|
167
|
+
**SSH Tunnel with SOCKS5:**
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# Create SSH tunnel to jump host
|
|
171
|
+
ssh -D 12345 -N user@jumphost.cscs.ch
|
|
172
|
+
|
|
173
|
+
# Configure backend to use tunnel
|
|
174
|
+
backend_settings:
|
|
175
|
+
socks_proxy: "socks5://localhost:12345"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**HTTP Proxy:**
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
backend_settings:
|
|
182
|
+
socks_proxy: "http://proxy.cscs.ch:8080"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Resource Identification
|
|
186
|
+
|
|
187
|
+
### Compute Resources
|
|
188
|
+
|
|
189
|
+
For compute resources, the system uses account names as returned by the DWDI API. The Waldur resource
|
|
190
|
+
`backend_id` should match the account name in the cluster accounting system.
|
|
191
|
+
|
|
192
|
+
### Storage Resources
|
|
193
|
+
|
|
194
|
+
For storage resources, there are two options:
|
|
195
|
+
|
|
196
|
+
1. **Direct Path Usage**: Set the Waldur resource `backend_id` to the actual filesystem path
|
|
197
|
+
2. **Path Mapping**: Use the `storage_path_mapping` setting to map resource IDs to paths
|
|
198
|
+
|
|
199
|
+
## Usage Reporting
|
|
200
|
+
|
|
201
|
+
Both backends are read-only and designed for usage reporting. They implement the `_get_usage_report()` method
|
|
202
|
+
but do not support:
|
|
203
|
+
|
|
204
|
+
- Account creation/deletion
|
|
205
|
+
- Resource management
|
|
206
|
+
- User management
|
|
207
|
+
- Limit setting
|
|
208
|
+
|
|
209
|
+
## Example Configurations
|
|
210
|
+
|
|
211
|
+
See the `examples/` directory for complete configuration examples:
|
|
212
|
+
|
|
213
|
+
- `cscs-dwdi-compute-config.yaml` - Compute backend only
|
|
214
|
+
- `cscs-dwdi-storage-config.yaml` - Storage backend only
|
|
215
|
+
- `cscs-dwdi-combined-config.yaml` - Both backends in one configuration
|
|
216
|
+
|
|
217
|
+
## Installation
|
|
218
|
+
|
|
219
|
+
The plugin is automatically discovered when the waldur-site-agent-cscs-dwdi package is installed alongside waldur-site-agent.
|
|
220
|
+
|
|
221
|
+
### UV Workspace Installation
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Install all workspace packages including cscs-dwdi plugin
|
|
225
|
+
uv sync --all-packages
|
|
226
|
+
|
|
227
|
+
# Or install specific plugin dependencies only
|
|
228
|
+
uv sync --extra cscs-dwdi
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Manual Installation
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Install from PyPI (when published)
|
|
235
|
+
pip install waldur-site-agent-cscs-dwdi
|
|
236
|
+
|
|
237
|
+
# Install from source
|
|
238
|
+
pip install -e plugins/cscs-dwdi/
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Testing
|
|
242
|
+
|
|
243
|
+
### Running Tests
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Run all cscs-dwdi tests
|
|
247
|
+
uv run pytest plugins/cscs-dwdi/tests/
|
|
248
|
+
|
|
249
|
+
# Run with coverage
|
|
250
|
+
uv run pytest plugins/cscs-dwdi/tests/ --cov=waldur_site_agent_cscs_dwdi
|
|
251
|
+
|
|
252
|
+
# Run specific test files
|
|
253
|
+
uv run pytest plugins/cscs-dwdi/tests/test_cscs_dwdi.py -v
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Test Coverage
|
|
257
|
+
|
|
258
|
+
The test suite covers:
|
|
259
|
+
|
|
260
|
+
- Client initialization and configuration
|
|
261
|
+
- OIDC authentication flow
|
|
262
|
+
- API endpoint calls (mocked)
|
|
263
|
+
- Usage data processing
|
|
264
|
+
- Error handling scenarios
|
|
265
|
+
- Backend initialization and validation
|
|
266
|
+
|
|
267
|
+
## API Compatibility
|
|
268
|
+
|
|
269
|
+
This plugin is compatible with DWDI API version 1 (`/api/v1/`). It requires the following API endpoints to be available:
|
|
270
|
+
|
|
271
|
+
**Compute API:**
|
|
272
|
+
|
|
273
|
+
- `/api/v1/compute/usage-month/account`
|
|
274
|
+
- `/api/v1/compute/usage-day/account`
|
|
275
|
+
|
|
276
|
+
**Storage API:**
|
|
277
|
+
|
|
278
|
+
- `/api/v1/storage/usage-month/filesystem_name/data_type`
|
|
279
|
+
- `/api/v1/storage/usage-day/filesystem_name/data_type`
|
|
280
|
+
|
|
281
|
+
## Troubleshooting
|
|
282
|
+
|
|
283
|
+
### Authentication Issues
|
|
284
|
+
|
|
285
|
+
**Problem**: Authentication failures or token errors
|
|
286
|
+
|
|
287
|
+
**Solutions**:
|
|
288
|
+
|
|
289
|
+
- Verify OIDC client credentials are correct
|
|
290
|
+
- Check that the token endpoint URL is accessible
|
|
291
|
+
- Ensure the client has appropriate scopes for DWDI API access
|
|
292
|
+
- Verify network connectivity to the OIDC provider
|
|
293
|
+
- Check logs for specific authentication error messages
|
|
294
|
+
|
|
295
|
+
**Testing authentication**:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# Test OIDC token acquisition manually
|
|
299
|
+
curl -X POST "https://auth.cscs.ch/realms/cscs/protocol/openid-connect/token" \
|
|
300
|
+
-H "Content-Type: application/x-www-form-urlencoded" \
|
|
301
|
+
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_SECRET&scope=openid"
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Storage Backend Issues
|
|
305
|
+
|
|
306
|
+
**Problem**: Storage usage data not found or incorrect
|
|
307
|
+
|
|
308
|
+
**Solutions**:
|
|
309
|
+
|
|
310
|
+
- Verify `storage_filesystem` and `storage_data_type` match available values in DWDI
|
|
311
|
+
- Check `storage_path_mapping` if using custom resource IDs
|
|
312
|
+
- Ensure storage paths exist in the DWDI system
|
|
313
|
+
- Validate that the paths have usage data for the requested time period
|
|
314
|
+
|
|
315
|
+
### Connection Issues
|
|
316
|
+
|
|
317
|
+
**Problem**: Network connectivity or API access failures
|
|
318
|
+
|
|
319
|
+
**Solutions**:
|
|
320
|
+
|
|
321
|
+
- Use the `ping()` method to test API connectivity
|
|
322
|
+
- Check network connectivity to the DWDI API endpoint
|
|
323
|
+
- Verify SSL/TLS configuration and certificates
|
|
324
|
+
- If behind a firewall, configure SOCKS proxy (`socks_proxy` setting)
|
|
325
|
+
- Check DNS resolution for the API hostname
|
|
326
|
+
|
|
327
|
+
### Proxy Issues
|
|
328
|
+
|
|
329
|
+
**Problem**: SOCKS or HTTP proxy connection failures
|
|
330
|
+
|
|
331
|
+
**Solutions**:
|
|
332
|
+
|
|
333
|
+
- Verify proxy server is running and accessible
|
|
334
|
+
- Check proxy authentication if required
|
|
335
|
+
- Test proxy connectivity manually: `curl --proxy socks5://localhost:12345 https://dwdi.cscs.ch`
|
|
336
|
+
- Ensure proxy supports the required protocol (SOCKS4/5, HTTP)
|
|
337
|
+
- Verify proxy URL format is correct (e.g., `socks5://hostname:port`)
|
|
338
|
+
|
|
339
|
+
### Debugging Tips
|
|
340
|
+
|
|
341
|
+
**Enable debug logging**:
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
import logging
|
|
345
|
+
logging.getLogger('waldur_site_agent_cscs_dwdi').setLevel(logging.DEBUG)
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Test API connectivity**:
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
# Test direct API access
|
|
352
|
+
curl -H "Authorization: Bearer YOUR_TOKEN" https://dwdi.cscs.ch/api/v1/
|
|
353
|
+
|
|
354
|
+
# Test through proxy
|
|
355
|
+
curl --proxy socks5://localhost:12345 -H "Authorization: Bearer YOUR_TOKEN" https://dwdi.cscs.ch/api/v1/
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Development
|
|
359
|
+
|
|
360
|
+
### Project Structure
|
|
361
|
+
|
|
362
|
+
```text
|
|
363
|
+
plugins/cscs-dwdi/
|
|
364
|
+
├── pyproject.toml # Plugin configuration
|
|
365
|
+
├── README.md # This documentation
|
|
366
|
+
├── examples/ # Configuration examples
|
|
367
|
+
├── waldur_site_agent_cscs_dwdi/
|
|
368
|
+
│ ├── __init__.py # Package init
|
|
369
|
+
│ ├── backend.py # Backend implementations
|
|
370
|
+
│ └── client.py # CSCS-DWDI API client
|
|
371
|
+
└── tests/
|
|
372
|
+
└── test_cscs_dwdi.py # Plugin tests
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Key Classes
|
|
376
|
+
|
|
377
|
+
- **`CSCSDWDIComputeBackend`**: Compute usage reporting backend
|
|
378
|
+
- **`CSCSDWDIStorageBackend`**: Storage usage reporting backend
|
|
379
|
+
- **`CSCSDWDIClient`**: HTTP client for CSCS-DWDI API communication with OIDC authentication
|
|
380
|
+
|
|
381
|
+
### Key Features
|
|
382
|
+
|
|
383
|
+
- **Automatic Token Management**: OIDC tokens are cached and refreshed automatically
|
|
384
|
+
- **Proxy Support**: Built-in SOCKS and HTTP proxy support using httpx
|
|
385
|
+
- **Error Handling**: Comprehensive error handling with detailed logging
|
|
386
|
+
- **Flexible Configuration**: Support for custom unit conversions and component mappings
|
|
387
|
+
|
|
388
|
+
### Extension Points
|
|
389
|
+
|
|
390
|
+
To extend the plugin:
|
|
391
|
+
|
|
392
|
+
1. **Additional Endpoints**: Modify `CSCSDWDIClient` to support more API endpoints
|
|
393
|
+
2. **Authentication Methods**: Update authentication logic in `client.py`
|
|
394
|
+
3. **Data Processing**: Enhance response processing methods for additional data formats
|
|
395
|
+
4. **Proxy Types**: Extend proxy support for additional proxy protocols
|
|
396
|
+
|
|
397
|
+
### Contributing
|
|
398
|
+
|
|
399
|
+
When contributing to this plugin:
|
|
400
|
+
|
|
401
|
+
1. Follow the existing code style and patterns
|
|
402
|
+
2. Add tests for new functionality
|
|
403
|
+
3. Update documentation for new features
|
|
404
|
+
4. Ensure backward compatibility with existing configurations
|