Fleet API Reference¶
The Fleet module provides classes and functions for managing multiple OpenWRT devices.
Fleet Configuration¶
FleetDefaults
¶
Bases: BaseModel
Default settings applied to all devices in the fleet.
Source code in src/wrtkit/fleet.py
FleetDevice
¶
Bases: BaseModel
Definition of a single device in the fleet.
Source code in src/wrtkit/fleet.py
FleetConfig
¶
Bases: BaseModel
Fleet inventory configuration.
Source code in src/wrtkit/fleet.py
Fleet Functions¶
load_fleet(fleet_file)
¶
Load a fleet inventory file.
Uses OmegaConf for variable interpolation including: - Environment variables: ${oc.env:VAR_NAME} - Config layer references: ${config_layers.base}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fleet_file
|
str
|
Path to the fleet YAML file |
required |
Returns:
| Type | Description |
|---|---|
FleetConfig
|
FleetConfig instance |
Source code in src/wrtkit/fleet.py
merge_device_configs(device, fleet_path)
¶
Merge multiple config files for a device using OmegaConf.
Config files are merged in order, with later files overriding earlier ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
FleetDevice
|
The device definition with config file list |
required |
fleet_path
|
Path
|
Path to the fleet file (for resolving relative paths) |
required |
Returns:
| Type | Description |
|---|---|
UCIConfig
|
Merged UCIConfig instance |
Source code in src/wrtkit/fleet.py
filter_devices(fleet, target=None, tags=None)
¶
Filter fleet devices by name/glob pattern and/or tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fleet
|
FleetConfig
|
The fleet configuration |
required |
target
|
Optional[str]
|
Device name or glob pattern (e.g., "ap-*") |
None
|
tags
|
Optional[List[str]]
|
List of tags (AND logic - device must have all tags) |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, FleetDevice]
|
Dictionary of matching devices keyed by name |
Source code in src/wrtkit/fleet.py
get_device_connection_params(device, defaults)
¶
Get connection parameters for a device, applying defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
FleetDevice
|
The device definition |
required |
defaults
|
FleetDefaults
|
Fleet defaults to apply |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with connection parameters |
Source code in src/wrtkit/fleet.py
Fleet Executor¶
DeviceResult
dataclass
¶
Result of operations on a single device.
Source code in src/wrtkit/fleet_executor.py
FleetResult
dataclass
¶
Result of fleet-wide operations.
Source code in src/wrtkit/fleet_executor.py
FleetExecutor
¶
Executes fleet operations with two-phase coordinated updates.
Phase 1 (Stage): Push UCI commands to all devices in parallel without committing. Fail fast if any device fails. Phase 2 (Commit): Send coordinated commit commands to all devices simultaneously.
Source code in src/wrtkit/fleet_executor.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
__init__(fleet, fleet_path, on_device_start=None, on_device_complete=None, on_phase_start=None)
¶
Initialize fleet executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fleet
|
FleetConfig
|
Fleet configuration |
required |
fleet_path
|
Path
|
Path to fleet file (for resolving relative paths) |
required |
on_device_start
|
Optional[Callable[[str, str], None]]
|
Callback when starting work on a device (name, target) |
None
|
on_device_complete
|
Optional[Callable[[str, DeviceResult], None]]
|
Callback when device work completes (name, result) |
None
|
on_phase_start
|
Optional[Callable[[str], None]]
|
Callback when a phase starts (phase_name) |
None
|
Source code in src/wrtkit/fleet_executor.py
preview(target=None, tags=None, max_workers=5)
¶
Preview changes for targeted devices without applying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Optional[str]
|
Device name or glob pattern |
None
|
tags
|
Optional[List[str]]
|
List of tags to filter by |
None
|
max_workers
|
int
|
Maximum parallel connections |
5
|
Returns:
| Type | Description |
|---|---|
FleetResult
|
FleetResult with diff information for each device |
Source code in src/wrtkit/fleet_executor.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
stage(target=None, tags=None, max_workers=5, remove_unmanaged=False)
¶
Stage changes to devices (Phase 1).
Pushes UCI commands without committing. Fails fast on any error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Optional[str]
|
Device name or glob pattern |
None
|
tags
|
Optional[List[str]]
|
List of tags to filter by |
None
|
max_workers
|
int
|
Maximum parallel connections |
5
|
remove_unmanaged
|
bool
|
Remove settings not in config |
False
|
Returns:
| Type | Description |
|---|---|
FleetResult
|
FleetResult with staging results |
Source code in src/wrtkit/fleet_executor.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
commit(delay=None)
¶
Commit staged changes on all devices (Phase 2).
Sends coordinated commit commands with optional delay for synchronization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delay
|
Optional[int]
|
Seconds to delay before commit (uses fleet default if None) |
None
|
Returns:
| Type | Description |
|---|---|
FleetResult
|
FleetResult with commit results |
Source code in src/wrtkit/fleet_executor.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
apply(target=None, tags=None, max_workers=5, remove_unmanaged=False, commit_delay=None)
¶
Apply changes to fleet devices with two-phase execution.
Phase 1: Stage all changes in parallel (fail fast) Phase 2: Coordinated commit if staging succeeded
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Optional[str]
|
Device name or glob pattern |
None
|
tags
|
Optional[List[str]]
|
List of tags to filter by |
None
|
max_workers
|
int
|
Maximum parallel connections |
5
|
remove_unmanaged
|
bool
|
Remove settings not in config |
False
|
commit_delay
|
Optional[int]
|
Override default commit delay |
None
|
Returns:
| Type | Description |
|---|---|
tuple[FleetResult, FleetResult]
|
Tuple of (stage_result, commit_result) |
Source code in src/wrtkit/fleet_executor.py
cleanup()
¶
Clean up any open connections.